@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,404 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError
|
|
3
|
+
} from "./chunk-MLGO3HLS.js";
|
|
4
|
+
import {
|
|
5
|
+
ERROR_CODES,
|
|
6
|
+
formatErrorMessage
|
|
7
|
+
} from "./chunk-Y3OTJH2S.js";
|
|
8
|
+
import {
|
|
9
|
+
logApiRequest,
|
|
10
|
+
logApiResponse,
|
|
11
|
+
logger
|
|
12
|
+
} from "./chunk-EZR55KV2.js";
|
|
13
|
+
|
|
14
|
+
// src/utils/error-processor.ts
|
|
15
|
+
import { NextResponse } from "next/server";
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
var PRISMA_ERROR_MAP = {
|
|
18
|
+
P2000: { code: 40001, message: "\uC785\uB825\uAC12\uC774 \uB108\uBB34 \uAE41\uB2C8\uB2E4.", status: 400 },
|
|
19
|
+
P2001: { code: 40401, message: "\uC694\uCCAD\uD55C \uB808\uCF54\uB4DC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.", status: 404 },
|
|
20
|
+
P2002: { code: 40905, message: "\uC774\uBBF8 \uC874\uC7AC\uD558\uB294 \uB370\uC774\uD130\uC785\uB2C8\uB2E4.", status: 409 },
|
|
21
|
+
P2003: { code: 40001, message: "\uC678\uB798 \uD0A4 \uC81C\uC57D \uC870\uAC74 \uC704\uBC18\uC785\uB2C8\uB2E4.", status: 400 },
|
|
22
|
+
P2004: { code: 40001, message: "\uB370\uC774\uD130\uBCA0\uC774\uC2A4 \uC81C\uC57D \uC870\uAC74 \uC704\uBC18\uC785\uB2C8\uB2E4.", status: 400 },
|
|
23
|
+
P2005: { code: 40001, message: "\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 \uD544\uB4DC \uAC12\uC785\uB2C8\uB2E4.", status: 400 },
|
|
24
|
+
P2006: { code: 40001, message: "\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 \uAC12\uC785\uB2C8\uB2E4.", status: 400 },
|
|
25
|
+
P2011: { code: 40004, message: "Null \uC81C\uC57D \uC870\uAC74 \uC704\uBC18\uC785\uB2C8\uB2E4.", status: 400 },
|
|
26
|
+
P2014: { code: 40001, message: "\uD544\uC218 \uAD00\uACC4 \uC704\uBC18\uC785\uB2C8\uB2E4.", status: 400 },
|
|
27
|
+
P2015: { code: 40401, message: "\uAD00\uB828 \uB808\uCF54\uB4DC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.", status: 404 },
|
|
28
|
+
P2016: { code: 40001, message: "\uCFFC\uB9AC \uD574\uC11D \uC624\uB958\uC785\uB2C8\uB2E4.", status: 400 },
|
|
29
|
+
P2017: { code: 40001, message: "\uAD00\uACC4\uAC00 \uC5F0\uACB0\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4.", status: 400 },
|
|
30
|
+
P2018: { code: 40401, message: "\uC5F0\uACB0\uB41C \uB808\uCF54\uB4DC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.", status: 404 },
|
|
31
|
+
P2025: { code: 40401, message: "\uC694\uCCAD\uD55C \uB808\uCF54\uB4DC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.", status: 404 }
|
|
32
|
+
};
|
|
33
|
+
var ErrorProcessor = class {
|
|
34
|
+
/**
|
|
35
|
+
* 에러를 처리하여 표준화된 응답으로 변환
|
|
36
|
+
*/
|
|
37
|
+
static process(error) {
|
|
38
|
+
if (error instanceof AppError) {
|
|
39
|
+
return error.toJSON();
|
|
40
|
+
}
|
|
41
|
+
if (error instanceof z.ZodError) {
|
|
42
|
+
return this.handleZodError(error);
|
|
43
|
+
}
|
|
44
|
+
if (error instanceof Error) {
|
|
45
|
+
const prismaError = this.extractPrismaError(error);
|
|
46
|
+
if (prismaError) {
|
|
47
|
+
return prismaError;
|
|
48
|
+
}
|
|
49
|
+
if (error.message.includes("Unique constraint failed")) {
|
|
50
|
+
return {
|
|
51
|
+
code: ERROR_CODES.DUPLICATE_RESOURCE.code,
|
|
52
|
+
message: formatErrorMessage(ERROR_CODES.DUPLICATE_RESOURCE.code),
|
|
53
|
+
status: 409,
|
|
54
|
+
key: "DUPLICATE_RESOURCE",
|
|
55
|
+
category: "conflict",
|
|
56
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (error.message.includes("not found") || error.message.includes("Not found")) {
|
|
60
|
+
return {
|
|
61
|
+
code: ERROR_CODES.NOT_FOUND.code,
|
|
62
|
+
message: formatErrorMessage(ERROR_CODES.NOT_FOUND.code, error.message),
|
|
63
|
+
status: 404,
|
|
64
|
+
key: "NOT_FOUND",
|
|
65
|
+
category: "resource",
|
|
66
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (error.message.includes("unauthorized") || error.message.includes("Unauthorized")) {
|
|
70
|
+
return {
|
|
71
|
+
code: ERROR_CODES.UNAUTHORIZED.code,
|
|
72
|
+
message: formatErrorMessage(ERROR_CODES.UNAUTHORIZED.code, error.message),
|
|
73
|
+
status: 401,
|
|
74
|
+
key: "UNAUTHORIZED",
|
|
75
|
+
category: "auth",
|
|
76
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
code: ERROR_CODES.SERVER_ERROR.code,
|
|
81
|
+
message: formatErrorMessage(ERROR_CODES.SERVER_ERROR.code),
|
|
82
|
+
status: 500,
|
|
83
|
+
key: "SERVER_ERROR",
|
|
84
|
+
category: "server",
|
|
85
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
code: ERROR_CODES.INTERNAL_SERVER_ERROR.code,
|
|
90
|
+
message: formatErrorMessage(ERROR_CODES.INTERNAL_SERVER_ERROR.code),
|
|
91
|
+
status: 500,
|
|
92
|
+
key: "INTERNAL_SERVER_ERROR",
|
|
93
|
+
category: "server",
|
|
94
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Zod 검증 에러 처리
|
|
99
|
+
*/
|
|
100
|
+
static handleZodError(error) {
|
|
101
|
+
var _a;
|
|
102
|
+
const issues = error.errors.map((err) => ({
|
|
103
|
+
path: err.path.join("."),
|
|
104
|
+
message: err.message,
|
|
105
|
+
code: err.code
|
|
106
|
+
}));
|
|
107
|
+
const firstMessage = ((_a = issues[0]) == null ? void 0 : _a.message) || ERROR_CODES.VALIDATION_ERROR.message;
|
|
108
|
+
return {
|
|
109
|
+
code: ERROR_CODES.VALIDATION_ERROR.code,
|
|
110
|
+
message: formatErrorMessage(ERROR_CODES.VALIDATION_ERROR.code, firstMessage),
|
|
111
|
+
status: 400,
|
|
112
|
+
key: "VALIDATION_ERROR",
|
|
113
|
+
category: "validation",
|
|
114
|
+
details: { issues },
|
|
115
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Prisma 에러 추출 및 처리
|
|
120
|
+
*/
|
|
121
|
+
static extractPrismaError(error) {
|
|
122
|
+
const codeMatch = error.message.match(/P\d{4}/);
|
|
123
|
+
if (!codeMatch) return null;
|
|
124
|
+
const prismaCode = codeMatch[0];
|
|
125
|
+
const mapping = PRISMA_ERROR_MAP[prismaCode];
|
|
126
|
+
if (mapping) {
|
|
127
|
+
return {
|
|
128
|
+
code: mapping.code,
|
|
129
|
+
message: formatErrorMessage(mapping.code, mapping.message),
|
|
130
|
+
status: mapping.status,
|
|
131
|
+
key: "DATABASE_ERROR",
|
|
132
|
+
category: "server",
|
|
133
|
+
details: { prismaCode },
|
|
134
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
logger.error("Unmapped Prisma error", { prismaCode, message: error.message });
|
|
138
|
+
return {
|
|
139
|
+
code: ERROR_CODES.DATABASE_ERROR.code,
|
|
140
|
+
message: formatErrorMessage(ERROR_CODES.DATABASE_ERROR.code),
|
|
141
|
+
status: 500,
|
|
142
|
+
key: "DATABASE_ERROR",
|
|
143
|
+
category: "server",
|
|
144
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* 에러를 NextResponse로 변환
|
|
149
|
+
*/
|
|
150
|
+
static toResponse(error, requestPath) {
|
|
151
|
+
const processed = this.process(error);
|
|
152
|
+
if (processed.status >= 500) {
|
|
153
|
+
logger.error("Server error", {
|
|
154
|
+
code: processed.code,
|
|
155
|
+
message: processed.message,
|
|
156
|
+
status: processed.status,
|
|
157
|
+
path: requestPath,
|
|
158
|
+
details: processed.details,
|
|
159
|
+
originalError: error instanceof Error ? error.stack : error
|
|
160
|
+
});
|
|
161
|
+
} else if (processed.status >= 400) {
|
|
162
|
+
logger.warn("Client error", {
|
|
163
|
+
code: processed.code,
|
|
164
|
+
message: processed.message,
|
|
165
|
+
status: processed.status,
|
|
166
|
+
path: requestPath
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return NextResponse.json(
|
|
170
|
+
{
|
|
171
|
+
success: false,
|
|
172
|
+
error: {
|
|
173
|
+
code: processed.code,
|
|
174
|
+
message: processed.message,
|
|
175
|
+
details: processed.details
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
{ status: processed.status }
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* 에러 핸들러 래퍼 함수 (간단한 버전)
|
|
183
|
+
* try-catch 블록을 대체하여 사용
|
|
184
|
+
*/
|
|
185
|
+
static withErrorHandling(handler) {
|
|
186
|
+
return (async (...args) => {
|
|
187
|
+
try {
|
|
188
|
+
return await handler(...args);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
return this.toResponse(error);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
function withErrorHandling(handler, options = {}) {
|
|
196
|
+
return async (request, ...args) => {
|
|
197
|
+
var _a;
|
|
198
|
+
const startTime = Date.now();
|
|
199
|
+
try {
|
|
200
|
+
await logApiRequest(request);
|
|
201
|
+
const response = await handler(request, ...args);
|
|
202
|
+
logApiResponse(request, response);
|
|
203
|
+
if (options.preserveCustomResponses && response.status !== 200) {
|
|
204
|
+
return response;
|
|
205
|
+
}
|
|
206
|
+
return response;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
const responseTime = Date.now() - startTime;
|
|
209
|
+
if (options.customErrorHandler) {
|
|
210
|
+
try {
|
|
211
|
+
const customResponse = options.customErrorHandler(error, request);
|
|
212
|
+
logApiResponse(request, customResponse);
|
|
213
|
+
return customResponse;
|
|
214
|
+
} catch (customError) {
|
|
215
|
+
logger.error("Custom error handler failed:", { error: customError, originalError: error });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
let response;
|
|
219
|
+
if (error instanceof z.ZodError) {
|
|
220
|
+
const issues = error.errors.map((err) => ({
|
|
221
|
+
path: err.path.join("."),
|
|
222
|
+
message: err.message,
|
|
223
|
+
code: err.code
|
|
224
|
+
}));
|
|
225
|
+
const firstMessage = ((_a = issues[0]) == null ? void 0 : _a.message) || ERROR_CODES.VALIDATION_ERROR.message;
|
|
226
|
+
response = NextResponse.json(
|
|
227
|
+
{
|
|
228
|
+
success: false,
|
|
229
|
+
error: {
|
|
230
|
+
code: ERROR_CODES.VALIDATION_ERROR.code,
|
|
231
|
+
message: formatErrorMessage(ERROR_CODES.VALIDATION_ERROR.code, firstMessage),
|
|
232
|
+
details: { issues }
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
{ status: 400 }
|
|
236
|
+
);
|
|
237
|
+
logger.warn("Validation error:", {
|
|
238
|
+
error: issues,
|
|
239
|
+
responseTime: `${responseTime}ms`,
|
|
240
|
+
path: request.nextUrl.pathname
|
|
241
|
+
});
|
|
242
|
+
} else if (error instanceof AppError) {
|
|
243
|
+
response = NextResponse.json(
|
|
244
|
+
{
|
|
245
|
+
success: false,
|
|
246
|
+
error: {
|
|
247
|
+
code: error.code,
|
|
248
|
+
message: error.message,
|
|
249
|
+
details: error.details
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
{ status: error.status }
|
|
253
|
+
);
|
|
254
|
+
logger[options.logLevel || "error"]("App error:", {
|
|
255
|
+
error: error.message,
|
|
256
|
+
code: error.code,
|
|
257
|
+
status: error.status,
|
|
258
|
+
responseTime: `${responseTime}ms`,
|
|
259
|
+
path: request.nextUrl.pathname
|
|
260
|
+
});
|
|
261
|
+
} else if (error instanceof Error) {
|
|
262
|
+
response = ErrorProcessor.toResponse(error, request.nextUrl.pathname);
|
|
263
|
+
logger.error("Unexpected error:", {
|
|
264
|
+
error: error.message,
|
|
265
|
+
stack: error.stack,
|
|
266
|
+
responseTime: `${responseTime}ms`,
|
|
267
|
+
path: request.nextUrl.pathname
|
|
268
|
+
});
|
|
269
|
+
} else {
|
|
270
|
+
response = NextResponse.json(
|
|
271
|
+
{
|
|
272
|
+
success: false,
|
|
273
|
+
error: {
|
|
274
|
+
code: ERROR_CODES.SERVER_ERROR.code,
|
|
275
|
+
message: formatErrorMessage(ERROR_CODES.SERVER_ERROR.code)
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
{ status: 500 }
|
|
279
|
+
);
|
|
280
|
+
logger.error("Unknown error:", {
|
|
281
|
+
error,
|
|
282
|
+
responseTime: `${responseTime}ms`,
|
|
283
|
+
path: request.nextUrl.pathname
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
if (options.maskSensitiveInfo) {
|
|
287
|
+
response = await maskSensitiveInfo(response);
|
|
288
|
+
}
|
|
289
|
+
logApiResponse(request, response);
|
|
290
|
+
return response;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
async function maskSensitiveInfo(response) {
|
|
295
|
+
var _a, _b;
|
|
296
|
+
try {
|
|
297
|
+
const clonedResponse = response.clone();
|
|
298
|
+
const body = await clonedResponse.json();
|
|
299
|
+
if ((_a = body.error) == null ? void 0 : _a.details) {
|
|
300
|
+
delete body.error.details;
|
|
301
|
+
}
|
|
302
|
+
if ((_b = body.data) == null ? void 0 : _b.password) {
|
|
303
|
+
body.data.password = "***";
|
|
304
|
+
}
|
|
305
|
+
return NextResponse.json(body, { status: response.status });
|
|
306
|
+
} catch (e) {
|
|
307
|
+
return response;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function handlePrismaError(error) {
|
|
311
|
+
if (error && typeof error === "object" && "code" in error) {
|
|
312
|
+
const prismaError = error;
|
|
313
|
+
if (prismaError.code === "P2002") {
|
|
314
|
+
const errorInfo2 = ERROR_CODES.DUPLICATE_RESOURCE;
|
|
315
|
+
return NextResponse.json(
|
|
316
|
+
{
|
|
317
|
+
success: false,
|
|
318
|
+
error: {
|
|
319
|
+
code: errorInfo2.code,
|
|
320
|
+
message: formatErrorMessage(errorInfo2.code)
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
{ status: errorInfo2.status }
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
if (prismaError.code === "P2025") {
|
|
327
|
+
const errorInfo2 = ERROR_CODES.NOT_FOUND;
|
|
328
|
+
return NextResponse.json(
|
|
329
|
+
{
|
|
330
|
+
success: false,
|
|
331
|
+
error: {
|
|
332
|
+
code: errorInfo2.code,
|
|
333
|
+
message: formatErrorMessage(errorInfo2.code)
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
{ status: errorInfo2.status }
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
if (prismaError.code === "P2003") {
|
|
340
|
+
const errorInfo2 = ERROR_CODES.BUSINESS_RULE_VIOLATION;
|
|
341
|
+
return NextResponse.json(
|
|
342
|
+
{
|
|
343
|
+
success: false,
|
|
344
|
+
error: {
|
|
345
|
+
code: errorInfo2.code,
|
|
346
|
+
message: formatErrorMessage(errorInfo2.code)
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
{ status: errorInfo2.status }
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const errorInfo = ERROR_CODES.DATABASE_ERROR;
|
|
354
|
+
return NextResponse.json(
|
|
355
|
+
{
|
|
356
|
+
success: false,
|
|
357
|
+
error: {
|
|
358
|
+
code: errorInfo.code,
|
|
359
|
+
message: formatErrorMessage(errorInfo.code)
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
{ status: errorInfo.status }
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
function throwBusinessRuleError(message, code) {
|
|
366
|
+
throw code ? new AppError(code, message) : AppError.businessRule(message);
|
|
367
|
+
}
|
|
368
|
+
function throwNotFoundError(message, code) {
|
|
369
|
+
throw code ? new AppError(code, message) : AppError.notFound(message);
|
|
370
|
+
}
|
|
371
|
+
function throwConflictError(message, code) {
|
|
372
|
+
throw code ? new AppError(code, message) : AppError.conflict(message);
|
|
373
|
+
}
|
|
374
|
+
function throwForbiddenError(message, code) {
|
|
375
|
+
throw code ? new AppError(code, message) : AppError.forbidden(message);
|
|
376
|
+
}
|
|
377
|
+
function throwUnauthorizedError(message, code) {
|
|
378
|
+
throw code ? new AppError(code, message) : AppError.unauthorized(message);
|
|
379
|
+
}
|
|
380
|
+
function throwValidationError(message, code) {
|
|
381
|
+
throw code ? new AppError(code, message) : AppError.validation(message);
|
|
382
|
+
}
|
|
383
|
+
function throwBadRequestError(message, code) {
|
|
384
|
+
throw code ? new AppError(code, message) : AppError.badRequest(message);
|
|
385
|
+
}
|
|
386
|
+
var processError = ErrorProcessor.process.bind(ErrorProcessor);
|
|
387
|
+
var errorToResponse = ErrorProcessor.toResponse.bind(ErrorProcessor);
|
|
388
|
+
var error_processor_default = ErrorProcessor;
|
|
389
|
+
|
|
390
|
+
export {
|
|
391
|
+
ErrorProcessor,
|
|
392
|
+
withErrorHandling,
|
|
393
|
+
handlePrismaError,
|
|
394
|
+
throwBusinessRuleError,
|
|
395
|
+
throwNotFoundError,
|
|
396
|
+
throwConflictError,
|
|
397
|
+
throwForbiddenError,
|
|
398
|
+
throwUnauthorizedError,
|
|
399
|
+
throwValidationError,
|
|
400
|
+
throwBadRequestError,
|
|
401
|
+
processError,
|
|
402
|
+
errorToResponse,
|
|
403
|
+
error_processor_default
|
|
404
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// src/auth/core/jwt/client.ts
|
|
2
|
+
var JWTClientManager = class {
|
|
3
|
+
constructor(storageKey = "jwt_tokens") {
|
|
4
|
+
this.storageKey = storageKey;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 로컬 스토리지에서 토큰 가져오기
|
|
8
|
+
*/
|
|
9
|
+
getStoredTokens() {
|
|
10
|
+
try {
|
|
11
|
+
if (typeof window === "undefined") {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const stored = localStorage.getItem(this.storageKey);
|
|
15
|
+
if (!stored) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const tokens = JSON.parse(stored);
|
|
19
|
+
if (tokens.expiresAt && Date.now() > tokens.expiresAt) {
|
|
20
|
+
console.debug("Stored tokens expired, clearing storage");
|
|
21
|
+
this.clearStoredTokens();
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return tokens;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error("Failed to get stored tokens", { error });
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 토큰을 로컬 스토리지에 저장
|
|
32
|
+
*/
|
|
33
|
+
storeTokens(accessToken, refreshToken, expiresIn = 7 * 24 * 60 * 60) {
|
|
34
|
+
try {
|
|
35
|
+
if (typeof window === "undefined") {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const expiresAt = Date.now() + expiresIn * 1e3;
|
|
39
|
+
const tokens = {
|
|
40
|
+
accessToken,
|
|
41
|
+
refreshToken,
|
|
42
|
+
expiresAt
|
|
43
|
+
};
|
|
44
|
+
localStorage.setItem(this.storageKey, JSON.stringify(tokens));
|
|
45
|
+
console.debug("Tokens stored successfully", {
|
|
46
|
+
expiresAt: new Date(expiresAt).toISOString()
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error("Failed to store tokens", { error });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 로컬 스토리지에서 토큰 제거
|
|
54
|
+
*/
|
|
55
|
+
clearStoredTokens() {
|
|
56
|
+
try {
|
|
57
|
+
if (typeof window === "undefined") {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
localStorage.removeItem(this.storageKey);
|
|
61
|
+
console.debug("Stored tokens cleared");
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error("Failed to clear stored tokens", { error });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* JWT 토큰에서 페이로드 디코딩 (검증 없음)
|
|
68
|
+
*/
|
|
69
|
+
decodeJWTPayload(token) {
|
|
70
|
+
try {
|
|
71
|
+
const parts = token.split(".");
|
|
72
|
+
if (parts.length !== 3) {
|
|
73
|
+
throw new Error("Invalid JWT format");
|
|
74
|
+
}
|
|
75
|
+
const payload = JSON.parse(atob(parts[1]));
|
|
76
|
+
return payload;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error("Failed to decode JWT payload", { error });
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 토큰 만료 여부 확인
|
|
84
|
+
*/
|
|
85
|
+
isTokenExpired(token) {
|
|
86
|
+
try {
|
|
87
|
+
const payload = this.decodeJWTPayload(token);
|
|
88
|
+
if (!payload || !payload.exp) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
const currentTime = Math.floor(Date.now() / 1e3);
|
|
92
|
+
return payload.exp < currentTime;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error("Failed to check token expiration", { error });
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 토큰 남은 시간 (초)
|
|
100
|
+
*/
|
|
101
|
+
getTokenRemainingTime(token) {
|
|
102
|
+
try {
|
|
103
|
+
const payload = this.decodeJWTPayload(token);
|
|
104
|
+
if (!payload || !payload.exp) {
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
const currentTime = Math.floor(Date.now() / 1e3);
|
|
108
|
+
const remainingTime = payload.exp - currentTime;
|
|
109
|
+
return Math.max(0, remainingTime);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error("Failed to get token remaining time", { error });
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 토큰에서 사용자 정보 추출
|
|
117
|
+
*/
|
|
118
|
+
extractUserFromToken(token) {
|
|
119
|
+
try {
|
|
120
|
+
const payload = this.decodeJWTPayload(token);
|
|
121
|
+
if (!payload || !payload.userId || !payload.email || !payload.role) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
userId: payload.userId,
|
|
126
|
+
email: payload.email,
|
|
127
|
+
role: payload.role
|
|
128
|
+
};
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error("Failed to extract user from token", { error });
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* 토큰에서 사용자 role 추출
|
|
136
|
+
*/
|
|
137
|
+
getUserRole(token) {
|
|
138
|
+
if (!token) {
|
|
139
|
+
return "USER";
|
|
140
|
+
}
|
|
141
|
+
const user = this.extractUserFromToken(token);
|
|
142
|
+
return (user == null ? void 0 : user.role) || "USER";
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Authorization 헤더 생성
|
|
146
|
+
*/
|
|
147
|
+
createAuthHeader(token) {
|
|
148
|
+
return `Bearer ${token}`;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* API 요청용 헤더 생성
|
|
152
|
+
*/
|
|
153
|
+
createApiHeaders(token) {
|
|
154
|
+
return {
|
|
155
|
+
Authorization: this.createAuthHeader(token),
|
|
156
|
+
"Content-Type": "application/json"
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 토큰이 곧 만료되는지 확인 (5분 이내)
|
|
161
|
+
*/
|
|
162
|
+
isTokenExpiringSoon(token, thresholdSeconds = 300) {
|
|
163
|
+
const remainingTime = this.getTokenRemainingTime(token);
|
|
164
|
+
return remainingTime > 0 && remainingTime <= thresholdSeconds;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 토큰 만료 시간 포맷팅
|
|
168
|
+
*/
|
|
169
|
+
getTokenExpirationString(token) {
|
|
170
|
+
try {
|
|
171
|
+
const payload = this.decodeJWTPayload(token);
|
|
172
|
+
if (!payload || !payload.exp) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
const expirationDate = new Date(payload.exp * 1e3);
|
|
176
|
+
return expirationDate.toLocaleString();
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error("Failed to get token expiration string", { error });
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* 토큰 발급 시간 포맷팅
|
|
184
|
+
*/
|
|
185
|
+
getTokenIssuedAtString(token) {
|
|
186
|
+
try {
|
|
187
|
+
const payload = this.decodeJWTPayload(token);
|
|
188
|
+
if (!payload || !payload.iat) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const issuedDate = new Date(payload.iat * 1e3);
|
|
192
|
+
return issuedDate.toLocaleString();
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.error("Failed to get token issued at string", { error });
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
var defaultManager = new JWTClientManager();
|
|
200
|
+
var getStoredTokens = () => defaultManager.getStoredTokens();
|
|
201
|
+
var storeTokens = (accessToken, refreshToken, expiresIn) => defaultManager.storeTokens(accessToken, refreshToken, expiresIn);
|
|
202
|
+
var clearStoredTokens = () => defaultManager.clearStoredTokens();
|
|
203
|
+
var clearTokens = () => defaultManager.clearStoredTokens();
|
|
204
|
+
var decodeJWTPayload = (token) => defaultManager.decodeJWTPayload(token);
|
|
205
|
+
var isTokenExpired = (token) => defaultManager.isTokenExpired(token);
|
|
206
|
+
var getTokenRemainingTime = (token) => defaultManager.getTokenRemainingTime(token);
|
|
207
|
+
var extractUserFromToken = (token) => defaultManager.extractUserFromToken(token);
|
|
208
|
+
var getUserRole = (token) => defaultManager.getUserRole(token);
|
|
209
|
+
var createAuthHeader = (token) => defaultManager.createAuthHeader(token);
|
|
210
|
+
var createApiHeaders = (token) => defaultManager.createApiHeaders(token);
|
|
211
|
+
var isTokenExpiringSoon = (token) => defaultManager.isTokenExpiringSoon(token);
|
|
212
|
+
var getTokenExpirationString = (token) => defaultManager.getTokenExpirationString(token);
|
|
213
|
+
var getTokenIssuedAtString = (token) => defaultManager.getTokenIssuedAtString(token);
|
|
214
|
+
|
|
215
|
+
export {
|
|
216
|
+
JWTClientManager,
|
|
217
|
+
getStoredTokens,
|
|
218
|
+
storeTokens,
|
|
219
|
+
clearStoredTokens,
|
|
220
|
+
clearTokens,
|
|
221
|
+
decodeJWTPayload,
|
|
222
|
+
isTokenExpired,
|
|
223
|
+
getTokenRemainingTime,
|
|
224
|
+
extractUserFromToken,
|
|
225
|
+
getUserRole,
|
|
226
|
+
createAuthHeader,
|
|
227
|
+
createApiHeaders,
|
|
228
|
+
isTokenExpiringSoon,
|
|
229
|
+
getTokenExpirationString,
|
|
230
|
+
getTokenIssuedAtString
|
|
231
|
+
};
|
|
File without changes
|