@withwiz/toolkit 0.1.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.
- package/README.md +162 -0
- package/dist/auth/adapters/prisma/index.d.ts +43 -0
- package/dist/auth/adapters/prisma/index.js +284 -0
- package/dist/auth/core/email/token-generator.d.ts +43 -0
- package/dist/auth/core/email/token-generator.js +7 -0
- package/dist/auth/core/jwt/client.d.ts +87 -0
- package/dist/auth/core/jwt/client.js +36 -0
- package/dist/auth/core/jwt/index.d.ts +110 -0
- package/dist/auth/core/jwt/index.js +10 -0
- package/dist/auth/core/jwt/types.d.ts +6 -0
- package/dist/auth/core/jwt/types.js +13 -0
- package/dist/auth/core/oauth/index.d.ts +51 -0
- package/dist/auth/core/oauth/index.js +12 -0
- package/dist/auth/core/password/client-helper.d.ts +44 -0
- package/dist/auth/core/password/client-helper.js +28 -0
- package/dist/auth/core/password/index.d.ts +71 -0
- package/dist/auth/core/password/index.js +14 -0
- package/dist/auth/errors/index.d.ts +49 -0
- package/dist/auth/errors/index.js +17 -0
- package/dist/auth/index.d.ts +21 -0
- package/dist/auth/index.js +97 -0
- package/dist/auth/types/index.d.ts +213 -0
- package/dist/auth/types/index.js +13 -0
- package/dist/cache/cache-config.d.ts +73 -0
- package/dist/cache/cache-config.js +12 -0
- package/dist/cache/cache-defaults.d.ts +141 -0
- package/dist/cache/cache-defaults.js +33 -0
- package/dist/cache/cache-env.d.ts +75 -0
- package/dist/cache/cache-env.js +25 -0
- package/dist/cache/cache-factory.d.ts +34 -0
- package/dist/cache/cache-factory.js +28 -0
- package/dist/cache/cache-invalidation.d.ts +90 -0
- package/dist/cache/cache-invalidation.js +24 -0
- package/dist/cache/cache-keys-legacy.d.ts +35 -0
- package/dist/cache/cache-keys-legacy.js +7 -0
- package/dist/cache/cache-redis.d.ts +74 -0
- package/dist/cache/cache-redis.js +24 -0
- package/dist/cache/cache-types.d.ts +151 -0
- package/dist/cache/cache-types.js +9 -0
- package/dist/cache/cache-wrapper.d.ts +27 -0
- package/dist/cache/cache-wrapper.js +22 -0
- package/dist/cache/cache.d.ts +14 -0
- package/dist/cache/cache.js +112 -0
- package/dist/cache/hybrid-cache-manager.d.ts +148 -0
- package/dist/cache/hybrid-cache-manager.js +13 -0
- package/dist/cache/index.d.ts +21 -0
- package/dist/cache/index.js +112 -0
- package/dist/cache/inmemory-cache-manager.d.ts +163 -0
- package/dist/cache/inmemory-cache-manager.js +9 -0
- package/dist/cache/noop-cache-manager.d.ts +36 -0
- package/dist/cache/noop-cache-manager.js +11 -0
- package/dist/cache/redis-cache-manager.d.ts +34 -0
- package/dist/cache/redis-cache-manager.js +11 -0
- package/dist/chunk-26Y7VEYG.js +93 -0
- package/dist/chunk-2DVWSDST.js +119 -0
- package/dist/chunk-2KAPUVIS.js +155 -0
- package/dist/chunk-2TO7WUKK.js +93 -0
- package/dist/chunk-34WAGUT5.js +117 -0
- package/dist/chunk-3DZA6AGS.js +120 -0
- package/dist/chunk-4DPSCTX4.js +212 -0
- package/dist/chunk-4KJXENRM.js +64 -0
- package/dist/chunk-4NWJ3WCZ.js +28 -0
- package/dist/chunk-4ODT3Q4A.js +86 -0
- package/dist/chunk-5ATB5D6S.js +40 -0
- package/dist/chunk-62FLBG6B.js +34 -0
- package/dist/chunk-62Q7DN5G.js +25 -0
- package/dist/chunk-65LHDFU3.js +242 -0
- package/dist/chunk-6C7HQIX4.js +13 -0
- package/dist/chunk-6D3HHYER.js +32 -0
- package/dist/chunk-6LTZCXNC.js +326 -0
- package/dist/chunk-7VJNLGAS.js +110 -0
- package/dist/chunk-7XFHGAJP.js +0 -0
- package/dist/chunk-A6EAAWMK.js +50 -0
- package/dist/chunk-AHDPGRXS.js +51 -0
- package/dist/chunk-AIH3F7JV.js +76 -0
- package/dist/chunk-AIHQBQ3E.js +109 -0
- package/dist/chunk-BKGVSC6S.js +152 -0
- package/dist/chunk-COK4ZXNG.js +0 -0
- package/dist/chunk-DEEJBDJE.js +47 -0
- package/dist/chunk-DH2ZHGW2.js +53 -0
- package/dist/chunk-EBUEBEJX.js +0 -0
- package/dist/chunk-EEUBKZV4.js +54 -0
- package/dist/chunk-EQYTE7WD.js +139 -0
- package/dist/chunk-EUQATJLI.js +180 -0
- package/dist/chunk-EZC6ETFW.js +80 -0
- package/dist/chunk-EZR55KV2.js +249 -0
- package/dist/chunk-F6LCSFSU.js +31 -0
- package/dist/chunk-FOKAATUQ.js +62 -0
- package/dist/chunk-FW3IEJ7H.js +71 -0
- package/dist/chunk-G26T2PRQ.js +53 -0
- package/dist/chunk-G4NI37NN.js +257 -0
- package/dist/chunk-GCZOXUDV.js +132 -0
- package/dist/chunk-GDWEDUHO.js +55 -0
- package/dist/chunk-GL2NANFH.js +434 -0
- package/dist/chunk-GPBOMJSZ.js +136 -0
- package/dist/chunk-H5I5GWAA.js +94 -0
- package/dist/chunk-HGC4CCKB.js +29 -0
- package/dist/chunk-HV3DGSSH.js +447 -0
- package/dist/chunk-I47QEDTX.js +193 -0
- package/dist/chunk-IAJNC34M.js +102 -0
- package/dist/chunk-IHXRF3BH.js +215 -0
- package/dist/chunk-IJEZ7G7S.js +26 -0
- package/dist/chunk-IQQKKUAV.js +151 -0
- package/dist/chunk-JBCDEAMW.js +35 -0
- package/dist/chunk-JLLMTTQ4.js +75 -0
- package/dist/chunk-JS5VI3OW.js +143 -0
- package/dist/chunk-KAWVMIRJ.js +44 -0
- package/dist/chunk-KMCJIL57.js +214 -0
- package/dist/chunk-KWTBD4CM.js +145 -0
- package/dist/chunk-KXAWBFJN.js +310 -0
- package/dist/chunk-L25BNU3E.js +56 -0
- package/dist/chunk-L76O3X3D.js +197 -0
- package/dist/chunk-LNV2E4I6.js +63 -0
- package/dist/chunk-MLGO3HLS.js +329 -0
- package/dist/chunk-MRJE6OX5.js +22 -0
- package/dist/chunk-MYLGYX4K.js +57 -0
- package/dist/chunk-N4YGR5WH.js +310 -0
- package/dist/chunk-OIVXOT2X.js +80 -0
- package/dist/chunk-ORMEWXMH.js +37 -0
- package/dist/chunk-POKGHK3L.js +57 -0
- package/dist/chunk-Q7IP4JMW.js +69 -0
- package/dist/chunk-RJUVBBZG.js +27 -0
- package/dist/chunk-S73334QY.js +89 -0
- package/dist/chunk-SLG26KHZ.js +101 -0
- package/dist/chunk-SR65BF6X.js +82 -0
- package/dist/chunk-SS56XFLI.js +19 -0
- package/dist/chunk-T3LJYAMO.js +277 -0
- package/dist/chunk-TDZJ6SAI.js +34 -0
- package/dist/chunk-TEIYA7U4.js +72 -0
- package/dist/chunk-TMVS4F7E.js +88 -0
- package/dist/chunk-TRBKJ7JT.js +137 -0
- package/dist/chunk-TXGNSECL.js +84 -0
- package/dist/chunk-TZAP5T4N.js +188 -0
- package/dist/chunk-UCYQNHST.js +24 -0
- package/dist/chunk-ULF5RDDX.js +0 -0
- package/dist/chunk-UXQRU3EM.js +167 -0
- package/dist/chunk-V5K5FYU7.js +200 -0
- package/dist/chunk-VDXB5DCY.js +68 -0
- package/dist/chunk-VSGKVZB4.js +47 -0
- package/dist/chunk-VWODEQ5C.js +204 -0
- package/dist/chunk-WDUFQFDP.js +193 -0
- package/dist/chunk-WHR7HPWF.js +126 -0
- package/dist/chunk-WSQMXMTL.js +122 -0
- package/dist/chunk-XHZ5L4FO.js +103 -0
- package/dist/chunk-XPASCCUA.js +404 -0
- package/dist/chunk-XRRPEBKB.js +231 -0
- package/dist/chunk-Y2TUZFCP.js +0 -0
- package/dist/chunk-Y3OTJH2S.js +473 -0
- package/dist/chunk-YBSHN67U.js +161 -0
- package/dist/chunk-YJ3TLEW3.js +100 -0
- package/dist/chunk-YJWLWUFK.js +105 -0
- package/dist/chunk-Z4D4CMDA.js +488 -0
- package/dist/chunk-ZHVUK5OY.js +314 -0
- package/dist/chunk-ZTN4X5FN.js +29 -0
- package/dist/chunk-ZZIKRBJU.js +96 -0
- package/dist/components/ui/Alert.d.ts +12 -0
- package/dist/components/ui/Alert.js +10 -0
- package/dist/components/ui/Badge.d.ts +7 -0
- package/dist/components/ui/Badge.js +8 -0
- package/dist/components/ui/Button.d.ts +7 -0
- package/dist/components/ui/Button.js +8 -0
- package/dist/components/ui/DataTable.d.ts +103 -0
- package/dist/components/ui/DataTable.js +606 -0
- package/dist/components/ui/DomainDisplay.d.ts +12 -0
- package/dist/components/ui/DomainDisplay.js +31 -0
- package/dist/components/ui/Input.d.ts +5 -0
- package/dist/components/ui/Input.js +8 -0
- package/dist/components/ui/Label.d.ts +5 -0
- package/dist/components/ui/Label.js +8 -0
- package/dist/components/ui/Pagination.d.ts +42 -0
- package/dist/components/ui/Pagination.js +20 -0
- package/dist/components/ui/Select.d.ts +15 -0
- package/dist/components/ui/Select.js +27 -0
- package/dist/components/ui/Skeleton.d.ts +6 -0
- package/dist/components/ui/Skeleton.js +8 -0
- package/dist/components/ui/TimezoneDisplay.d.ts +22 -0
- package/dist/components/ui/TimezoneDisplay.js +83 -0
- package/dist/components/ui/Tooltip.d.ts +21 -0
- package/dist/components/ui/Tooltip.js +94 -0
- package/dist/components/ui/WorldMapChart.d.ts +17 -0
- package/dist/components/ui/WorldMapChart.js +250 -0
- package/dist/components/ui/loading-bar.d.ts +20 -0
- package/dist/components/ui/loading-bar.js +15 -0
- package/dist/constants/error-codes.d.ts +389 -0
- package/dist/constants/error-codes.js +27 -0
- package/dist/constants/index.d.ts +11 -0
- package/dist/constants/index.js +85 -0
- package/dist/constants/messages.d.ts +83 -0
- package/dist/constants/messages.js +13 -0
- package/dist/constants/pagination.d.ts +43 -0
- package/dist/constants/pagination.js +15 -0
- package/dist/constants/security.d.ts +66 -0
- package/dist/constants/security.js +23 -0
- package/dist/constants/validation.d.ts +60 -0
- package/dist/constants/validation.js +19 -0
- package/dist/error/ErrorBoundary.d.ts +47 -0
- package/dist/error/app-error.d.ts +144 -0
- package/dist/error/app-error.js +10 -0
- package/dist/error/components/EmptyState.d.ts +50 -0
- package/dist/error/components/ErrorAlert.d.ts +50 -0
- package/dist/error/components/ErrorPage.d.ts +39 -0
- package/dist/error/components/LoadingState.d.ts +37 -0
- package/dist/error/components/index.d.ts +13 -0
- package/dist/error/components/index.js +18 -0
- package/dist/error/core/locale-detector.d.ts +44 -0
- package/dist/error/core/locale-detector.js +9 -0
- package/dist/error/error-display.d.ts +55 -0
- package/dist/error/error-display.js +24 -0
- package/dist/error/error-handler.d.ts +118 -0
- package/dist/error/error-handler.js +18 -0
- package/dist/error/friendly-messages-v2.d.ts +46 -0
- package/dist/error/friendly-messages-v2.js +15 -0
- package/dist/error/friendly-messages.d.ts +22 -0
- package/dist/error/friendly-messages.js +12 -0
- package/dist/error/hooks/index.d.ts +7 -0
- package/dist/error/hooks/index.js +14 -0
- package/dist/error/hooks/useErrorHandler.d.ts +67 -0
- package/dist/error/hooks/useErrorHandler.js +14 -0
- package/dist/error/index.d.ts +26 -0
- package/dist/error/index.js +289 -0
- package/dist/error/logging/error-logger.d.ts +77 -0
- package/dist/error/logging/error-logger.js +10 -0
- package/dist/error/logging/index.d.ts +9 -0
- package/dist/error/logging/index.js +35 -0
- package/dist/error/logging/transports/base.d.ts +30 -0
- package/dist/error/logging/transports/base.js +7 -0
- package/dist/error/logging/transports/console.d.ts +40 -0
- package/dist/error/logging/transports/console.js +9 -0
- package/dist/error/logging/transports/file.d.ts +49 -0
- package/dist/error/logging/transports/file.js +8 -0
- package/dist/error/logging/transports/index.d.ts +12 -0
- package/dist/error/logging/transports/index.js +25 -0
- package/dist/error/logging/transports/sentry.d.ts +44 -0
- package/dist/error/logging/transports/sentry.js +9 -0
- package/dist/error/logging/transports/slack.d.ts +51 -0
- package/dist/error/logging/transports/slack.js +9 -0
- package/dist/error/logging/types.d.ts +83 -0
- package/dist/error/logging/types.js +7 -0
- package/dist/error/messages/en.d.ts +5 -0
- package/dist/error/messages/en.js +7 -0
- package/dist/error/messages/index.d.ts +40 -0
- package/dist/error/messages/index.js +17 -0
- package/dist/error/messages/ko.d.ts +5 -0
- package/dist/error/messages/ko.js +7 -0
- package/dist/error/messages/types.d.ts +30 -0
- package/dist/error/messages/types.js +0 -0
- package/dist/error/recovery/circuit-breaker.d.ts +85 -0
- package/dist/error/recovery/circuit-breaker.js +9 -0
- package/dist/error/recovery/degradation.d.ts +56 -0
- package/dist/error/recovery/degradation.js +7 -0
- package/dist/error/recovery/fallback.d.ts +55 -0
- package/dist/error/recovery/fallback.js +11 -0
- package/dist/error/recovery/index.d.ts +12 -0
- package/dist/error/recovery/index.js +26 -0
- package/dist/error/recovery/retry.d.ts +44 -0
- package/dist/error/recovery/retry.js +7 -0
- package/dist/geolocation/batch-processor.d.ts +33 -0
- package/dist/geolocation/batch-processor.js +10 -0
- package/dist/geolocation/index.d.ts +14 -0
- package/dist/geolocation/index.js +36 -0
- package/dist/geolocation/providers/base-provider.d.ts +33 -0
- package/dist/geolocation/providers/base-provider.js +9 -0
- package/dist/geolocation/providers/index.d.ts +54 -0
- package/dist/geolocation/providers/index.js +29 -0
- package/dist/geolocation/providers/ip-api-provider.d.ts +17 -0
- package/dist/geolocation/providers/ip-api-provider.js +8 -0
- package/dist/geolocation/providers/ipapi-co-provider.d.ts +17 -0
- package/dist/geolocation/providers/ipapi-co-provider.js +8 -0
- package/dist/geolocation/providers/ipgeolocation-provider.d.ts +18 -0
- package/dist/geolocation/providers/ipgeolocation-provider.js +8 -0
- package/dist/geolocation/providers/maxmind-provider.d.ts +18 -0
- package/dist/geolocation/providers/maxmind-provider.js +8 -0
- package/dist/hooks/useDataTable.d.ts +51 -0
- package/dist/hooks/useDataTable.js +149 -0
- package/dist/hooks/useDebounce.d.ts +7 -0
- package/dist/hooks/useDebounce.js +7 -0
- package/dist/hooks/useExitIntent.d.ts +35 -0
- package/dist/hooks/useExitIntent.js +72 -0
- package/dist/hooks/useTimezone.d.ts +19 -0
- package/dist/hooks/useTimezone.js +11 -0
- package/dist/logger/logger.d.ts +11 -0
- package/dist/logger/logger.js +17 -0
- package/dist/middleware/auth.d.ts +87 -0
- package/dist/middleware/auth.js +20 -0
- package/dist/middleware/cors.d.ts +30 -0
- package/dist/middleware/cors.js +10 -0
- package/dist/middleware/error-handler.d.ts +23 -0
- package/dist/middleware/error-handler.js +13 -0
- package/dist/middleware/index.d.ts +16 -0
- package/dist/middleware/index.js +72 -0
- package/dist/middleware/init-request.d.ts +18 -0
- package/dist/middleware/init-request.js +8 -0
- package/dist/middleware/middleware-chain.d.ts +53 -0
- package/dist/middleware/middleware-chain.js +8 -0
- package/dist/middleware/rate-limit.d.ts +82 -0
- package/dist/middleware/rate-limit.js +14 -0
- package/dist/middleware/response-logger.d.ts +22 -0
- package/dist/middleware/response-logger.js +8 -0
- package/dist/middleware/security.d.ts +31 -0
- package/dist/middleware/security.js +9 -0
- package/dist/middleware/types.d.ts +45 -0
- package/dist/middleware/types.js +0 -0
- package/dist/middleware/wrappers.d.ts +91 -0
- package/dist/middleware/wrappers.js +32 -0
- package/dist/storage/r2-storage.d.ts +38 -0
- package/dist/storage/r2-storage.js +105 -0
- package/dist/system/cpu.d.ts +2 -0
- package/dist/system/cpu.js +9 -0
- package/dist/system/disk.d.ts +2 -0
- package/dist/system/disk.js +9 -0
- package/dist/system/environment.d.ts +8 -0
- package/dist/system/environment.js +9 -0
- package/dist/system/health-check.d.ts +26 -0
- package/dist/system/health-check.js +10 -0
- package/dist/system/index.d.ts +51 -0
- package/dist/system/index.js +194 -0
- package/dist/system/memory.d.ts +2 -0
- package/dist/system/memory.js +9 -0
- package/dist/system/network.d.ts +2 -0
- package/dist/system/network.js +9 -0
- package/dist/system/types.d.ts +93 -0
- package/dist/system/types.js +0 -0
- package/dist/system/utils.d.ts +12 -0
- package/dist/system/utils.js +26 -0
- package/dist/types/api.d.ts +80 -0
- package/dist/types/api.js +0 -0
- package/dist/types/database.d.ts +38 -0
- package/dist/types/database.js +0 -0
- package/dist/types/env.d.ts +105 -0
- package/dist/types/env.js +0 -0
- package/dist/types/geoip.d.ts +152 -0
- package/dist/types/geoip.js +0 -0
- package/dist/types/i18n.d.ts +11 -0
- package/dist/types/i18n.js +0 -0
- package/dist/types/qr-code.d.ts +139 -0
- package/dist/types/qr-code.js +75 -0
- package/dist/types/user.d.ts +54 -0
- package/dist/types/user.js +0 -0
- package/dist/utils/api-helpers.d.ts +147 -0
- package/dist/utils/api-helpers.js +30 -0
- package/dist/utils/client/client-utils.d.ts +3 -0
- package/dist/utils/client/client-utils.js +9 -0
- package/dist/utils/client/qr-code.d.ts +16 -0
- package/dist/utils/client/qr-code.js +215 -0
- package/dist/utils/cors.d.ts +40 -0
- package/dist/utils/cors.js +21 -0
- package/dist/utils/csv-export.d.ts +97 -0
- package/dist/utils/csv-export.js +20 -0
- package/dist/utils/error-message-formatter.d.ts +17 -0
- package/dist/utils/error-message-formatter.js +11 -0
- package/dist/utils/error-processor.d.ts +70 -0
- package/dist/utils/error-processor.js +34 -0
- package/dist/utils/format-number.d.ts +17 -0
- package/dist/utils/format-number.js +9 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.js +160 -0
- package/dist/utils/input-validation.d.ts +88 -0
- package/dist/utils/input-validation.js +223 -0
- package/dist/utils/ip-utils.d.ts +15 -0
- package/dist/utils/ip-utils.js +91 -0
- package/dist/utils/optimistic-lock.d.ts +27 -0
- package/dist/utils/optimistic-lock.js +16 -0
- package/dist/utils/sanitizer.d.ts +72 -0
- package/dist/utils/sanitizer.js +19 -0
- package/dist/utils/shared-utils.d.ts +25 -0
- package/dist/utils/shared-utils.js +43 -0
- package/dist/utils/short-code-generator.d.ts +24 -0
- package/dist/utils/short-code-generator.js +9 -0
- package/dist/utils/timezone.d.ts +56 -0
- package/dist/utils/timezone.js +29 -0
- package/dist/utils/type-guards.d.ts +164 -0
- package/dist/utils/type-guards.js +59 -0
- package/dist/utils/url-normalizer.d.ts +53 -0
- package/dist/utils/url-normalizer.js +21 -0
- package/dist/validators/index.d.ts +7 -0
- package/dist/validators/index.js +13 -0
- package/dist/validators/password-validator.d.ts +86 -0
- package/dist/validators/password-validator.js +13 -0
- package/dist/world_countries-C2WUL2CQ.js +279 -0
- package/package.json +129 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getRedisClient,
|
|
3
|
+
isRedisGloballyDisabled,
|
|
4
|
+
notifyRedisError,
|
|
5
|
+
resetRedisGlobalState
|
|
6
|
+
} from "./chunk-6LTZCXNC.js";
|
|
7
|
+
import {
|
|
8
|
+
getENV,
|
|
9
|
+
isCacheEnabled
|
|
10
|
+
} from "./chunk-I47QEDTX.js";
|
|
11
|
+
import {
|
|
12
|
+
logger
|
|
13
|
+
} from "./chunk-EZR55KV2.js";
|
|
14
|
+
import {
|
|
15
|
+
__spreadValues
|
|
16
|
+
} from "./chunk-ORMEWXMH.js";
|
|
17
|
+
|
|
18
|
+
// src/cache/redis-cache-manager.ts
|
|
19
|
+
var RedisCacheManager = class _RedisCacheManager {
|
|
20
|
+
constructor(prefix) {
|
|
21
|
+
this.prefix = prefix;
|
|
22
|
+
this.metrics = {
|
|
23
|
+
hits: 0,
|
|
24
|
+
misses: 0,
|
|
25
|
+
errors: 0,
|
|
26
|
+
totalRequests: 0,
|
|
27
|
+
hitRate: 0,
|
|
28
|
+
averageResponseTime: 0
|
|
29
|
+
};
|
|
30
|
+
this.connectionStatus = {
|
|
31
|
+
isConnected: false,
|
|
32
|
+
connectionErrors: 0
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// globalThis를 사용하여 프로세스 레벨에서 인스턴스 관리 (HMR 안전)
|
|
36
|
+
static getGlobalInstances() {
|
|
37
|
+
if (!globalThis.__redisCacheManagerInstances) {
|
|
38
|
+
globalThis.__redisCacheManagerInstances = /* @__PURE__ */ new Map();
|
|
39
|
+
}
|
|
40
|
+
return globalThis.__redisCacheManagerInstances;
|
|
41
|
+
}
|
|
42
|
+
// 정적 팩토리 메서드로 인스턴스 가져오기
|
|
43
|
+
static getInstance(prefix) {
|
|
44
|
+
const globalInstances = _RedisCacheManager.getGlobalInstances();
|
|
45
|
+
if (!globalInstances.has(prefix)) {
|
|
46
|
+
const instance = new _RedisCacheManager(prefix);
|
|
47
|
+
globalInstances.set(prefix, instance);
|
|
48
|
+
logger.debug(`RedisCacheManager initialization: ${prefix}`, {
|
|
49
|
+
prefix,
|
|
50
|
+
redisAvailable: !!getRedisClient(),
|
|
51
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return globalInstances.get(prefix);
|
|
55
|
+
}
|
|
56
|
+
// 인스턴스 초기화 (테스트용)
|
|
57
|
+
static clearInstances() {
|
|
58
|
+
_RedisCacheManager.getGlobalInstances().clear();
|
|
59
|
+
}
|
|
60
|
+
// 메트릭 업데이트
|
|
61
|
+
updateMetrics(responseTime) {
|
|
62
|
+
this.metrics.hitRate = this.metrics.totalRequests > 0 ? this.metrics.hits / this.metrics.totalRequests * 100 : 0;
|
|
63
|
+
const totalTime = this.metrics.averageResponseTime * (this.metrics.totalRequests - 1) + responseTime;
|
|
64
|
+
this.metrics.averageResponseTime = totalTime / this.metrics.totalRequests;
|
|
65
|
+
}
|
|
66
|
+
// 메트릭 조회
|
|
67
|
+
getMetrics() {
|
|
68
|
+
return __spreadValues({}, this.metrics);
|
|
69
|
+
}
|
|
70
|
+
// 연결 상태 조회
|
|
71
|
+
getConnectionStatus() {
|
|
72
|
+
return __spreadValues({}, this.connectionStatus);
|
|
73
|
+
}
|
|
74
|
+
// Redis 연결 상태 확인 (PING 테스트)
|
|
75
|
+
async checkConnection() {
|
|
76
|
+
const redis = getRedisClient();
|
|
77
|
+
if (!redis) {
|
|
78
|
+
this.connectionStatus.isConnected = false;
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
const pingResult = await redis.ping();
|
|
83
|
+
if (pingResult === "PONG") {
|
|
84
|
+
this.connectionStatus.isConnected = true;
|
|
85
|
+
this.connectionStatus.lastPingTime = /* @__PURE__ */ new Date();
|
|
86
|
+
return true;
|
|
87
|
+
} else {
|
|
88
|
+
this.connectionStatus.isConnected = false;
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
} catch (error) {
|
|
92
|
+
this.connectionStatus.isConnected = false;
|
|
93
|
+
this.connectionStatus.connectionErrors++;
|
|
94
|
+
this.connectionStatus.lastConnectionError = error instanceof Error ? error.message : "Unknown error";
|
|
95
|
+
this.connectionStatus.lastConnectionErrorTime = /* @__PURE__ */ new Date();
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// 캐시 설정 정보 조회
|
|
100
|
+
getConfig() {
|
|
101
|
+
const ENV = getENV();
|
|
102
|
+
return {
|
|
103
|
+
prefix: this.prefix,
|
|
104
|
+
enabled: true,
|
|
105
|
+
redisAvailable: !!getRedisClient(),
|
|
106
|
+
envVars: {
|
|
107
|
+
CACHE_ENABLED: ENV.CACHE.ENABLED ? "true" : "false",
|
|
108
|
+
UPSTASH_REDIS_REST_URL: ENV.REDIS.URL ? "\uC124\uC815\uB428" : "\uBBF8\uC124\uC815",
|
|
109
|
+
UPSTASH_REDIS_REST_TOKEN: ENV.REDIS.TOKEN ? "\uC124\uC815\uB428" : "\uBBF8\uC124\uC815"
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
getKey(key) {
|
|
114
|
+
return `${this.prefix}:${key}`;
|
|
115
|
+
}
|
|
116
|
+
// BigInt를 Number로 변환하는 헬퍼 함수
|
|
117
|
+
serializeData(data) {
|
|
118
|
+
if (data === null || data === void 0) {
|
|
119
|
+
return data;
|
|
120
|
+
}
|
|
121
|
+
if (typeof data === "bigint") {
|
|
122
|
+
return Number(data);
|
|
123
|
+
}
|
|
124
|
+
if (Array.isArray(data)) {
|
|
125
|
+
return data.map((item) => this.serializeData(item));
|
|
126
|
+
}
|
|
127
|
+
if (typeof data === "object") {
|
|
128
|
+
const serialized = {};
|
|
129
|
+
for (const [key, value] of Object.entries(data)) {
|
|
130
|
+
serialized[key] = this.serializeData(value);
|
|
131
|
+
}
|
|
132
|
+
return serialized;
|
|
133
|
+
}
|
|
134
|
+
return data;
|
|
135
|
+
}
|
|
136
|
+
async get(key) {
|
|
137
|
+
var _a;
|
|
138
|
+
const startTime = Date.now();
|
|
139
|
+
const fullKey = `${this.prefix}:${key}`;
|
|
140
|
+
this.metrics.totalRequests++;
|
|
141
|
+
if (!isCacheEnabled()) {
|
|
142
|
+
logger.debug(
|
|
143
|
+
`Cache retrieval skipped due to cache disabled: ${fullKey}`,
|
|
144
|
+
{
|
|
145
|
+
prefix: this.prefix,
|
|
146
|
+
key,
|
|
147
|
+
fullKey,
|
|
148
|
+
cacheEnabled: isCacheEnabled()
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
this.metrics.misses++;
|
|
152
|
+
this.updateMetrics(0);
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
if (isRedisGloballyDisabled()) {
|
|
156
|
+
this.metrics.misses++;
|
|
157
|
+
this.updateMetrics(0);
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
const redis = getRedisClient();
|
|
162
|
+
if (!redis) {
|
|
163
|
+
logger.warn(
|
|
164
|
+
`Cache retrieval failed due to Redis unavailability: ${fullKey}`,
|
|
165
|
+
{
|
|
166
|
+
prefix: this.prefix,
|
|
167
|
+
key,
|
|
168
|
+
fullKey
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
this.metrics.errors++;
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
logger.debug(`Cache retrieval started: ${fullKey}`, {
|
|
175
|
+
prefix: this.prefix,
|
|
176
|
+
key,
|
|
177
|
+
fullKey,
|
|
178
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
179
|
+
});
|
|
180
|
+
const value = await redis.get(fullKey);
|
|
181
|
+
const responseTime = Date.now() - startTime;
|
|
182
|
+
this.connectionStatus.isConnected = true;
|
|
183
|
+
this.connectionStatus.lastPingTime = /* @__PURE__ */ new Date();
|
|
184
|
+
resetRedisGlobalState();
|
|
185
|
+
if (value !== null && value !== void 0) {
|
|
186
|
+
this.metrics.hits++;
|
|
187
|
+
this.updateMetrics(responseTime);
|
|
188
|
+
logger.debug(`[Cache:R] hit: ${fullKey}`, {
|
|
189
|
+
prefix: this.prefix,
|
|
190
|
+
key,
|
|
191
|
+
fullKey,
|
|
192
|
+
responseTime: `${responseTime}ms`,
|
|
193
|
+
valueType: typeof value,
|
|
194
|
+
valueSize: ((_a = JSON.stringify(value)) == null ? void 0 : _a.length) || 0
|
|
195
|
+
});
|
|
196
|
+
return value;
|
|
197
|
+
} else {
|
|
198
|
+
this.metrics.misses++;
|
|
199
|
+
this.updateMetrics(responseTime);
|
|
200
|
+
logger.debug(`[Cache:R] miss: ${fullKey} (${responseTime}ms)`);
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
} catch (error) {
|
|
204
|
+
const responseTime = Date.now() - startTime;
|
|
205
|
+
const errorMessage = error instanceof Error ? error.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958";
|
|
206
|
+
this.metrics.errors++;
|
|
207
|
+
this.connectionStatus.connectionErrors++;
|
|
208
|
+
this.connectionStatus.lastConnectionError = errorMessage;
|
|
209
|
+
this.connectionStatus.lastConnectionErrorTime = /* @__PURE__ */ new Date();
|
|
210
|
+
this.updateMetrics(responseTime);
|
|
211
|
+
notifyRedisError(
|
|
212
|
+
error instanceof Error ? error : new Error(errorMessage),
|
|
213
|
+
`CacheManager.get:${this.prefix}`
|
|
214
|
+
);
|
|
215
|
+
logger.error(`Cache retrieval failed: ${fullKey}`, {
|
|
216
|
+
prefix: this.prefix,
|
|
217
|
+
key,
|
|
218
|
+
fullKey,
|
|
219
|
+
error: errorMessage,
|
|
220
|
+
responseTime: `${responseTime}ms`,
|
|
221
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
222
|
+
});
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async set(key, value, ttl) {
|
|
227
|
+
var _a, _b;
|
|
228
|
+
const startTime = Date.now();
|
|
229
|
+
const fullKey = `${this.prefix}:${key}`;
|
|
230
|
+
if (value === void 0) {
|
|
231
|
+
logger.warn(`[Cache:R] Attempted to set undefined value: ${fullKey}`);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (!isCacheEnabled()) {
|
|
235
|
+
logger.debug(`Cache storage skipped due to cache disabled: ${fullKey}`, {
|
|
236
|
+
prefix: this.prefix,
|
|
237
|
+
key,
|
|
238
|
+
fullKey,
|
|
239
|
+
cacheEnabled: isCacheEnabled()
|
|
240
|
+
});
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (isRedisGloballyDisabled()) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const redis = getRedisClient();
|
|
248
|
+
if (!redis) {
|
|
249
|
+
logger.warn(
|
|
250
|
+
`Cache storage failed due to Redis unavailability: ${fullKey}`,
|
|
251
|
+
{
|
|
252
|
+
prefix: this.prefix,
|
|
253
|
+
key,
|
|
254
|
+
fullKey,
|
|
255
|
+
valueType: typeof value,
|
|
256
|
+
valueSize: ((_a = JSON.stringify(value)) == null ? void 0 : _a.length) || 0,
|
|
257
|
+
ttl: ttl ? `${ttl}s` : "\uAE30\uBCF8\uAC12",
|
|
258
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
logger.debug(`Cache storage started: ${fullKey}`, {
|
|
264
|
+
prefix: this.prefix,
|
|
265
|
+
key,
|
|
266
|
+
fullKey,
|
|
267
|
+
valueType: typeof value,
|
|
268
|
+
valueSize: ((_b = JSON.stringify(value)) == null ? void 0 : _b.length) || 0,
|
|
269
|
+
ttl: ttl ? `${ttl}s` : "\uAE30\uBCF8\uAC12",
|
|
270
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
271
|
+
});
|
|
272
|
+
if (ttl) {
|
|
273
|
+
await redis.set(fullKey, value, { ex: ttl });
|
|
274
|
+
} else {
|
|
275
|
+
await redis.set(fullKey, value);
|
|
276
|
+
}
|
|
277
|
+
const responseTime = Date.now() - startTime;
|
|
278
|
+
this.connectionStatus.isConnected = true;
|
|
279
|
+
this.connectionStatus.lastPingTime = /* @__PURE__ */ new Date();
|
|
280
|
+
resetRedisGlobalState();
|
|
281
|
+
logger.info(`[Cache:R] set: ${fullKey}`, {
|
|
282
|
+
prefix: this.prefix,
|
|
283
|
+
key,
|
|
284
|
+
fullKey,
|
|
285
|
+
responseTime: `${responseTime}ms`,
|
|
286
|
+
ttl: ttl ? `${ttl}s` : "\uAE30\uBCF8\uAC12"
|
|
287
|
+
});
|
|
288
|
+
} catch (error) {
|
|
289
|
+
const responseTime = Date.now() - startTime;
|
|
290
|
+
const errorMessage = error instanceof Error ? error.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958";
|
|
291
|
+
this.connectionStatus.connectionErrors++;
|
|
292
|
+
this.connectionStatus.lastConnectionError = errorMessage;
|
|
293
|
+
this.connectionStatus.lastConnectionErrorTime = /* @__PURE__ */ new Date();
|
|
294
|
+
notifyRedisError(
|
|
295
|
+
error instanceof Error ? error : new Error(errorMessage),
|
|
296
|
+
`CacheManager.set:${this.prefix}`
|
|
297
|
+
);
|
|
298
|
+
logger.error(`Cache storage failed: ${fullKey}`, {
|
|
299
|
+
prefix: this.prefix,
|
|
300
|
+
key,
|
|
301
|
+
fullKey,
|
|
302
|
+
error: errorMessage,
|
|
303
|
+
responseTime: `${responseTime}ms`,
|
|
304
|
+
valueType: typeof value,
|
|
305
|
+
ttl,
|
|
306
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
async delete(key) {
|
|
311
|
+
const startTime = Date.now();
|
|
312
|
+
const fullKey = `${this.prefix}:${key}`;
|
|
313
|
+
try {
|
|
314
|
+
const redis = getRedisClient();
|
|
315
|
+
if (!redis) {
|
|
316
|
+
logger.warn(
|
|
317
|
+
`Cache deletion failed due to Redis unavailability: ${fullKey}`,
|
|
318
|
+
{
|
|
319
|
+
prefix: this.prefix,
|
|
320
|
+
key,
|
|
321
|
+
fullKey
|
|
322
|
+
}
|
|
323
|
+
);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
logger.debug(`Cache deletion started: ${fullKey}`, {
|
|
327
|
+
prefix: this.prefix,
|
|
328
|
+
key,
|
|
329
|
+
fullKey,
|
|
330
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
331
|
+
});
|
|
332
|
+
await redis.del(fullKey);
|
|
333
|
+
const responseTime = Date.now() - startTime;
|
|
334
|
+
this.connectionStatus.isConnected = true;
|
|
335
|
+
this.connectionStatus.lastPingTime = /* @__PURE__ */ new Date();
|
|
336
|
+
logger.debug(`Cache deletion completed: ${fullKey}`, {
|
|
337
|
+
prefix: this.prefix,
|
|
338
|
+
key,
|
|
339
|
+
fullKey,
|
|
340
|
+
responseTime: `${responseTime}ms`
|
|
341
|
+
});
|
|
342
|
+
} catch (error) {
|
|
343
|
+
const responseTime = Date.now() - startTime;
|
|
344
|
+
const errorMessage = error instanceof Error ? error.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958";
|
|
345
|
+
this.connectionStatus.connectionErrors++;
|
|
346
|
+
this.connectionStatus.lastConnectionError = errorMessage;
|
|
347
|
+
this.connectionStatus.lastConnectionErrorTime = /* @__PURE__ */ new Date();
|
|
348
|
+
logger.error(`Cache deletion failed: ${fullKey}`, {
|
|
349
|
+
prefix: this.prefix,
|
|
350
|
+
key,
|
|
351
|
+
fullKey,
|
|
352
|
+
error: errorMessage,
|
|
353
|
+
responseTime: `${responseTime}ms`,
|
|
354
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
async deletePattern(pattern) {
|
|
359
|
+
const redis = getRedisClient();
|
|
360
|
+
if (!redis) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
try {
|
|
364
|
+
let cursor = 0;
|
|
365
|
+
do {
|
|
366
|
+
const result = await redis.scan(cursor, {
|
|
367
|
+
match: this.getKey(pattern),
|
|
368
|
+
count: 100
|
|
369
|
+
});
|
|
370
|
+
const nextCursor = result[0];
|
|
371
|
+
const keys = result[1];
|
|
372
|
+
cursor = typeof nextCursor === "string" ? parseInt(nextCursor, 10) : nextCursor;
|
|
373
|
+
if (Array.isArray(keys) && keys.length > 0) {
|
|
374
|
+
await redis.del(...keys);
|
|
375
|
+
}
|
|
376
|
+
} while (cursor !== 0);
|
|
377
|
+
this.connectionStatus.isConnected = true;
|
|
378
|
+
this.connectionStatus.lastPingTime = /* @__PURE__ */ new Date();
|
|
379
|
+
} catch (error) {
|
|
380
|
+
logger.error("Cache delete pattern error:", error);
|
|
381
|
+
this.connectionStatus.connectionErrors++;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
async exists(key) {
|
|
385
|
+
const redis = getRedisClient();
|
|
386
|
+
if (!redis) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
const result = await redis.exists(this.getKey(key));
|
|
391
|
+
this.connectionStatus.isConnected = true;
|
|
392
|
+
this.connectionStatus.lastPingTime = /* @__PURE__ */ new Date();
|
|
393
|
+
return result === 1;
|
|
394
|
+
} catch (error) {
|
|
395
|
+
logger.error("Cache exists error:", error);
|
|
396
|
+
this.connectionStatus.connectionErrors++;
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async increment(key, value = 1) {
|
|
401
|
+
const redis = getRedisClient();
|
|
402
|
+
if (!redis) {
|
|
403
|
+
return 0;
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const result = await redis.incrby(this.getKey(key), value);
|
|
407
|
+
this.connectionStatus.isConnected = true;
|
|
408
|
+
this.connectionStatus.lastPingTime = /* @__PURE__ */ new Date();
|
|
409
|
+
return result;
|
|
410
|
+
} catch (error) {
|
|
411
|
+
logger.error("Cache increment error:", error);
|
|
412
|
+
this.connectionStatus.connectionErrors++;
|
|
413
|
+
return 0;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
async expire(key, ttl) {
|
|
417
|
+
const redis = getRedisClient();
|
|
418
|
+
if (!redis) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
try {
|
|
422
|
+
await redis.expire(this.getKey(key), ttl);
|
|
423
|
+
this.connectionStatus.isConnected = true;
|
|
424
|
+
this.connectionStatus.lastPingTime = /* @__PURE__ */ new Date();
|
|
425
|
+
} catch (error) {
|
|
426
|
+
logger.error("Cache expire error:", error);
|
|
427
|
+
this.connectionStatus.connectionErrors++;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
export {
|
|
433
|
+
RedisCacheManager
|
|
434
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError
|
|
3
|
+
} from "./chunk-MLGO3HLS.js";
|
|
4
|
+
import {
|
|
5
|
+
ERROR_CODES,
|
|
6
|
+
formatErrorMessage,
|
|
7
|
+
getHttpStatus
|
|
8
|
+
} from "./chunk-Y3OTJH2S.js";
|
|
9
|
+
import {
|
|
10
|
+
logger
|
|
11
|
+
} from "./chunk-EZR55KV2.js";
|
|
12
|
+
import {
|
|
13
|
+
__spreadProps,
|
|
14
|
+
__spreadValues
|
|
15
|
+
} from "./chunk-ORMEWXMH.js";
|
|
16
|
+
|
|
17
|
+
// src/error/error-handler.ts
|
|
18
|
+
import { NextResponse } from "next/server";
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
var PRISMA_ERROR_MAP = {
|
|
21
|
+
P2000: { code: 40001, message: "\uC785\uB825\uAC12\uC774 \uB108\uBB34 \uAE41\uB2C8\uB2E4." },
|
|
22
|
+
P2001: { code: 40401, message: "\uB808\uCF54\uB4DC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4." },
|
|
23
|
+
P2002: { code: 40905, message: "\uC774\uBBF8 \uC874\uC7AC\uD558\uB294 \uB370\uC774\uD130\uC785\uB2C8\uB2E4." },
|
|
24
|
+
P2003: { code: 40001, message: "\uC678\uB798 \uD0A4 \uC81C\uC57D \uC870\uAC74 \uC704\uBC18\uC785\uB2C8\uB2E4." },
|
|
25
|
+
P2025: { code: 40401, message: "\uB808\uCF54\uB4DC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4." }
|
|
26
|
+
};
|
|
27
|
+
function errorToResponse(error, requestPath) {
|
|
28
|
+
const processed = processError(error);
|
|
29
|
+
if (processed.status >= 500) {
|
|
30
|
+
logger.error("Server error", __spreadProps(__spreadValues({}, processed), { path: requestPath, stack: error instanceof Error ? error.stack : void 0 }));
|
|
31
|
+
} else if (processed.status >= 400) {
|
|
32
|
+
logger.warn("Client error", __spreadProps(__spreadValues({}, processed), { path: requestPath }));
|
|
33
|
+
}
|
|
34
|
+
return NextResponse.json(
|
|
35
|
+
{ success: false, error: { code: processed.code, message: processed.message, details: processed.details } },
|
|
36
|
+
{ status: processed.status }
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function processError(error) {
|
|
40
|
+
var _a;
|
|
41
|
+
if (error instanceof AppError) {
|
|
42
|
+
return { code: error.code, message: error.message, status: error.status, details: error.details };
|
|
43
|
+
}
|
|
44
|
+
if (error instanceof z.ZodError) {
|
|
45
|
+
const issues = error.errors.map((e) => ({ path: e.path.join("."), message: e.message }));
|
|
46
|
+
return {
|
|
47
|
+
code: ERROR_CODES.VALIDATION_ERROR.code,
|
|
48
|
+
message: formatErrorMessage(ERROR_CODES.VALIDATION_ERROR.code, (_a = issues[0]) == null ? void 0 : _a.message),
|
|
49
|
+
status: 400,
|
|
50
|
+
details: { issues }
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (error instanceof Error) {
|
|
54
|
+
const prismaMatch = error.message.match(/P\d{4}/);
|
|
55
|
+
if (prismaMatch) {
|
|
56
|
+
const mapping = PRISMA_ERROR_MAP[prismaMatch[0]];
|
|
57
|
+
if (mapping) {
|
|
58
|
+
return { code: mapping.code, message: formatErrorMessage(mapping.code, mapping.message), status: getHttpStatus(mapping.code) };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (error.message.toLowerCase().includes("not found")) {
|
|
62
|
+
return { code: ERROR_CODES.NOT_FOUND.code, message: formatErrorMessage(ERROR_CODES.NOT_FOUND.code), status: 404 };
|
|
63
|
+
}
|
|
64
|
+
if (error.message.toLowerCase().includes("unauthorized")) {
|
|
65
|
+
return { code: ERROR_CODES.UNAUTHORIZED.code, message: formatErrorMessage(ERROR_CODES.UNAUTHORIZED.code), status: 401 };
|
|
66
|
+
}
|
|
67
|
+
return { code: ERROR_CODES.SERVER_ERROR.code, message: formatErrorMessage(ERROR_CODES.SERVER_ERROR.code), status: 500 };
|
|
68
|
+
}
|
|
69
|
+
return { code: ERROR_CODES.INTERNAL_SERVER_ERROR.code, message: formatErrorMessage(ERROR_CODES.INTERNAL_SERVER_ERROR.code), status: 500 };
|
|
70
|
+
}
|
|
71
|
+
function withErrorHandler(handler) {
|
|
72
|
+
return async (request, ...args) => {
|
|
73
|
+
try {
|
|
74
|
+
return await handler(request, ...args);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
return errorToResponse(error, request.nextUrl.pathname);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
var ErrorResponse = {
|
|
81
|
+
// 400xx
|
|
82
|
+
validation: (message, details) => errorToResponse(AppError.validation(message, details ? __spreadValues({}, details) : void 0)),
|
|
83
|
+
badRequest: (message) => errorToResponse(AppError.badRequest(message)),
|
|
84
|
+
invalidUrl: () => errorToResponse(AppError.invalidUrl()),
|
|
85
|
+
invalidEmail: () => errorToResponse(AppError.invalidEmail()),
|
|
86
|
+
invalidAlias: () => errorToResponse(AppError.invalidAlias()),
|
|
87
|
+
// 401xx
|
|
88
|
+
unauthorized: (message) => errorToResponse(AppError.unauthorized(message)),
|
|
89
|
+
invalidToken: () => errorToResponse(AppError.invalidToken()),
|
|
90
|
+
tokenExpired: () => errorToResponse(AppError.tokenExpired()),
|
|
91
|
+
invalidCredentials: () => errorToResponse(AppError.invalidCredentials()),
|
|
92
|
+
sessionExpired: () => errorToResponse(AppError.sessionExpired()),
|
|
93
|
+
// 403xx
|
|
94
|
+
forbidden: (message) => errorToResponse(AppError.forbidden(message)),
|
|
95
|
+
emailNotVerified: () => errorToResponse(AppError.emailNotVerified()),
|
|
96
|
+
accountDisabled: () => errorToResponse(AppError.accountDisabled()),
|
|
97
|
+
accountLocked: () => errorToResponse(AppError.accountLocked()),
|
|
98
|
+
// 404xx
|
|
99
|
+
notFound: (message) => errorToResponse(AppError.notFound(message)),
|
|
100
|
+
userNotFound: () => errorToResponse(AppError.userNotFound()),
|
|
101
|
+
linkNotFound: () => errorToResponse(AppError.linkNotFound()),
|
|
102
|
+
// 409xx
|
|
103
|
+
conflict: (message) => errorToResponse(AppError.conflict(message)),
|
|
104
|
+
duplicate: (resource) => errorToResponse(AppError.duplicate(resource)),
|
|
105
|
+
emailExists: () => errorToResponse(AppError.emailExists()),
|
|
106
|
+
aliasExists: () => errorToResponse(AppError.aliasExists()),
|
|
107
|
+
// 422xx
|
|
108
|
+
businessRule: (message) => errorToResponse(AppError.businessRule(message)),
|
|
109
|
+
linkExpired: () => errorToResponse(AppError.linkExpired()),
|
|
110
|
+
linkInactive: () => errorToResponse(AppError.linkInactive()),
|
|
111
|
+
linkPasswordRequired: () => errorToResponse(AppError.linkPasswordRequired()),
|
|
112
|
+
linkPasswordIncorrect: () => errorToResponse(AppError.linkPasswordIncorrect()),
|
|
113
|
+
reservedWord: () => errorToResponse(AppError.reservedWord()),
|
|
114
|
+
quotaExceeded: () => errorToResponse(AppError.quotaExceeded()),
|
|
115
|
+
// 429xx
|
|
116
|
+
rateLimit: () => errorToResponse(AppError.rateLimit()),
|
|
117
|
+
dailyLimit: () => errorToResponse(AppError.dailyLimit()),
|
|
118
|
+
// 500xx
|
|
119
|
+
serverError: (message) => errorToResponse(AppError.serverError(message)),
|
|
120
|
+
databaseError: () => errorToResponse(AppError.databaseError()),
|
|
121
|
+
// 503xx
|
|
122
|
+
serviceUnavailable: () => errorToResponse(AppError.serviceUnavailable()),
|
|
123
|
+
externalServiceError: (service) => errorToResponse(AppError.externalServiceError(service)),
|
|
124
|
+
// 보안
|
|
125
|
+
accessBlocked: () => errorToResponse(AppError.accessBlocked()),
|
|
126
|
+
ipBlocked: () => errorToResponse(AppError.ipBlocked())
|
|
127
|
+
};
|
|
128
|
+
var error_handler_default = { errorToResponse, processError, withErrorHandler, ErrorResponse };
|
|
129
|
+
|
|
130
|
+
export {
|
|
131
|
+
errorToResponse,
|
|
132
|
+
processError,
|
|
133
|
+
withErrorHandler,
|
|
134
|
+
ErrorResponse,
|
|
135
|
+
error_handler_default
|
|
136
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError
|
|
3
|
+
} from "./chunk-MLGO3HLS.js";
|
|
4
|
+
import {
|
|
5
|
+
ERROR_CODES
|
|
6
|
+
} from "./chunk-Y3OTJH2S.js";
|
|
7
|
+
import {
|
|
8
|
+
logger
|
|
9
|
+
} from "./chunk-EZR55KV2.js";
|
|
10
|
+
|
|
11
|
+
// src/middleware/rate-limit.ts
|
|
12
|
+
var _rateLimitAdapter = null;
|
|
13
|
+
var _adapterWarningLogged = false;
|
|
14
|
+
function setRateLimitAdapter(adapter) {
|
|
15
|
+
const isInitialSetup = _rateLimitAdapter === null;
|
|
16
|
+
const previousTypes = _rateLimitAdapter ? Object.keys(_rateLimitAdapter.rateLimiters).join(", ") : "none";
|
|
17
|
+
const newTypes = Object.keys(adapter.rateLimiters).join(", ");
|
|
18
|
+
_rateLimitAdapter = adapter;
|
|
19
|
+
_adapterWarningLogged = false;
|
|
20
|
+
if (isInitialSetup) {
|
|
21
|
+
logger.info(
|
|
22
|
+
`[Rate Limit Middleware] \u2705 Initialized with types: [${newTypes}]`
|
|
23
|
+
);
|
|
24
|
+
} else {
|
|
25
|
+
logger.info(
|
|
26
|
+
`[Rate Limit Middleware] \u{1F504} Updated - Previous: [${previousTypes}] \u2192 New: [${newTypes}]`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function getRateLimitAdapter() {
|
|
31
|
+
if (!_rateLimitAdapter && !_adapterWarningLogged) {
|
|
32
|
+
logger.warn(
|
|
33
|
+
"[Rate Limit Middleware] Adapter not configured. Rate limiting is DISABLED.\nTo enable: Call setRateLimitAdapter() in instrumentation.ts"
|
|
34
|
+
);
|
|
35
|
+
_adapterWarningLogged = true;
|
|
36
|
+
}
|
|
37
|
+
return _rateLimitAdapter;
|
|
38
|
+
}
|
|
39
|
+
function createRateLimitMiddleware(type) {
|
|
40
|
+
return async (context, next) => {
|
|
41
|
+
const adapter = getRateLimitAdapter();
|
|
42
|
+
if (!adapter) {
|
|
43
|
+
logger.debug(`[Rate Limit Middleware] Skipping rate limit check for '${type}' (adapter not configured)`);
|
|
44
|
+
return await next();
|
|
45
|
+
}
|
|
46
|
+
if (adapter.isEnabled) {
|
|
47
|
+
const enabled = await adapter.isEnabled(type);
|
|
48
|
+
if (!enabled) {
|
|
49
|
+
return await next();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const ip = adapter.extractClientIp(context.request.headers);
|
|
53
|
+
const identifier = context.user ? `user:${context.user.id}` : `ip:${ip}`;
|
|
54
|
+
const limiter = adapter.rateLimiters[type];
|
|
55
|
+
if (!limiter) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`[Rate Limit Middleware] Unknown rate limit type: ${type}`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const result = await limiter.check(identifier);
|
|
61
|
+
context.metadata.rateLimit = {
|
|
62
|
+
limit: limiter.config.limit,
|
|
63
|
+
remaining: result.remaining,
|
|
64
|
+
reset: result.resetIn
|
|
65
|
+
};
|
|
66
|
+
if (!result.success) {
|
|
67
|
+
throw new AppError(
|
|
68
|
+
ERROR_CODES.RATE_LIMIT_EXCEEDED.code,
|
|
69
|
+
void 0,
|
|
70
|
+
// message는 에러 코드에서 자동 생성
|
|
71
|
+
{
|
|
72
|
+
resetIn: result.resetIn,
|
|
73
|
+
identifier,
|
|
74
|
+
type
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return await next();
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
var rateLimitMiddleware = {
|
|
82
|
+
/** API Rate Limit (분당 120회) */
|
|
83
|
+
api: createRateLimitMiddleware("api"),
|
|
84
|
+
/** 인증 Rate Limit (시간당 40회) */
|
|
85
|
+
auth: createRateLimitMiddleware("auth"),
|
|
86
|
+
/** 관리자 Rate Limit (분당 200회) */
|
|
87
|
+
admin: createRateLimitMiddleware("admin")
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export {
|
|
91
|
+
setRateLimitAdapter,
|
|
92
|
+
createRateLimitMiddleware,
|
|
93
|
+
rateLimitMiddleware
|
|
94
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/error/logging/transports/base.ts
|
|
2
|
+
var BaseTransport = class {
|
|
3
|
+
constructor(name, enabled = true) {
|
|
4
|
+
this.name = name;
|
|
5
|
+
this.enabled = enabled;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Transport 활성화 여부
|
|
9
|
+
*/
|
|
10
|
+
isEnabled() {
|
|
11
|
+
return this.enabled;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Transport 활성화
|
|
15
|
+
*/
|
|
16
|
+
enable() {
|
|
17
|
+
this.enabled = true;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Transport 비활성화
|
|
21
|
+
*/
|
|
22
|
+
disable() {
|
|
23
|
+
this.enabled = false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
BaseTransport
|
|
29
|
+
};
|