@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
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# @withwiz/toolkit
|
|
2
|
+
|
|
3
|
+
Shared utility library for [withwiz](https://github.com/greeun) projects β a collection of production-ready modules for authentication, caching, error handling, middleware, geolocation, logging, and more.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Auth** β JWT, password hashing, OAuth helpers, Prisma adapter
|
|
8
|
+
- **Cache** β Redis-backed caching with factory, invalidation, and defaults
|
|
9
|
+
- **Constants** β Error codes, messages, pagination, security constants
|
|
10
|
+
- **Error** β Typed `AppError`, centralized error handler and display
|
|
11
|
+
- **Geolocation** β GeoIP lookup, batch processing, provider factory
|
|
12
|
+
- **Hooks** β `useDataTable`, `useDebounce`, `useExitIntent`, `useTimezone`
|
|
13
|
+
- **Logger** β Winston-based structured logger with daily rotation
|
|
14
|
+
- **Middleware** β Auth, rate-limiting, CORS, security middleware wrappers
|
|
15
|
+
- **Storage** β Cloudflare R2 (AWS S3-compatible) storage
|
|
16
|
+
- **System** β Health check endpoint
|
|
17
|
+
- **Types** β Shared TypeScript types (API, DB, env, GeoIP, user, i18n, QR)
|
|
18
|
+
- **Utils** β Sanitizer, validators, CSV export, URL normalizer, timezone, IP utils, and more
|
|
19
|
+
- **Validators** β Password strength validator
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @withwiz/toolkit
|
|
25
|
+
# or
|
|
26
|
+
pnpm add @withwiz/toolkit
|
|
27
|
+
# or
|
|
28
|
+
yarn add @withwiz/toolkit
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Peer dependencies
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install next react react-dom
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// Auth β JWT
|
|
41
|
+
import { signToken, verifyToken } from '@withwiz/toolkit/auth/core/jwt'
|
|
42
|
+
|
|
43
|
+
const token = await signToken({ userId: 'u_123' })
|
|
44
|
+
const payload = await verifyToken(token)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// Cache β Redis wrapper
|
|
49
|
+
import { withCache } from '@withwiz/toolkit/cache'
|
|
50
|
+
|
|
51
|
+
const data = await withCache('my-key', async () => fetchData(), 3600)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
// Error β typed error class
|
|
56
|
+
import { AppError } from '@withwiz/toolkit/error'
|
|
57
|
+
|
|
58
|
+
throw new AppError('NOT_FOUND', 'Resource not found', 404)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
// Logger
|
|
63
|
+
import { logInfo, logError } from '@withwiz/toolkit/logger/logger'
|
|
64
|
+
|
|
65
|
+
logInfo('Server started', { port: 3000 })
|
|
66
|
+
logError('Something went wrong', { error })
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
// Geolocation
|
|
71
|
+
import { getGeoLocation } from '@withwiz/toolkit/geolocation'
|
|
72
|
+
|
|
73
|
+
const geo = await getGeoLocation('8.8.8.8')
|
|
74
|
+
// { country: 'US', city: 'Mountain View', ... }
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
// Hooks (React)
|
|
79
|
+
import { useDebounce } from '@withwiz/toolkit/hooks/useDebounce'
|
|
80
|
+
|
|
81
|
+
const debouncedQuery = useDebounce(query, 300)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
// Utils
|
|
86
|
+
import { sanitizeInput } from '@withwiz/toolkit/utils/sanitizer'
|
|
87
|
+
import { formatNumber } from '@withwiz/toolkit/utils/format-number'
|
|
88
|
+
import { normalizeUrl } from '@withwiz/toolkit/utils/url-normalizer'
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Module reference
|
|
92
|
+
|
|
93
|
+
| Subpath | Description |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `/auth` | Full auth module (JWT + password + OAuth + Prisma adapter) |
|
|
96
|
+
| `/auth/core/jwt` | JWT sign / verify |
|
|
97
|
+
| `/auth/core/password` | bcrypt helpers |
|
|
98
|
+
| `/auth/core/oauth` | OAuth utilities |
|
|
99
|
+
| `/auth/adapters/prisma` | Prisma-based session adapter |
|
|
100
|
+
| `/cache` | Redis cache (get / set / delete / withCache) |
|
|
101
|
+
| `/cache/cache-factory` | Cache factory for multiple backends |
|
|
102
|
+
| `/cache/cache-invalidation` | Pattern-based cache invalidation |
|
|
103
|
+
| `/constants` | All shared constants |
|
|
104
|
+
| `/constants/error-codes` | Application error codes |
|
|
105
|
+
| `/constants/messages` | Shared user-facing messages |
|
|
106
|
+
| `/constants/pagination` | Default pagination settings |
|
|
107
|
+
| `/constants/security` | Security-related constants |
|
|
108
|
+
| `/error` | AppError, error handler, error display |
|
|
109
|
+
| `/geolocation` | GeoIP lookup & batch processor |
|
|
110
|
+
| `/hooks/useDataTable` | Table state management hook |
|
|
111
|
+
| `/hooks/useDebounce` | Debounce hook |
|
|
112
|
+
| `/hooks/useExitIntent` | Exit intent detection hook |
|
|
113
|
+
| `/hooks/useTimezone` | Timezone detection hook |
|
|
114
|
+
| `/logger/logger` | Structured Winston logger |
|
|
115
|
+
| `/middleware` | Next.js middleware helpers |
|
|
116
|
+
| `/middleware/auth` | Auth middleware |
|
|
117
|
+
| `/middleware/rate-limit` | Rate limiting middleware |
|
|
118
|
+
| `/middleware/cors` | CORS middleware |
|
|
119
|
+
| `/middleware/security` | Security headers middleware |
|
|
120
|
+
| `/storage` | Cloudflare R2 / S3 storage client |
|
|
121
|
+
| `/system/health-check` | Health check handler |
|
|
122
|
+
| `/types/api` | API response types |
|
|
123
|
+
| `/types/database` | Database entity types |
|
|
124
|
+
| `/types/env` | Environment variable types |
|
|
125
|
+
| `/types/user` | User types |
|
|
126
|
+
| `/types/geoip` | GeoIP types |
|
|
127
|
+
| `/utils` | All utility functions |
|
|
128
|
+
| `/utils/sanitizer` | Input sanitization |
|
|
129
|
+
| `/utils/url-normalizer` | URL normalization |
|
|
130
|
+
| `/utils/timezone` | Timezone formatting helpers |
|
|
131
|
+
| `/utils/csv-export` | CSV export helper |
|
|
132
|
+
| `/validators/password-validator` | Password strength validator |
|
|
133
|
+
|
|
134
|
+
## Requirements
|
|
135
|
+
|
|
136
|
+
- Node.js >= 18
|
|
137
|
+
- Next.js >= 14
|
|
138
|
+
- React >= 18
|
|
139
|
+
- TypeScript >= 5
|
|
140
|
+
|
|
141
|
+
## Development
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# Install dependencies
|
|
145
|
+
npm install
|
|
146
|
+
|
|
147
|
+
# Build
|
|
148
|
+
npm run build
|
|
149
|
+
|
|
150
|
+
# Run tests
|
|
151
|
+
npm test
|
|
152
|
+
|
|
153
|
+
# Watch mode
|
|
154
|
+
npm run test:watch
|
|
155
|
+
|
|
156
|
+
# Coverage
|
|
157
|
+
npm run test:coverage
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT Β© [withwiz](https://github.com/greeun)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @shared/auth/adapters/prisma
|
|
3
|
+
*
|
|
4
|
+
* Prisma ORM μ΄λν° (λ°μ΄ν°λ² μ΄μ€ μΆμν ꡬν)
|
|
5
|
+
* ν νλ‘μ νΈμμ μ¬μ¬μ© κ°λ₯
|
|
6
|
+
*
|
|
7
|
+
* Prisma 7λΆν° Generated Clientκ° νλ‘μ νΈλ³ κ²½λ‘μ μμ±λλ―λ‘,
|
|
8
|
+
* ν¨ν€μ§ λ
립μ±μ μν΄ λ νμ΄ν(Duck Typing) λ°©μμΌλ‘ PrismaClientλ₯Ό λ°μ΅λλ€.
|
|
9
|
+
*/
|
|
10
|
+
type PrismaClientLike = Record<string, any>;
|
|
11
|
+
import type { UserRepository, OAuthAccountRepository, EmailTokenRepository, BaseUser, CreateUserData, UpdateUserData, OAuthAccount, CreateOAuthAccountData, UpdateOAuthAccountData, EmailToken, TokenType, OAuthProvider } from '@withwiz/auth/types';
|
|
12
|
+
export declare class PrismaUserRepository implements UserRepository {
|
|
13
|
+
private prisma;
|
|
14
|
+
constructor(prisma: PrismaClientLike);
|
|
15
|
+
findById(id: string): Promise<BaseUser | null>;
|
|
16
|
+
findByEmail(email: string): Promise<BaseUser | null>;
|
|
17
|
+
create(data: CreateUserData): Promise<BaseUser>;
|
|
18
|
+
update(id: string, data: UpdateUserData): Promise<BaseUser>;
|
|
19
|
+
delete(id: string): Promise<void>;
|
|
20
|
+
updateLastLoginAt(id: string): Promise<void>;
|
|
21
|
+
verifyEmail(email: string): Promise<void>;
|
|
22
|
+
private mapToBaseUser;
|
|
23
|
+
}
|
|
24
|
+
export declare class PrismaOAuthAccountRepository implements OAuthAccountRepository {
|
|
25
|
+
private prisma;
|
|
26
|
+
constructor(prisma: PrismaClientLike);
|
|
27
|
+
findByProvider(provider: OAuthProvider, providerAccountId: string): Promise<OAuthAccount | null>;
|
|
28
|
+
findByUserId(userId: string): Promise<OAuthAccount[]>;
|
|
29
|
+
create(data: CreateOAuthAccountData): Promise<OAuthAccount>;
|
|
30
|
+
update(id: string, data: UpdateOAuthAccountData): Promise<OAuthAccount>;
|
|
31
|
+
delete(id: string): Promise<void>;
|
|
32
|
+
private mapToOAuthAccount;
|
|
33
|
+
}
|
|
34
|
+
export declare class PrismaEmailTokenRepository implements EmailTokenRepository {
|
|
35
|
+
private prisma;
|
|
36
|
+
constructor(prisma: PrismaClientLike);
|
|
37
|
+
create(email: string, token: string, type: TokenType, expiresAt: Date): Promise<EmailToken>;
|
|
38
|
+
findByEmailAndToken(email: string, token: string, type: TokenType): Promise<EmailToken | null>;
|
|
39
|
+
delete(email: string, token: string, type: TokenType): Promise<void>;
|
|
40
|
+
deleteExpired(): Promise<void>;
|
|
41
|
+
markAsUsed(id: string): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import "../../../chunk-ORMEWXMH.js";
|
|
2
|
+
|
|
3
|
+
// src/auth/adapters/prisma/index.ts
|
|
4
|
+
var PrismaUserRepository = class {
|
|
5
|
+
constructor(prisma) {
|
|
6
|
+
this.prisma = prisma;
|
|
7
|
+
}
|
|
8
|
+
async findById(id) {
|
|
9
|
+
const user = await this.prisma.user.findUnique({ where: { id } });
|
|
10
|
+
return user ? this.mapToBaseUser(user) : null;
|
|
11
|
+
}
|
|
12
|
+
async findByEmail(email) {
|
|
13
|
+
const user = await this.prisma.user.findUnique({ where: { email } });
|
|
14
|
+
return user ? this.mapToBaseUser(user) : null;
|
|
15
|
+
}
|
|
16
|
+
async create(data) {
|
|
17
|
+
const user = await this.prisma.user.create({
|
|
18
|
+
data: {
|
|
19
|
+
email: data.email,
|
|
20
|
+
password: data.password || null,
|
|
21
|
+
name: data.name || null,
|
|
22
|
+
role: data.role || "USER",
|
|
23
|
+
emailVerified: data.emailVerified || null,
|
|
24
|
+
image: data.image || null
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return this.mapToBaseUser(user);
|
|
28
|
+
}
|
|
29
|
+
async update(id, data) {
|
|
30
|
+
const user = await this.prisma.user.update({
|
|
31
|
+
where: { id },
|
|
32
|
+
data: {
|
|
33
|
+
email: data.email,
|
|
34
|
+
password: data.password,
|
|
35
|
+
name: data.name,
|
|
36
|
+
role: data.role,
|
|
37
|
+
emailVerified: data.emailVerified,
|
|
38
|
+
isActive: data.isActive,
|
|
39
|
+
image: data.image
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return this.mapToBaseUser(user);
|
|
43
|
+
}
|
|
44
|
+
async delete(id) {
|
|
45
|
+
await this.prisma.user.delete({ where: { id } });
|
|
46
|
+
}
|
|
47
|
+
async updateLastLoginAt(id) {
|
|
48
|
+
await this.prisma.user.update({
|
|
49
|
+
where: { id },
|
|
50
|
+
data: { lastLoginAt: /* @__PURE__ */ new Date() }
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async verifyEmail(email) {
|
|
54
|
+
await this.prisma.user.update({
|
|
55
|
+
where: { email },
|
|
56
|
+
data: { emailVerified: /* @__PURE__ */ new Date() }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
mapToBaseUser(user) {
|
|
60
|
+
return {
|
|
61
|
+
id: user.id,
|
|
62
|
+
email: user.email,
|
|
63
|
+
name: user.name,
|
|
64
|
+
role: user.role,
|
|
65
|
+
emailVerified: user.emailVerified,
|
|
66
|
+
isActive: user.isActive,
|
|
67
|
+
image: user.image,
|
|
68
|
+
createdAt: user.createdAt,
|
|
69
|
+
updatedAt: user.updatedAt
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var PrismaOAuthAccountRepository = class {
|
|
74
|
+
constructor(prisma) {
|
|
75
|
+
this.prisma = prisma;
|
|
76
|
+
}
|
|
77
|
+
async findByProvider(provider, providerAccountId) {
|
|
78
|
+
const account = await this.prisma.account.findUnique({
|
|
79
|
+
where: {
|
|
80
|
+
provider_providerAccountId: {
|
|
81
|
+
provider,
|
|
82
|
+
providerAccountId
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
include: {
|
|
86
|
+
token: true
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return account ? this.mapToOAuthAccount(account) : null;
|
|
90
|
+
}
|
|
91
|
+
async findByUserId(userId) {
|
|
92
|
+
const accounts = await this.prisma.account.findMany({
|
|
93
|
+
where: { userId },
|
|
94
|
+
include: {
|
|
95
|
+
token: true
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return accounts.map((a) => this.mapToOAuthAccount(a));
|
|
99
|
+
}
|
|
100
|
+
async create(data) {
|
|
101
|
+
const account = await this.prisma.account.create({
|
|
102
|
+
data: {
|
|
103
|
+
userId: data.userId,
|
|
104
|
+
type: "oauth",
|
|
105
|
+
// Account λͺ¨λΈμ type νλ
|
|
106
|
+
provider: data.provider,
|
|
107
|
+
providerAccountId: data.providerAccountId,
|
|
108
|
+
token: data.accessToken || data.refreshToken ? {
|
|
109
|
+
create: {
|
|
110
|
+
accessToken: data.accessToken || null,
|
|
111
|
+
refreshToken: data.refreshToken || null,
|
|
112
|
+
expiresAt: data.expiresAt ? Math.floor(data.expiresAt.getTime() / 1e3) : null,
|
|
113
|
+
tokenType: data.tokenType || null,
|
|
114
|
+
scope: data.scope || null
|
|
115
|
+
}
|
|
116
|
+
} : void 0
|
|
117
|
+
},
|
|
118
|
+
include: {
|
|
119
|
+
token: true
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return this.mapToOAuthAccount(account);
|
|
123
|
+
}
|
|
124
|
+
async update(id, data) {
|
|
125
|
+
const account = await this.prisma.account.update({
|
|
126
|
+
where: { id },
|
|
127
|
+
data: {
|
|
128
|
+
token: {
|
|
129
|
+
upsert: {
|
|
130
|
+
create: {
|
|
131
|
+
accessToken: data.accessToken || null,
|
|
132
|
+
refreshToken: data.refreshToken || null,
|
|
133
|
+
expiresAt: data.expiresAt ? Math.floor(data.expiresAt.getTime() / 1e3) : null,
|
|
134
|
+
tokenType: data.tokenType || null,
|
|
135
|
+
scope: data.scope || null
|
|
136
|
+
},
|
|
137
|
+
update: {
|
|
138
|
+
accessToken: data.accessToken || null,
|
|
139
|
+
refreshToken: data.refreshToken || null,
|
|
140
|
+
expiresAt: data.expiresAt ? Math.floor(data.expiresAt.getTime() / 1e3) : null,
|
|
141
|
+
tokenType: data.tokenType || null,
|
|
142
|
+
scope: data.scope || null
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
include: {
|
|
148
|
+
token: true
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return this.mapToOAuthAccount(account);
|
|
152
|
+
}
|
|
153
|
+
async delete(id) {
|
|
154
|
+
await this.prisma.account.delete({ where: { id } });
|
|
155
|
+
}
|
|
156
|
+
mapToOAuthAccount(account) {
|
|
157
|
+
var _a, _b, _c, _d, _e;
|
|
158
|
+
return {
|
|
159
|
+
id: account.id,
|
|
160
|
+
userId: account.userId,
|
|
161
|
+
provider: account.provider,
|
|
162
|
+
providerAccountId: account.providerAccountId,
|
|
163
|
+
accessToken: ((_a = account.token) == null ? void 0 : _a.accessToken) || null,
|
|
164
|
+
refreshToken: ((_b = account.token) == null ? void 0 : _b.refreshToken) || null,
|
|
165
|
+
expiresAt: ((_c = account.token) == null ? void 0 : _c.expiresAt) ? new Date(account.token.expiresAt * 1e3) : null,
|
|
166
|
+
tokenType: ((_d = account.token) == null ? void 0 : _d.tokenType) || null,
|
|
167
|
+
scope: ((_e = account.token) == null ? void 0 : _e.scope) || null,
|
|
168
|
+
createdAt: account.createdAt,
|
|
169
|
+
updatedAt: account.updatedAt || account.createdAt
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var PrismaEmailTokenRepository = class {
|
|
174
|
+
constructor(prisma) {
|
|
175
|
+
this.prisma = prisma;
|
|
176
|
+
}
|
|
177
|
+
async create(email, token, type, expiresAt) {
|
|
178
|
+
let result;
|
|
179
|
+
switch (type) {
|
|
180
|
+
case "EMAIL_VERIFICATION":
|
|
181
|
+
result = await this.prisma.emailVerificationToken.create({
|
|
182
|
+
data: { email, token, expires: expiresAt }
|
|
183
|
+
});
|
|
184
|
+
break;
|
|
185
|
+
case "PASSWORD_RESET":
|
|
186
|
+
result = await this.prisma.passwordResetToken.create({
|
|
187
|
+
data: { email, token, expires: expiresAt }
|
|
188
|
+
});
|
|
189
|
+
break;
|
|
190
|
+
case "MAGIC_LINK":
|
|
191
|
+
result = await this.prisma.magicLinkToken.create({
|
|
192
|
+
data: { email, token, expires: expiresAt, used: false }
|
|
193
|
+
});
|
|
194
|
+
break;
|
|
195
|
+
default:
|
|
196
|
+
throw new Error(`Unsupported token type: ${type}`);
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
id: result.id,
|
|
200
|
+
email: result.email,
|
|
201
|
+
token: result.token,
|
|
202
|
+
type,
|
|
203
|
+
expires: result.expires,
|
|
204
|
+
used: result.used,
|
|
205
|
+
createdAt: result.createdAt
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
async findByEmailAndToken(email, token, type) {
|
|
209
|
+
let result;
|
|
210
|
+
switch (type) {
|
|
211
|
+
case "EMAIL_VERIFICATION":
|
|
212
|
+
result = await this.prisma.emailVerificationToken.findFirst({
|
|
213
|
+
where: { email, token }
|
|
214
|
+
});
|
|
215
|
+
break;
|
|
216
|
+
case "PASSWORD_RESET":
|
|
217
|
+
result = await this.prisma.passwordResetToken.findFirst({
|
|
218
|
+
where: { email, token }
|
|
219
|
+
});
|
|
220
|
+
break;
|
|
221
|
+
case "MAGIC_LINK":
|
|
222
|
+
result = await this.prisma.magicLinkToken.findFirst({
|
|
223
|
+
where: { email, token }
|
|
224
|
+
});
|
|
225
|
+
break;
|
|
226
|
+
default:
|
|
227
|
+
throw new Error(`Unsupported token type: ${type}`);
|
|
228
|
+
}
|
|
229
|
+
if (!result) return null;
|
|
230
|
+
return {
|
|
231
|
+
id: result.id,
|
|
232
|
+
email: result.email,
|
|
233
|
+
token: result.token,
|
|
234
|
+
type,
|
|
235
|
+
expires: result.expires,
|
|
236
|
+
used: result.used,
|
|
237
|
+
createdAt: result.createdAt
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
async delete(email, token, type) {
|
|
241
|
+
switch (type) {
|
|
242
|
+
case "EMAIL_VERIFICATION":
|
|
243
|
+
await this.prisma.emailVerificationToken.deleteMany({
|
|
244
|
+
where: { email, token }
|
|
245
|
+
});
|
|
246
|
+
break;
|
|
247
|
+
case "PASSWORD_RESET":
|
|
248
|
+
await this.prisma.passwordResetToken.deleteMany({
|
|
249
|
+
where: { email, token }
|
|
250
|
+
});
|
|
251
|
+
break;
|
|
252
|
+
case "MAGIC_LINK":
|
|
253
|
+
await this.prisma.magicLinkToken.deleteMany({
|
|
254
|
+
where: { email, token }
|
|
255
|
+
});
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async deleteExpired() {
|
|
260
|
+
const now = /* @__PURE__ */ new Date();
|
|
261
|
+
await Promise.all([
|
|
262
|
+
this.prisma.emailVerificationToken.deleteMany({
|
|
263
|
+
where: { expires: { lt: now } }
|
|
264
|
+
}),
|
|
265
|
+
this.prisma.passwordResetToken.deleteMany({
|
|
266
|
+
where: { expires: { lt: now } }
|
|
267
|
+
}),
|
|
268
|
+
this.prisma.magicLinkToken.deleteMany({
|
|
269
|
+
where: { expires: { lt: now } }
|
|
270
|
+
})
|
|
271
|
+
]);
|
|
272
|
+
}
|
|
273
|
+
async markAsUsed(id) {
|
|
274
|
+
await this.prisma.magicLinkToken.update({
|
|
275
|
+
where: { id },
|
|
276
|
+
data: { used: true }
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
export {
|
|
281
|
+
PrismaEmailTokenRepository,
|
|
282
|
+
PrismaOAuthAccountRepository,
|
|
283
|
+
PrismaUserRepository
|
|
284
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Auth - Email Token Generator
|
|
3
|
+
*
|
|
4
|
+
* μ΄λ©μΌ μΈμ¦μ© ν ν° μμ± μ νΈλ¦¬ν° (νλ μμν¬ λ
립μ )
|
|
5
|
+
* crypto λͺ¨λ κΈ°λ°
|
|
6
|
+
*/
|
|
7
|
+
export declare class TokenGenerator {
|
|
8
|
+
/**
|
|
9
|
+
* μμ ν λλ€ ν ν° μμ±
|
|
10
|
+
*
|
|
11
|
+
* @param bytes - λ°μ΄νΈ μ (κΈ°λ³Έ: 32)
|
|
12
|
+
* @returns 16μ§μ λ¬Έμμ΄ ν ν°
|
|
13
|
+
*/
|
|
14
|
+
static generate(bytes?: number): string;
|
|
15
|
+
/**
|
|
16
|
+
* URL-safe ν ν° μμ± (Base64URL)
|
|
17
|
+
*
|
|
18
|
+
* @param bytes - λ°μ΄νΈ μ (κΈ°λ³Έ: 32)
|
|
19
|
+
* @returns URL-safe ν ν°
|
|
20
|
+
*/
|
|
21
|
+
static generateUrlSafe(bytes?: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* μ«μ PIN μ½λ μμ±
|
|
24
|
+
*
|
|
25
|
+
* @param length - PIN κΈΈμ΄ (κΈ°λ³Έ: 6)
|
|
26
|
+
* @returns μ«μ PIN μ½λ
|
|
27
|
+
*/
|
|
28
|
+
static generatePIN(length?: number): string;
|
|
29
|
+
/**
|
|
30
|
+
* λ§λ£ μκ° κ³μ°
|
|
31
|
+
*
|
|
32
|
+
* @param milliseconds - λ§λ£κΉμ§μ λ°λ¦¬μ΄
|
|
33
|
+
* @returns λ§λ£ Date κ°μ²΄
|
|
34
|
+
*/
|
|
35
|
+
static calculateExpiry(milliseconds: number): Date;
|
|
36
|
+
/**
|
|
37
|
+
* ν ν°μ΄ λ§λ£λμλμ§ νμΈ
|
|
38
|
+
*
|
|
39
|
+
* @param expiryDate - λ§λ£ Date
|
|
40
|
+
* @returns λ§λ£ μ¬λΆ
|
|
41
|
+
*/
|
|
42
|
+
static isExpired(expiryDate: Date): boolean;
|
|
43
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Auth - JWT Client Module
|
|
3
|
+
*
|
|
4
|
+
* ν΄λΌμ΄μΈνΈ μΈ‘ JWT μ νΈλ¦¬ν° (λΈλΌμ°μ μ μ©, μμ ν λ
립μ )
|
|
5
|
+
* νλ μμν¬ λ
립μ - React, Vue, Angular λ± μ΄λμλ μ¬μ© κ°λ₯
|
|
6
|
+
*/
|
|
7
|
+
interface TokenStorage {
|
|
8
|
+
accessToken: string | null;
|
|
9
|
+
refreshToken: string | null;
|
|
10
|
+
expiresAt: number | null;
|
|
11
|
+
}
|
|
12
|
+
interface UserInfo {
|
|
13
|
+
userId: string;
|
|
14
|
+
email: string;
|
|
15
|
+
role: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class JWTClientManager {
|
|
18
|
+
private storageKey;
|
|
19
|
+
constructor(storageKey?: string);
|
|
20
|
+
/**
|
|
21
|
+
* λ‘컬 μ€ν 리μ§μμ ν ν° κ°μ Έμ€κΈ°
|
|
22
|
+
*/
|
|
23
|
+
getStoredTokens(): TokenStorage | null;
|
|
24
|
+
/**
|
|
25
|
+
* ν ν°μ λ‘컬 μ€ν 리μ§μ μ μ₯
|
|
26
|
+
*/
|
|
27
|
+
storeTokens(accessToken: string, refreshToken: string, expiresIn?: number): void;
|
|
28
|
+
/**
|
|
29
|
+
* λ‘컬 μ€ν 리μ§μμ ν ν° μ κ±°
|
|
30
|
+
*/
|
|
31
|
+
clearStoredTokens(): void;
|
|
32
|
+
/**
|
|
33
|
+
* JWT ν ν°μμ νμ΄λ‘λ λμ½λ© (κ²μ¦ μμ)
|
|
34
|
+
*/
|
|
35
|
+
decodeJWTPayload(token: string): any | null;
|
|
36
|
+
/**
|
|
37
|
+
* ν ν° λ§λ£ μ¬λΆ νμΈ
|
|
38
|
+
*/
|
|
39
|
+
isTokenExpired(token: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* ν ν° λ¨μ μκ° (μ΄)
|
|
42
|
+
*/
|
|
43
|
+
getTokenRemainingTime(token: string): number;
|
|
44
|
+
/**
|
|
45
|
+
* ν ν°μμ μ¬μ©μ μ 보 μΆμΆ
|
|
46
|
+
*/
|
|
47
|
+
extractUserFromToken(token: string): UserInfo | null;
|
|
48
|
+
/**
|
|
49
|
+
* ν ν°μμ μ¬μ©μ role μΆμΆ
|
|
50
|
+
*/
|
|
51
|
+
getUserRole(token: string | null): string;
|
|
52
|
+
/**
|
|
53
|
+
* Authorization ν€λ μμ±
|
|
54
|
+
*/
|
|
55
|
+
createAuthHeader(token: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* API μμ²μ© ν€λ μμ±
|
|
58
|
+
*/
|
|
59
|
+
createApiHeaders(token: string): Record<string, string>;
|
|
60
|
+
/**
|
|
61
|
+
* ν ν°μ΄ κ³§ λ§λ£λλμ§ νμΈ (5λΆ μ΄λ΄)
|
|
62
|
+
*/
|
|
63
|
+
isTokenExpiringSoon(token: string, thresholdSeconds?: number): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* ν ν° λ§λ£ μκ° ν¬λ§·ν
|
|
66
|
+
*/
|
|
67
|
+
getTokenExpirationString(token: string): string | null;
|
|
68
|
+
/**
|
|
69
|
+
* ν ν° λ°κΈ μκ° ν¬λ§·ν
|
|
70
|
+
*/
|
|
71
|
+
getTokenIssuedAtString(token: string): string | null;
|
|
72
|
+
}
|
|
73
|
+
export declare const getStoredTokens: () => TokenStorage | null;
|
|
74
|
+
export declare const storeTokens: (accessToken: string, refreshToken: string, expiresIn?: number) => void;
|
|
75
|
+
export declare const clearStoredTokens: () => void;
|
|
76
|
+
export declare const clearTokens: () => void;
|
|
77
|
+
export declare const decodeJWTPayload: (token: string) => any;
|
|
78
|
+
export declare const isTokenExpired: (token: string) => boolean;
|
|
79
|
+
export declare const getTokenRemainingTime: (token: string) => number;
|
|
80
|
+
export declare const extractUserFromToken: (token: string) => UserInfo | null;
|
|
81
|
+
export declare const getUserRole: (token: string | null) => string;
|
|
82
|
+
export declare const createAuthHeader: (token: string) => string;
|
|
83
|
+
export declare const createApiHeaders: (token: string) => Record<string, string>;
|
|
84
|
+
export declare const isTokenExpiringSoon: (token: string) => boolean;
|
|
85
|
+
export declare const getTokenExpirationString: (token: string) => string | null;
|
|
86
|
+
export declare const getTokenIssuedAtString: (token: string) => string | null;
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
JWTClientManager,
|
|
4
|
+
clearStoredTokens,
|
|
5
|
+
clearTokens,
|
|
6
|
+
createApiHeaders,
|
|
7
|
+
createAuthHeader,
|
|
8
|
+
decodeJWTPayload,
|
|
9
|
+
extractUserFromToken,
|
|
10
|
+
getStoredTokens,
|
|
11
|
+
getTokenExpirationString,
|
|
12
|
+
getTokenIssuedAtString,
|
|
13
|
+
getTokenRemainingTime,
|
|
14
|
+
getUserRole,
|
|
15
|
+
isTokenExpired,
|
|
16
|
+
isTokenExpiringSoon,
|
|
17
|
+
storeTokens
|
|
18
|
+
} from "../../../chunk-XRRPEBKB.js";
|
|
19
|
+
import "../../../chunk-ORMEWXMH.js";
|
|
20
|
+
export {
|
|
21
|
+
JWTClientManager,
|
|
22
|
+
clearStoredTokens,
|
|
23
|
+
clearTokens,
|
|
24
|
+
createApiHeaders,
|
|
25
|
+
createAuthHeader,
|
|
26
|
+
decodeJWTPayload,
|
|
27
|
+
extractUserFromToken,
|
|
28
|
+
getStoredTokens,
|
|
29
|
+
getTokenExpirationString,
|
|
30
|
+
getTokenIssuedAtString,
|
|
31
|
+
getTokenRemainingTime,
|
|
32
|
+
getUserRole,
|
|
33
|
+
isTokenExpired,
|
|
34
|
+
isTokenExpiringSoon,
|
|
35
|
+
storeTokens
|
|
36
|
+
};
|