@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,137 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadValues
|
|
3
|
+
} from "./chunk-ORMEWXMH.js";
|
|
4
|
+
|
|
5
|
+
// src/utils/timezone.ts
|
|
6
|
+
function getCurrentUTC() {
|
|
7
|
+
return /* @__PURE__ */ new Date();
|
|
8
|
+
}
|
|
9
|
+
function utcToLocal(utcDate, timezone) {
|
|
10
|
+
const date = new Date(utcDate);
|
|
11
|
+
if (timezone) {
|
|
12
|
+
return new Date(date.toLocaleString("en-US", { timeZone: timezone }));
|
|
13
|
+
}
|
|
14
|
+
return date;
|
|
15
|
+
}
|
|
16
|
+
function localToUTC(localDate) {
|
|
17
|
+
const date = new Date(localDate);
|
|
18
|
+
return new Date(date.getTime() - date.getTimezoneOffset() * 6e4);
|
|
19
|
+
}
|
|
20
|
+
function formatUserFriendlyDate(date, options) {
|
|
21
|
+
const dateObj = new Date(date);
|
|
22
|
+
const defaultOptions = __spreadValues({
|
|
23
|
+
year: "numeric",
|
|
24
|
+
month: "long",
|
|
25
|
+
day: "numeric",
|
|
26
|
+
hour: "2-digit",
|
|
27
|
+
minute: "2-digit",
|
|
28
|
+
timeZoneName: "short",
|
|
29
|
+
hour12: false
|
|
30
|
+
}, options);
|
|
31
|
+
return dateObj.toLocaleDateString(void 0, defaultOptions);
|
|
32
|
+
}
|
|
33
|
+
function formatSimpleDate(date) {
|
|
34
|
+
const dateObj = new Date(date);
|
|
35
|
+
return dateObj.toLocaleDateString(void 0, {
|
|
36
|
+
year: "numeric",
|
|
37
|
+
month: "2-digit",
|
|
38
|
+
day: "2-digit"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function formatSimpleTime(date) {
|
|
42
|
+
const dateObj = new Date(date);
|
|
43
|
+
return dateObj.toLocaleTimeString(void 0, {
|
|
44
|
+
hour: "2-digit",
|
|
45
|
+
minute: "2-digit",
|
|
46
|
+
second: "2-digit",
|
|
47
|
+
hour12: false
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function formatFullDateTime(date) {
|
|
51
|
+
const dateObj = new Date(date);
|
|
52
|
+
const dateStr = dateObj.toLocaleDateString(void 0, {
|
|
53
|
+
year: "numeric",
|
|
54
|
+
month: "2-digit",
|
|
55
|
+
day: "2-digit"
|
|
56
|
+
});
|
|
57
|
+
const timeStr = dateObj.toLocaleTimeString(void 0, {
|
|
58
|
+
hour: "2-digit",
|
|
59
|
+
minute: "2-digit",
|
|
60
|
+
second: "2-digit",
|
|
61
|
+
hour12: false
|
|
62
|
+
});
|
|
63
|
+
return `${dateStr} ${timeStr}`;
|
|
64
|
+
}
|
|
65
|
+
function formatTableDateTime(date) {
|
|
66
|
+
const dateObj = new Date(date);
|
|
67
|
+
return {
|
|
68
|
+
date: dateObj.toLocaleDateString(void 0, {
|
|
69
|
+
year: "numeric",
|
|
70
|
+
month: "2-digit",
|
|
71
|
+
day: "2-digit"
|
|
72
|
+
}),
|
|
73
|
+
time: dateObj.toLocaleTimeString(void 0, {
|
|
74
|
+
hour: "2-digit",
|
|
75
|
+
minute: "2-digit",
|
|
76
|
+
second: "2-digit",
|
|
77
|
+
hour12: false
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function getRelativeTime(date) {
|
|
82
|
+
const now = /* @__PURE__ */ new Date();
|
|
83
|
+
const targetDate = new Date(date);
|
|
84
|
+
const diffInSeconds = Math.floor(
|
|
85
|
+
(now.getTime() - targetDate.getTime()) / 1e3
|
|
86
|
+
);
|
|
87
|
+
if (diffInSeconds < 60) {
|
|
88
|
+
return "just now";
|
|
89
|
+
}
|
|
90
|
+
const diffInMinutes = Math.floor(diffInSeconds / 60);
|
|
91
|
+
if (diffInMinutes < 60) {
|
|
92
|
+
return `${diffInMinutes}m ago`;
|
|
93
|
+
}
|
|
94
|
+
const diffInHours = Math.floor(diffInMinutes / 60);
|
|
95
|
+
if (diffInHours < 24) {
|
|
96
|
+
return `${diffInHours}h ago`;
|
|
97
|
+
}
|
|
98
|
+
const diffInDays = Math.floor(diffInHours / 24);
|
|
99
|
+
if (diffInDays < 7) {
|
|
100
|
+
return `${diffInDays}d ago`;
|
|
101
|
+
}
|
|
102
|
+
const diffInWeeks = Math.floor(diffInDays / 7);
|
|
103
|
+
if (diffInWeeks < 4) {
|
|
104
|
+
return `${diffInWeeks}w ago`;
|
|
105
|
+
}
|
|
106
|
+
const diffInMonths = Math.floor(diffInDays / 30);
|
|
107
|
+
if (diffInMonths < 12) {
|
|
108
|
+
return `${diffInMonths}mo ago`;
|
|
109
|
+
}
|
|
110
|
+
const diffInYears = Math.floor(diffInDays / 365);
|
|
111
|
+
return `${diffInYears}y ago`;
|
|
112
|
+
}
|
|
113
|
+
function getUserTimezone() {
|
|
114
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
115
|
+
}
|
|
116
|
+
function getTimezoneOffset() {
|
|
117
|
+
return (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
118
|
+
}
|
|
119
|
+
function toUTCISOString(date) {
|
|
120
|
+
const dateObj = new Date(date);
|
|
121
|
+
return dateObj.toISOString();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
getCurrentUTC,
|
|
126
|
+
utcToLocal,
|
|
127
|
+
localToUTC,
|
|
128
|
+
formatUserFriendlyDate,
|
|
129
|
+
formatSimpleDate,
|
|
130
|
+
formatSimpleTime,
|
|
131
|
+
formatFullDateTime,
|
|
132
|
+
formatTableDateTime,
|
|
133
|
+
getRelativeTime,
|
|
134
|
+
getUserTimezone,
|
|
135
|
+
getTimezoneOffset,
|
|
136
|
+
toUTCISOString
|
|
137
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getENV,
|
|
3
|
+
isCacheEnabled
|
|
4
|
+
} from "./chunk-I47QEDTX.js";
|
|
5
|
+
|
|
6
|
+
// src/cache/cache-config.ts
|
|
7
|
+
var getCacheConfig = {
|
|
8
|
+
// Analytics 캐시 설정
|
|
9
|
+
analytics: {
|
|
10
|
+
enabled: () => getENV().CACHE.ANALYTICS.ENABLED && isCacheEnabled(),
|
|
11
|
+
duration: () => getENV().CACHE.ANALYTICS.DURATION
|
|
12
|
+
},
|
|
13
|
+
// User 캐시 설정
|
|
14
|
+
user: {
|
|
15
|
+
enabled: () => getENV().CACHE.USER.ENABLED && isCacheEnabled(),
|
|
16
|
+
duration: () => getENV().CACHE.USER.DURATION
|
|
17
|
+
},
|
|
18
|
+
// GeoIP 캐시 설정
|
|
19
|
+
geoip: {
|
|
20
|
+
enabled: () => getENV().CACHE.GEOIP.ENABLED && isCacheEnabled(),
|
|
21
|
+
duration: () => getENV().CACHE.GEOIP.DURATION
|
|
22
|
+
},
|
|
23
|
+
// Settings 캐시 설정
|
|
24
|
+
settings: {
|
|
25
|
+
enabled: () => getENV().CACHE.SETTINGS.ENABLED && isCacheEnabled(),
|
|
26
|
+
duration: () => getENV().CACHE.SETTINGS.DURATION
|
|
27
|
+
},
|
|
28
|
+
// Reserved Words 캐시 설정
|
|
29
|
+
reservedWords: {
|
|
30
|
+
enabled: () => getENV().CACHE.RESERVED_WORDS.ENABLED && isCacheEnabled(),
|
|
31
|
+
duration: () => getENV().CACHE.RESERVED_WORDS.DURATION
|
|
32
|
+
},
|
|
33
|
+
// Alias 캐시 설정
|
|
34
|
+
alias: {
|
|
35
|
+
enabled: () => getENV().CACHE.ALIAS.ENABLED && isCacheEnabled(),
|
|
36
|
+
duration: () => getENV().CACHE.ALIAS.DURATION
|
|
37
|
+
},
|
|
38
|
+
// Community 캐시 설정
|
|
39
|
+
community: {
|
|
40
|
+
enabled: () => getENV().CACHE.COMMUNITY.ENABLED && isCacheEnabled(),
|
|
41
|
+
duration: () => getENV().CACHE.COMMUNITY.DURATION
|
|
42
|
+
},
|
|
43
|
+
// Link 캐시 설정
|
|
44
|
+
link: {
|
|
45
|
+
enabled: () => getENV().CACHE.LINK.ENABLED && isCacheEnabled(),
|
|
46
|
+
duration: () => getENV().CACHE.LINK.DURATION
|
|
47
|
+
},
|
|
48
|
+
// Rate Limiter 캐시 설정
|
|
49
|
+
rateLimit: {
|
|
50
|
+
enabled: () => getENV().CACHE.RATE_LIMIT.ENABLED && isCacheEnabled(),
|
|
51
|
+
duration: () => getENV().CACHE.RATE_LIMIT.DURATION
|
|
52
|
+
},
|
|
53
|
+
// URL Shortener Token 캐시 설정
|
|
54
|
+
urlToken: {
|
|
55
|
+
enabled: () => getENV().CACHE.URL_TOKEN.ENABLED && isCacheEnabled(),
|
|
56
|
+
duration: () => getENV().CACHE.URL_TOKEN.DURATION
|
|
57
|
+
},
|
|
58
|
+
// API Key 캐시 설정
|
|
59
|
+
apiKey: {
|
|
60
|
+
enabled: () => getENV().CACHE.API_KEY.ENABLED && isCacheEnabled(),
|
|
61
|
+
duration: () => getENV().CACHE.API_KEY.DURATION
|
|
62
|
+
},
|
|
63
|
+
// API Config 캐시 설정
|
|
64
|
+
apiConfig: {
|
|
65
|
+
enabled: () => getENV().CACHE.API_CONFIG.ENABLED && isCacheEnabled(),
|
|
66
|
+
duration: () => getENV().CACHE.API_CONFIG.DURATION
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var getCacheTTL = {
|
|
70
|
+
settings: () => getCacheConfig.settings.duration(),
|
|
71
|
+
reservedWords: () => getCacheConfig.reservedWords.duration(),
|
|
72
|
+
alias: () => getCacheConfig.alias.duration(),
|
|
73
|
+
user: () => getCacheConfig.user.duration(),
|
|
74
|
+
analytics: () => getCacheConfig.analytics.duration(),
|
|
75
|
+
geoip: () => getCacheConfig.geoip.duration(),
|
|
76
|
+
community: () => getCacheConfig.community.duration(),
|
|
77
|
+
link: () => getCacheConfig.link.duration(),
|
|
78
|
+
default: () => getCacheConfig.analytics.duration()
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
getCacheConfig,
|
|
83
|
+
getCacheTTL
|
|
84
|
+
};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logger
|
|
3
|
+
} from "./chunk-EZR55KV2.js";
|
|
4
|
+
import {
|
|
5
|
+
__spreadValues
|
|
6
|
+
} from "./chunk-ORMEWXMH.js";
|
|
7
|
+
|
|
8
|
+
// src/geolocation/batch-processor.ts
|
|
9
|
+
var BatchProcessor = class {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.config = __spreadValues({
|
|
12
|
+
batchSize: 50,
|
|
13
|
+
delayBetweenBatches: 2e3,
|
|
14
|
+
maxConcurrentBatches: 3,
|
|
15
|
+
retryAttempts: 3,
|
|
16
|
+
timeout: 1e4
|
|
17
|
+
}, config);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 배치 처리 실행
|
|
21
|
+
*/
|
|
22
|
+
async processBatch(items, processor, onProgress) {
|
|
23
|
+
const result = {
|
|
24
|
+
totalProcessed: 0,
|
|
25
|
+
successful: 0,
|
|
26
|
+
failed: 0,
|
|
27
|
+
skipped: 0,
|
|
28
|
+
errors: [],
|
|
29
|
+
processingTime: 0,
|
|
30
|
+
averageTimePerItem: 0
|
|
31
|
+
};
|
|
32
|
+
try {
|
|
33
|
+
logger.info(`Starting batch processing for ${items.length} items`);
|
|
34
|
+
for (let i = 0; i < items.length; i += this.config.batchSize) {
|
|
35
|
+
const batch = items.slice(i, i + this.config.batchSize);
|
|
36
|
+
try {
|
|
37
|
+
const batchResults = await processor(batch);
|
|
38
|
+
result.totalProcessed += batch.length;
|
|
39
|
+
result.successful += batchResults.length;
|
|
40
|
+
if (onProgress) {
|
|
41
|
+
onProgress(result.totalProcessed, items.length);
|
|
42
|
+
}
|
|
43
|
+
if (i + this.config.batchSize < items.length) {
|
|
44
|
+
await new Promise((resolve) => setTimeout(resolve, this.config.delayBetweenBatches));
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
logger.error(`Batch processing error for batch ${i}-${i + this.config.batchSize}`, { error });
|
|
48
|
+
result.errors.push(`Batch ${i}-${i + this.config.batchSize}: ${error}`);
|
|
49
|
+
result.failed += batch.length;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
logger.info("Batch processing completed", result);
|
|
53
|
+
return result;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
logger.error("Batch processing failed", { error });
|
|
56
|
+
result.errors.push(`Overall error: ${error}`);
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 재시도 로직이 포함된 배치 처리
|
|
62
|
+
*/
|
|
63
|
+
async processBatchWithRetry(items, processor, onProgress) {
|
|
64
|
+
const result = {
|
|
65
|
+
totalProcessed: 0,
|
|
66
|
+
successful: 0,
|
|
67
|
+
failed: 0,
|
|
68
|
+
skipped: 0,
|
|
69
|
+
errors: [],
|
|
70
|
+
processingTime: 0,
|
|
71
|
+
averageTimePerItem: 0
|
|
72
|
+
};
|
|
73
|
+
try {
|
|
74
|
+
logger.info(`Starting batch processing with retry for ${items.length} items`);
|
|
75
|
+
for (let i = 0; i < items.length; i += this.config.batchSize) {
|
|
76
|
+
const batch = items.slice(i, i + this.config.batchSize);
|
|
77
|
+
let batchResults = [];
|
|
78
|
+
let retryCount = 0;
|
|
79
|
+
while (retryCount < this.config.retryAttempts) {
|
|
80
|
+
try {
|
|
81
|
+
batchResults = await processor(batch);
|
|
82
|
+
break;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
retryCount++;
|
|
85
|
+
logger.warn(`Batch processing attempt ${retryCount} failed for batch ${i}-${i + this.config.batchSize}`, { error });
|
|
86
|
+
if (retryCount >= this.config.retryAttempts) {
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
await new Promise((resolve) => setTimeout(resolve, this.config.delayBetweenBatches * retryCount));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
result.totalProcessed += batch.length;
|
|
93
|
+
result.successful += batchResults.length;
|
|
94
|
+
if (onProgress) {
|
|
95
|
+
onProgress(result.totalProcessed, items.length);
|
|
96
|
+
}
|
|
97
|
+
if (i + this.config.batchSize < items.length) {
|
|
98
|
+
await new Promise((resolve) => setTimeout(resolve, this.config.delayBetweenBatches));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
logger.info("Batch processing with retry completed", result);
|
|
102
|
+
return result;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
logger.error("Batch processing with retry failed", { error });
|
|
105
|
+
result.errors.push(`Overall error: ${error}`);
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 동시 배치 처리 (병렬 처리)
|
|
111
|
+
*/
|
|
112
|
+
async processBatchConcurrent(items, processor, onProgress) {
|
|
113
|
+
const result = {
|
|
114
|
+
totalProcessed: 0,
|
|
115
|
+
successful: 0,
|
|
116
|
+
failed: 0,
|
|
117
|
+
skipped: 0,
|
|
118
|
+
errors: [],
|
|
119
|
+
processingTime: 0,
|
|
120
|
+
averageTimePerItem: 0
|
|
121
|
+
};
|
|
122
|
+
try {
|
|
123
|
+
logger.info(`Starting concurrent batch processing for ${items.length} items`);
|
|
124
|
+
const batches = [];
|
|
125
|
+
for (let i = 0; i < items.length; i += this.config.batchSize) {
|
|
126
|
+
batches.push(items.slice(i, i + this.config.batchSize));
|
|
127
|
+
}
|
|
128
|
+
const concurrentBatches = [];
|
|
129
|
+
for (let i = 0; i < batches.length; i += this.config.maxConcurrentBatches) {
|
|
130
|
+
concurrentBatches.push(batches.slice(i, i + this.config.maxConcurrentBatches));
|
|
131
|
+
}
|
|
132
|
+
for (const batchGroup of concurrentBatches) {
|
|
133
|
+
const promises = batchGroup.map(async (batch, index) => {
|
|
134
|
+
try {
|
|
135
|
+
const batchResults2 = await processor(batch);
|
|
136
|
+
return { success: true, results: batchResults2, batchIndex: index };
|
|
137
|
+
} catch (error) {
|
|
138
|
+
logger.error(`Concurrent batch processing error for batch ${index}`, { error });
|
|
139
|
+
return { success: false, error, batchIndex: index };
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const batchResults = await Promise.all(promises);
|
|
143
|
+
batchResults.forEach(({ success, results, error, batchIndex }) => {
|
|
144
|
+
const batch = batchGroup[batchIndex];
|
|
145
|
+
result.totalProcessed += batch.length;
|
|
146
|
+
if (success && results) {
|
|
147
|
+
result.successful += results.length;
|
|
148
|
+
} else {
|
|
149
|
+
result.failed += batch.length;
|
|
150
|
+
result.errors.push(`Concurrent batch ${batchIndex}: ${error}`);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (onProgress) {
|
|
154
|
+
onProgress(result.totalProcessed, items.length);
|
|
155
|
+
}
|
|
156
|
+
if (concurrentBatches.indexOf(batchGroup) < concurrentBatches.length - 1) {
|
|
157
|
+
await new Promise((resolve) => setTimeout(resolve, this.config.delayBetweenBatches));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
logger.info("Concurrent batch processing completed", result);
|
|
161
|
+
return result;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
logger.error("Concurrent batch processing failed", { error });
|
|
164
|
+
result.errors.push(`Overall error: ${error}`);
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 설정 업데이트
|
|
170
|
+
*/
|
|
171
|
+
updateConfig(newConfig) {
|
|
172
|
+
this.config = __spreadValues(__spreadValues({}, this.config), newConfig);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 현재 설정 조회
|
|
176
|
+
*/
|
|
177
|
+
getConfig() {
|
|
178
|
+
return __spreadValues({}, this.config);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
function createBatchProcessor(config) {
|
|
182
|
+
return new BatchProcessor(config);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export {
|
|
186
|
+
BatchProcessor,
|
|
187
|
+
createBatchProcessor
|
|
188
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
cn
|
|
3
|
+
} from "./chunk-62FLBG6B.js";
|
|
4
|
+
|
|
5
|
+
// src/components/ui/Badge.tsx
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
function Badge({
|
|
8
|
+
children,
|
|
9
|
+
variant = "default",
|
|
10
|
+
className
|
|
11
|
+
}) {
|
|
12
|
+
const baseClasses = "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2";
|
|
13
|
+
const variantClasses = {
|
|
14
|
+
default: "border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
|
|
15
|
+
secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
16
|
+
destructive: "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
|
|
17
|
+
outline: "text-foreground"
|
|
18
|
+
};
|
|
19
|
+
return /* @__PURE__ */ jsx("div", { className: cn(baseClasses, variantClasses[variant], className), children });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
Badge
|
|
24
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppError
|
|
3
|
+
} from "./chunk-MLGO3HLS.js";
|
|
4
|
+
import {
|
|
5
|
+
ERROR_CODES
|
|
6
|
+
} from "./chunk-Y3OTJH2S.js";
|
|
7
|
+
import {
|
|
8
|
+
JWTManager
|
|
9
|
+
} from "./chunk-T3LJYAMO.js";
|
|
10
|
+
import {
|
|
11
|
+
logger
|
|
12
|
+
} from "./chunk-EZR55KV2.js";
|
|
13
|
+
|
|
14
|
+
// src/middleware/auth.ts
|
|
15
|
+
function setAccessTokenBlacklistChecker(checker) {
|
|
16
|
+
globalThis.__accessTokenBlacklistChecker = checker;
|
|
17
|
+
logger.info(
|
|
18
|
+
"[Auth Middleware] Access Token blacklist checker configured"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
function getAccessTokenChecker() {
|
|
22
|
+
var _a;
|
|
23
|
+
return (_a = globalThis.__accessTokenBlacklistChecker) != null ? _a : null;
|
|
24
|
+
}
|
|
25
|
+
var _jwtManager = null;
|
|
26
|
+
var _jwtWarningLogged = false;
|
|
27
|
+
function getJWTManager() {
|
|
28
|
+
if (!_jwtManager) {
|
|
29
|
+
const secret = process.env.JWT_SECRET;
|
|
30
|
+
if (!secret) {
|
|
31
|
+
if (!_jwtWarningLogged) {
|
|
32
|
+
logger.warn(
|
|
33
|
+
"[Auth Middleware] JWT_SECRET not configured. Authentication is DISABLED.\nProtected routes will fail. Set JWT_SECRET environment variable to enable auth."
|
|
34
|
+
);
|
|
35
|
+
_jwtWarningLogged = true;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (secret.length < 32) {
|
|
40
|
+
logger.error(
|
|
41
|
+
"[Auth Middleware] JWT_SECRET must be at least 32 characters long"
|
|
42
|
+
);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
_jwtManager = new JWTManager(
|
|
46
|
+
{
|
|
47
|
+
secret,
|
|
48
|
+
accessTokenExpiry: process.env.JWT_EXPIRES_IN || "7d",
|
|
49
|
+
refreshTokenExpiry: process.env.JWT_REFRESH_TOKEN_EXPIRES_IN || "30d",
|
|
50
|
+
algorithm: "HS256"
|
|
51
|
+
},
|
|
52
|
+
// Winston logger for middleware
|
|
53
|
+
{
|
|
54
|
+
debug: (msg, meta) => logger.debug(`[Auth] ${msg}`, meta),
|
|
55
|
+
info: (msg, meta) => logger.info(`[Auth] ${msg}`, meta),
|
|
56
|
+
warn: (msg, meta) => logger.warn(`[Auth] ${msg}`, meta),
|
|
57
|
+
error: (msg, meta) => logger.error(`[Auth] ${msg}`, meta)
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
logger.info(
|
|
61
|
+
`[Auth Middleware] \u2705 Initialized - Access: ${process.env.JWT_EXPIRES_IN || "7d"}, Refresh: ${process.env.JWT_REFRESH_TOKEN_EXPIRES_IN || "30d"}`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return _jwtManager;
|
|
65
|
+
}
|
|
66
|
+
function initializeAuthMiddleware() {
|
|
67
|
+
const jwtManager = getJWTManager();
|
|
68
|
+
return jwtManager !== null;
|
|
69
|
+
}
|
|
70
|
+
var authMiddleware = async (context, next) => {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
try {
|
|
73
|
+
const jwtManager = getJWTManager();
|
|
74
|
+
if (!jwtManager) {
|
|
75
|
+
logger.error(
|
|
76
|
+
"[Auth Middleware] Cannot authenticate - JWT_SECRET not configured"
|
|
77
|
+
);
|
|
78
|
+
throw new AppError(
|
|
79
|
+
ERROR_CODES.UNAUTHORIZED.code,
|
|
80
|
+
"Authentication not configured. Contact administrator."
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
const authHeader = context.request.headers.get("authorization");
|
|
84
|
+
const token = jwtManager.extractTokenFromHeader(authHeader);
|
|
85
|
+
if (!token) {
|
|
86
|
+
throw new AppError(ERROR_CODES.UNAUTHORIZED.code);
|
|
87
|
+
}
|
|
88
|
+
const tokenChecker = getAccessTokenChecker();
|
|
89
|
+
if (tokenChecker) {
|
|
90
|
+
const isRevoked = await tokenChecker.isAccessTokenRevoked(token);
|
|
91
|
+
if (isRevoked) {
|
|
92
|
+
logger.debug(
|
|
93
|
+
"[Auth Middleware] Access token is revoked (blacklisted)"
|
|
94
|
+
);
|
|
95
|
+
throw new AppError(
|
|
96
|
+
ERROR_CODES.INVALID_TOKEN.code,
|
|
97
|
+
"Token has been revoked"
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const payload = await jwtManager.verifyAccessToken(token);
|
|
102
|
+
context.user = {
|
|
103
|
+
id: payload.userId,
|
|
104
|
+
email: (_a = payload.email) != null ? _a : "",
|
|
105
|
+
name: void 0,
|
|
106
|
+
// 필요시 DB에서 조회
|
|
107
|
+
role: payload.role === "ADMIN" ? "ADMIN" : "USER"
|
|
108
|
+
};
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (error instanceof AppError) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
if (error.code === "TOKEN_EXPIRED" || ((_b = error.message) == null ? void 0 : _b.includes("expired"))) {
|
|
114
|
+
throw new AppError(ERROR_CODES.TOKEN_EXPIRED.code, error.message);
|
|
115
|
+
}
|
|
116
|
+
throw new AppError(
|
|
117
|
+
ERROR_CODES.INVALID_TOKEN.code,
|
|
118
|
+
error.message || "Invalid token"
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return await next();
|
|
122
|
+
};
|
|
123
|
+
var optionalAuthMiddleware = async (context, next) => {
|
|
124
|
+
var _a;
|
|
125
|
+
try {
|
|
126
|
+
const jwtManager = getJWTManager();
|
|
127
|
+
if (jwtManager) {
|
|
128
|
+
const authHeader = context.request.headers.get("authorization");
|
|
129
|
+
const token = jwtManager.extractTokenFromHeader(authHeader);
|
|
130
|
+
if (token) {
|
|
131
|
+
const tokenChecker = getAccessTokenChecker();
|
|
132
|
+
let isRevoked = false;
|
|
133
|
+
if (tokenChecker) {
|
|
134
|
+
isRevoked = await tokenChecker.isAccessTokenRevoked(token);
|
|
135
|
+
}
|
|
136
|
+
if (!isRevoked) {
|
|
137
|
+
const payload = await jwtManager.verifyAccessToken(token);
|
|
138
|
+
context.user = {
|
|
139
|
+
id: payload.userId,
|
|
140
|
+
email: (_a = payload.email) != null ? _a : "",
|
|
141
|
+
name: void 0,
|
|
142
|
+
role: payload.role === "ADMIN" ? "ADMIN" : "USER"
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
} catch (e) {
|
|
148
|
+
}
|
|
149
|
+
return await next();
|
|
150
|
+
};
|
|
151
|
+
var adminMiddleware = async (context, next) => {
|
|
152
|
+
if (!context.user) {
|
|
153
|
+
throw new AppError(ERROR_CODES.UNAUTHORIZED.code);
|
|
154
|
+
}
|
|
155
|
+
if (context.user.role !== "ADMIN") {
|
|
156
|
+
throw new AppError(ERROR_CODES.FORBIDDEN.code);
|
|
157
|
+
}
|
|
158
|
+
return await next();
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export {
|
|
162
|
+
setAccessTokenBlacklistChecker,
|
|
163
|
+
initializeAuthMiddleware,
|
|
164
|
+
authMiddleware,
|
|
165
|
+
optionalAuthMiddleware,
|
|
166
|
+
adminMiddleware
|
|
167
|
+
};
|