@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,242 @@
|
|
|
1
|
+
import {
|
|
2
|
+
convertToBytes,
|
|
3
|
+
formatBytesPerSec,
|
|
4
|
+
runCommand,
|
|
5
|
+
runMacCommand
|
|
6
|
+
} from "./chunk-KWTBD4CM.js";
|
|
7
|
+
import {
|
|
8
|
+
logger
|
|
9
|
+
} from "./chunk-EZR55KV2.js";
|
|
10
|
+
|
|
11
|
+
// src/system/network.ts
|
|
12
|
+
async function getNetworkInfo() {
|
|
13
|
+
try {
|
|
14
|
+
const platform = process.platform;
|
|
15
|
+
let connectionsOutput;
|
|
16
|
+
let processConnectionsCount = 0;
|
|
17
|
+
if (platform === "darwin") {
|
|
18
|
+
connectionsOutput = await runMacCommand("netstat -an | grep ESTABLISHED | wc -l");
|
|
19
|
+
} else {
|
|
20
|
+
connectionsOutput = await runCommand("netstat -an | grep ESTABLISHED | wc -l");
|
|
21
|
+
}
|
|
22
|
+
const pid = process.pid;
|
|
23
|
+
try {
|
|
24
|
+
if (platform === "darwin") {
|
|
25
|
+
const processOutput = await runMacCommand(`lsof -i -a -p ${pid} 2>/dev/null | grep ESTABLISHED | wc -l`);
|
|
26
|
+
processConnectionsCount = parseInt(processOutput.trim()) || 0;
|
|
27
|
+
} else {
|
|
28
|
+
try {
|
|
29
|
+
const processOutput = await runCommand(`ls -la /proc/${pid}/fd 2>/dev/null | grep socket | wc -l`);
|
|
30
|
+
processConnectionsCount = parseInt(processOutput.trim()) || 0;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
const ssOutput = await runCommand(`ss -tnp 2>/dev/null | grep "pid=${pid}" | wc -l`);
|
|
33
|
+
processConnectionsCount = parseInt(ssOutput.trim()) || 0;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} catch (error) {
|
|
37
|
+
logger.debug("Process connections count failed:", error);
|
|
38
|
+
processConnectionsCount = 0;
|
|
39
|
+
}
|
|
40
|
+
const getProcessNetworkStats = async () => {
|
|
41
|
+
try {
|
|
42
|
+
if (platform === "darwin") {
|
|
43
|
+
try {
|
|
44
|
+
const nettopOutput = await runMacCommand(`nettop -J bytes_in,bytes_out -l 1 -p ${pid} 2>/dev/null`);
|
|
45
|
+
let totalRx = 0, totalTx = 0;
|
|
46
|
+
const lines = nettopOutput.split("\n").filter((line) => line.trim());
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
const bytesMatch = line.match(/(\d+(?:\.\d+)?)\s+(B|KiB|MiB|GiB)\s+(\d+(?:\.\d+)?)\s+(B|KiB|MiB|GiB)/);
|
|
49
|
+
if (bytesMatch) {
|
|
50
|
+
const rxValue = parseFloat(bytesMatch[1]);
|
|
51
|
+
const rxUnit = bytesMatch[2];
|
|
52
|
+
const txValue = parseFloat(bytesMatch[3]);
|
|
53
|
+
const txUnit = bytesMatch[4];
|
|
54
|
+
totalRx += convertToBytes(rxValue, rxUnit);
|
|
55
|
+
totalTx += convertToBytes(txValue, txUnit);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { rx: totalRx, tx: totalTx };
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return { rx: 0, tx: 0 };
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
try {
|
|
64
|
+
const ioOutput = await runCommand(`cat /proc/${pid}/io 2>/dev/null`);
|
|
65
|
+
let rx = 0, tx = 0;
|
|
66
|
+
const readMatch = ioOutput.match(/read_bytes:\s+(\d+)/);
|
|
67
|
+
const writeMatch = ioOutput.match(/write_bytes:\s+(\d+)/);
|
|
68
|
+
if (readMatch) rx = parseInt(readMatch[1]) || 0;
|
|
69
|
+
if (writeMatch) tx = parseInt(writeMatch[1]) || 0;
|
|
70
|
+
return { rx, tx };
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return { rx: 0, tx: 0 };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
return { rx: 0, tx: 0 };
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const getNetworkStats = async () => {
|
|
80
|
+
if (platform === "darwin") {
|
|
81
|
+
try {
|
|
82
|
+
const nettopOutput = await runMacCommand("nettop -J bytes_in,bytes_out -l 1 -s 1");
|
|
83
|
+
let totalRx = 0, totalTx = 0;
|
|
84
|
+
const lines = nettopOutput.split("\n").filter((line) => line.trim());
|
|
85
|
+
for (const line of lines) {
|
|
86
|
+
const bytesMatch = line.match(/(\d+(?:\.\d+)?)\s+(B|KiB|MiB|GiB)\s+(\d+(?:\.\d+)?)\s+(B|KiB|MiB|GiB)/);
|
|
87
|
+
if (bytesMatch) {
|
|
88
|
+
const rxValue = parseFloat(bytesMatch[1]);
|
|
89
|
+
const rxUnit = bytesMatch[2];
|
|
90
|
+
const txValue = parseFloat(bytesMatch[3]);
|
|
91
|
+
const txUnit = bytesMatch[4];
|
|
92
|
+
const rxBytes = convertToBytes(rxValue, rxUnit);
|
|
93
|
+
const txBytes = convertToBytes(txValue, txUnit);
|
|
94
|
+
totalRx += rxBytes;
|
|
95
|
+
totalTx += txBytes;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { rx: totalRx, tx: totalTx };
|
|
99
|
+
} catch (error) {
|
|
100
|
+
logger.debug("nettop failed, falling back to ifconfig:", error);
|
|
101
|
+
try {
|
|
102
|
+
const ifaceList = await runMacCommand("ifconfig -l");
|
|
103
|
+
const ifaces = ifaceList.split(/\s+/).filter(Boolean);
|
|
104
|
+
let maxRx = 0, maxTx = 0;
|
|
105
|
+
let found = false;
|
|
106
|
+
for (const iface of ifaces) {
|
|
107
|
+
try {
|
|
108
|
+
const ifconfigOutput = await runMacCommand(`ifconfig ${iface}`);
|
|
109
|
+
let rx = 0, tx = 0;
|
|
110
|
+
const rxMatch1 = ifconfigOutput.match(/input bytes (\d+)/);
|
|
111
|
+
const txMatch1 = ifconfigOutput.match(/output bytes (\d+)/);
|
|
112
|
+
const bytesMatch = ifconfigOutput.match(/bytes:\s*(\d+)\s+(\d+)/);
|
|
113
|
+
const rxMatch3 = ifconfigOutput.match(/RX bytes:(\d+)/);
|
|
114
|
+
const txMatch3 = ifconfigOutput.match(/TX bytes:(\d+)/);
|
|
115
|
+
if (rxMatch1 && txMatch1) {
|
|
116
|
+
rx = parseInt(rxMatch1[1]);
|
|
117
|
+
tx = parseInt(txMatch1[1]);
|
|
118
|
+
} else if (bytesMatch) {
|
|
119
|
+
rx = parseInt(bytesMatch[1]);
|
|
120
|
+
tx = parseInt(bytesMatch[2]);
|
|
121
|
+
} else if (rxMatch3 && txMatch3) {
|
|
122
|
+
rx = parseInt(rxMatch3[1]);
|
|
123
|
+
tx = parseInt(txMatch3[1]);
|
|
124
|
+
}
|
|
125
|
+
if (rx > 0 || tx > 0) {
|
|
126
|
+
if (rx + tx > maxRx + maxTx) {
|
|
127
|
+
maxRx = rx;
|
|
128
|
+
maxTx = tx;
|
|
129
|
+
found = true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} catch (e) {
|
|
133
|
+
logger.debug(`Error reading interface ${iface}:`, e);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (found) {
|
|
137
|
+
return { rx: maxRx, tx: maxTx };
|
|
138
|
+
} else {
|
|
139
|
+
return { rx: 0, tx: 0 };
|
|
140
|
+
}
|
|
141
|
+
} catch (ifconfigError) {
|
|
142
|
+
logger.debug("ifconfig fallback failed:", ifconfigError);
|
|
143
|
+
return { rx: 0, tx: 0 };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
try {
|
|
148
|
+
const netstatOutput = await runCommand("cat /proc/net/dev | grep -E '^(eth|wlan|lo|en|wl|ens|eno|enp)' | tail -n +2");
|
|
149
|
+
let totalRx = 0;
|
|
150
|
+
let totalTx = 0;
|
|
151
|
+
const lines = netstatOutput.split("\n").filter((line) => line.trim());
|
|
152
|
+
for (const line of lines) {
|
|
153
|
+
const parts = line.split(/\s+/).filter((part) => part.trim());
|
|
154
|
+
if (parts.length >= 17) {
|
|
155
|
+
const rx = parseInt(parts[1]) || 0;
|
|
156
|
+
const tx = parseInt(parts[9]) || 0;
|
|
157
|
+
totalRx += rx;
|
|
158
|
+
totalTx += tx;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (totalRx > 0 || totalTx > 0) {
|
|
162
|
+
return { rx: totalRx, tx: totalTx };
|
|
163
|
+
} else {
|
|
164
|
+
throw new Error("/proc/net/dev\uC5D0\uC11C \uC720\uD6A8\uD55C \uB370\uC774\uD130\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
165
|
+
}
|
|
166
|
+
} catch (error) {
|
|
167
|
+
logger.debug("/proc/net/dev failed, trying netstat:", error);
|
|
168
|
+
try {
|
|
169
|
+
const netstatOutput = await runCommand("netstat -i | grep -E '^(eth|wlan|lo|en|wl|ens|eno|enp)' | tail -n +2");
|
|
170
|
+
let totalRx = 0;
|
|
171
|
+
let totalTx = 0;
|
|
172
|
+
const lines = netstatOutput.split("\n").filter((line) => line.trim());
|
|
173
|
+
for (const line of lines) {
|
|
174
|
+
const parts = line.split(/\s+/).filter((part) => part.trim());
|
|
175
|
+
if (parts.length >= 4) {
|
|
176
|
+
const rx = parseInt(parts[3]) || 0;
|
|
177
|
+
const tx = parseInt(parts[7]) || 0;
|
|
178
|
+
totalRx += rx * 1500;
|
|
179
|
+
totalTx += tx * 1500;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (totalRx > 0 || totalTx > 0) {
|
|
183
|
+
return { rx: totalRx, tx: totalTx };
|
|
184
|
+
} else {
|
|
185
|
+
throw new Error("netstat\uC5D0\uC11C \uC720\uD6A8\uD55C \uB370\uC774\uD130\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
186
|
+
}
|
|
187
|
+
} catch (netstatError) {
|
|
188
|
+
logger.debug("netstat fallback failed:", netstatError);
|
|
189
|
+
try {
|
|
190
|
+
const ssOutput = await runCommand("ss -i | grep -c ESTAB");
|
|
191
|
+
const connections2 = parseInt(ssOutput.trim()) || 0;
|
|
192
|
+
const estimatedBytes = connections2 * 1024;
|
|
193
|
+
return { rx: estimatedBytes, tx: estimatedBytes };
|
|
194
|
+
} catch (ssError) {
|
|
195
|
+
logger.debug("ss fallback failed:", ssError);
|
|
196
|
+
try {
|
|
197
|
+
const sockstatOutput = await runCommand("cat /proc/net/sockstat | grep TCP");
|
|
198
|
+
const match = sockstatOutput.match(/TCP:\s+(\d+)/);
|
|
199
|
+
if (match) {
|
|
200
|
+
const tcpSockets = parseInt(match[1]) || 0;
|
|
201
|
+
const estimatedBytes = tcpSockets * 512;
|
|
202
|
+
return { rx: estimatedBytes, tx: estimatedBytes };
|
|
203
|
+
} else {
|
|
204
|
+
throw new Error("/proc/net/sockstat\uC5D0\uC11C TCP \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
|
|
205
|
+
}
|
|
206
|
+
} catch (sockstatError) {
|
|
207
|
+
logger.debug("/proc/net/sockstat fallback failed:", sockstatError);
|
|
208
|
+
return { rx: 0, tx: 0 };
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const systemStats1 = await getNetworkStats();
|
|
216
|
+
const processStats1 = await getProcessNetworkStats();
|
|
217
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
218
|
+
const systemStats2 = await getNetworkStats();
|
|
219
|
+
const processStats2 = await getProcessNetworkStats();
|
|
220
|
+
const systemRxRate = Math.max(0, systemStats2.rx - systemStats1.rx);
|
|
221
|
+
const systemTxRate = Math.max(0, systemStats2.tx - systemStats1.tx);
|
|
222
|
+
const processRxRate = Math.max(0, processStats2.rx - processStats1.rx);
|
|
223
|
+
const processTxRate = Math.max(0, processStats2.tx - processStats1.tx);
|
|
224
|
+
const connections = parseInt(connectionsOutput) || 0;
|
|
225
|
+
const result = {
|
|
226
|
+
rxRate: formatBytesPerSec(systemRxRate),
|
|
227
|
+
txRate: formatBytesPerSec(systemTxRate),
|
|
228
|
+
processRxRate: formatBytesPerSec(processRxRate),
|
|
229
|
+
processTxRate: formatBytesPerSec(processTxRate),
|
|
230
|
+
connections,
|
|
231
|
+
processConnections: processConnectionsCount
|
|
232
|
+
};
|
|
233
|
+
return result;
|
|
234
|
+
} catch (error) {
|
|
235
|
+
logger.error("Network info fetch error:", error);
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export {
|
|
241
|
+
getNetworkInfo
|
|
242
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/error/logging/types.ts
|
|
2
|
+
var ELogLevel = /* @__PURE__ */ ((ELogLevel2) => {
|
|
3
|
+
ELogLevel2["DEBUG"] = "debug";
|
|
4
|
+
ELogLevel2["INFO"] = "info";
|
|
5
|
+
ELogLevel2["WARN"] = "warn";
|
|
6
|
+
ELogLevel2["ERROR"] = "error";
|
|
7
|
+
ELogLevel2["CRITICAL"] = "critical";
|
|
8
|
+
return ELogLevel2;
|
|
9
|
+
})(ELogLevel || {});
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
ELogLevel
|
|
13
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/auth/types/index.ts
|
|
2
|
+
var UserRole = /* @__PURE__ */ ((UserRole2) => {
|
|
3
|
+
UserRole2["USER"] = "USER";
|
|
4
|
+
UserRole2["ADMIN"] = "ADMIN";
|
|
5
|
+
return UserRole2;
|
|
6
|
+
})(UserRole || {});
|
|
7
|
+
var OAuthProvider = /* @__PURE__ */ ((OAuthProvider2) => {
|
|
8
|
+
OAuthProvider2["GOOGLE"] = "google";
|
|
9
|
+
OAuthProvider2["GITHUB"] = "github";
|
|
10
|
+
return OAuthProvider2;
|
|
11
|
+
})(OAuthProvider || {});
|
|
12
|
+
var PasswordStrength = /* @__PURE__ */ ((PasswordStrength2) => {
|
|
13
|
+
PasswordStrength2["VERY_WEAK"] = "VERY_WEAK";
|
|
14
|
+
PasswordStrength2["WEAK"] = "WEAK";
|
|
15
|
+
PasswordStrength2["MEDIUM"] = "MEDIUM";
|
|
16
|
+
PasswordStrength2["STRONG"] = "STRONG";
|
|
17
|
+
PasswordStrength2["VERY_STRONG"] = "VERY_STRONG";
|
|
18
|
+
return PasswordStrength2;
|
|
19
|
+
})(PasswordStrength || {});
|
|
20
|
+
var TokenType = /* @__PURE__ */ ((TokenType2) => {
|
|
21
|
+
TokenType2["EMAIL_VERIFICATION"] = "EMAIL_VERIFICATION";
|
|
22
|
+
TokenType2["PASSWORD_RESET"] = "PASSWORD_RESET";
|
|
23
|
+
TokenType2["MAGIC_LINK"] = "MAGIC_LINK";
|
|
24
|
+
return TokenType2;
|
|
25
|
+
})(TokenType || {});
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
UserRole,
|
|
29
|
+
OAuthProvider,
|
|
30
|
+
PasswordStrength,
|
|
31
|
+
TokenType
|
|
32
|
+
};
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCacheFallbackConfig,
|
|
3
|
+
getConfig,
|
|
4
|
+
getEnv,
|
|
5
|
+
isCacheEnabled,
|
|
6
|
+
validateRedisEnvironment
|
|
7
|
+
} from "./chunk-I47QEDTX.js";
|
|
8
|
+
import {
|
|
9
|
+
logger
|
|
10
|
+
} from "./chunk-EZR55KV2.js";
|
|
11
|
+
|
|
12
|
+
// src/cache/cache-redis.ts
|
|
13
|
+
import { Redis } from "@upstash/redis";
|
|
14
|
+
function getGlobalRedisState() {
|
|
15
|
+
if (!globalThis.__globalRedisState) {
|
|
16
|
+
globalThis.__globalRedisState = {
|
|
17
|
+
isDisabled: false,
|
|
18
|
+
errorCount: 0,
|
|
19
|
+
lastErrorTime: null,
|
|
20
|
+
lastErrorMessage: null,
|
|
21
|
+
reconnectTimerId: null
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return globalThis.__globalRedisState;
|
|
25
|
+
}
|
|
26
|
+
function getRedisErrorThreshold() {
|
|
27
|
+
return getCacheFallbackConfig().redisErrorThresholdGlobal;
|
|
28
|
+
}
|
|
29
|
+
function getRedisReconnectInterval() {
|
|
30
|
+
return getCacheFallbackConfig().redisReconnectInterval;
|
|
31
|
+
}
|
|
32
|
+
function isRedisGloballyDisabled() {
|
|
33
|
+
return getGlobalRedisState().isDisabled;
|
|
34
|
+
}
|
|
35
|
+
function notifyRedisError(error, source) {
|
|
36
|
+
const state = getGlobalRedisState();
|
|
37
|
+
state.errorCount++;
|
|
38
|
+
state.lastErrorTime = /* @__PURE__ */ new Date();
|
|
39
|
+
state.lastErrorMessage = error.message;
|
|
40
|
+
const threshold = getRedisErrorThreshold();
|
|
41
|
+
logger.warn("[Redis:Global] Redis error occurred", {
|
|
42
|
+
source,
|
|
43
|
+
errorCount: state.errorCount,
|
|
44
|
+
threshold,
|
|
45
|
+
error: error.message
|
|
46
|
+
});
|
|
47
|
+
if (state.errorCount >= threshold && !state.isDisabled) {
|
|
48
|
+
disableRedisGlobally();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function disableRedisGlobally() {
|
|
52
|
+
const state = getGlobalRedisState();
|
|
53
|
+
if (state.isDisabled) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
state.isDisabled = true;
|
|
57
|
+
const reconnectInterval = getRedisReconnectInterval();
|
|
58
|
+
logger.warn("[Redis:Global] Redis globally disabled, falling back to in-memory cache", {
|
|
59
|
+
errorCount: state.errorCount,
|
|
60
|
+
lastError: state.lastErrorMessage,
|
|
61
|
+
reconnectIn: `${reconnectInterval}ms`
|
|
62
|
+
});
|
|
63
|
+
if (state.reconnectTimerId) {
|
|
64
|
+
clearTimeout(state.reconnectTimerId);
|
|
65
|
+
}
|
|
66
|
+
state.reconnectTimerId = setTimeout(() => {
|
|
67
|
+
tryReconnectRedisGlobally();
|
|
68
|
+
}, reconnectInterval);
|
|
69
|
+
}
|
|
70
|
+
async function tryReconnectRedisGlobally() {
|
|
71
|
+
const state = getGlobalRedisState();
|
|
72
|
+
logger.info("[Redis:Global] Attempting Redis reconnection...");
|
|
73
|
+
try {
|
|
74
|
+
const env = getEnv();
|
|
75
|
+
if (!env.UPSTASH_REDIS_REST_URL || !env.UPSTASH_REDIS_REST_TOKEN) {
|
|
76
|
+
scheduleNextReconnect();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const redis = new Redis({
|
|
80
|
+
url: env.UPSTASH_REDIS_REST_URL,
|
|
81
|
+
token: env.UPSTASH_REDIS_REST_TOKEN
|
|
82
|
+
});
|
|
83
|
+
const pingResult = await redis.ping();
|
|
84
|
+
if (pingResult === "PONG") {
|
|
85
|
+
resetRedisGlobalState();
|
|
86
|
+
logger.info("[Redis:Global] Redis reconnection successful");
|
|
87
|
+
} else {
|
|
88
|
+
scheduleNextReconnect();
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
logger.warn("[Redis:Global] Redis reconnection failed", {
|
|
92
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
93
|
+
});
|
|
94
|
+
scheduleNextReconnect();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function scheduleNextReconnect() {
|
|
98
|
+
const state = getGlobalRedisState();
|
|
99
|
+
if (state.reconnectTimerId) {
|
|
100
|
+
clearTimeout(state.reconnectTimerId);
|
|
101
|
+
}
|
|
102
|
+
state.reconnectTimerId = setTimeout(() => {
|
|
103
|
+
tryReconnectRedisGlobally();
|
|
104
|
+
}, getRedisReconnectInterval());
|
|
105
|
+
}
|
|
106
|
+
function resetRedisGlobalState() {
|
|
107
|
+
const state = getGlobalRedisState();
|
|
108
|
+
if (state.errorCount > 0 || state.isDisabled) {
|
|
109
|
+
logger.info("[Redis:Global] Redis global state reset", {
|
|
110
|
+
previousErrorCount: state.errorCount,
|
|
111
|
+
wasDisabled: state.isDisabled
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
state.isDisabled = false;
|
|
115
|
+
state.errorCount = 0;
|
|
116
|
+
state.lastErrorTime = null;
|
|
117
|
+
state.lastErrorMessage = null;
|
|
118
|
+
if (state.reconnectTimerId) {
|
|
119
|
+
clearTimeout(state.reconnectTimerId);
|
|
120
|
+
state.reconnectTimerId = null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function getRedisGlobalStatus() {
|
|
124
|
+
const state = getGlobalRedisState();
|
|
125
|
+
return {
|
|
126
|
+
isDisabled: state.isDisabled,
|
|
127
|
+
errorCount: state.errorCount,
|
|
128
|
+
lastErrorTime: state.lastErrorTime,
|
|
129
|
+
lastErrorMessage: state.lastErrorMessage
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function checkRedisConnection() {
|
|
133
|
+
var _a;
|
|
134
|
+
const startTime = Date.now();
|
|
135
|
+
try {
|
|
136
|
+
if (!isCacheEnabled()) {
|
|
137
|
+
logger.info("[Redis:Cache] Redis connection check skipped: CACHE_ENABLED=false", {
|
|
138
|
+
purpose: "cache"
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
success: false,
|
|
142
|
+
error: "Redis cache is disabled (CACHE_ENABLED=false)",
|
|
143
|
+
details: {
|
|
144
|
+
purpose: "cache",
|
|
145
|
+
reason: "CACHE_ENABLED=false",
|
|
146
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (!getConfig().isRedisAvailable()) {
|
|
151
|
+
logger.info("[Redis:Cache] Redis connection check skipped: CACHE_REDIS_ENABLED=false", {
|
|
152
|
+
purpose: "cache"
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
success: false,
|
|
156
|
+
error: "Redis backend is disabled (CACHE_REDIS_ENABLED=false)",
|
|
157
|
+
details: {
|
|
158
|
+
purpose: "cache",
|
|
159
|
+
reason: "CACHE_REDIS_ENABLED=false",
|
|
160
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const envValidation = validateRedisEnvironment();
|
|
165
|
+
const env = getEnv();
|
|
166
|
+
if (!envValidation.isValid) {
|
|
167
|
+
const error = `Redis environment variable validation failed: ${envValidation.errors.join(", ")}`;
|
|
168
|
+
logger.error("[Redis:Cache] Redis connection failed: Environment variable validation failed", {
|
|
169
|
+
purpose: "cache",
|
|
170
|
+
errors: envValidation.errors,
|
|
171
|
+
nodeEnv: env.NODE_ENV,
|
|
172
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
173
|
+
});
|
|
174
|
+
return { success: false, error };
|
|
175
|
+
}
|
|
176
|
+
logger.info("[Redis:Cache] Redis connection status check started", {
|
|
177
|
+
purpose: "cache"
|
|
178
|
+
});
|
|
179
|
+
const redisUrl = env.UPSTASH_REDIS_REST_URL;
|
|
180
|
+
const redisToken = env.UPSTASH_REDIS_REST_TOKEN;
|
|
181
|
+
if (!redisUrl || !redisToken || redisUrl.trim() === "" || redisToken.trim() === "") {
|
|
182
|
+
const error = "Redis environment variables are not configured.";
|
|
183
|
+
logger.error("[Redis:Cache] Redis connection failed: Environment variables not set", {
|
|
184
|
+
purpose: "cache",
|
|
185
|
+
redisUrl: !!redisUrl,
|
|
186
|
+
redisToken: !!redisToken,
|
|
187
|
+
redisUrlLength: (redisUrl == null ? void 0 : redisUrl.length) || 0,
|
|
188
|
+
redisTokenLength: (redisToken == null ? void 0 : redisToken.length) || 0,
|
|
189
|
+
nodeEnv: env.NODE_ENV,
|
|
190
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
191
|
+
});
|
|
192
|
+
return { success: false, error };
|
|
193
|
+
}
|
|
194
|
+
const redis = new Redis({
|
|
195
|
+
url: redisUrl,
|
|
196
|
+
token: redisToken
|
|
197
|
+
});
|
|
198
|
+
logger.info("[Redis:Cache] Redis client creation complete", {
|
|
199
|
+
purpose: "cache",
|
|
200
|
+
url: redisUrl.substring(0, 50) + "...",
|
|
201
|
+
tokenLength: redisToken.length
|
|
202
|
+
});
|
|
203
|
+
const pingResult = await redis.ping();
|
|
204
|
+
const responseTime = Date.now() - startTime;
|
|
205
|
+
if (pingResult === "PONG") {
|
|
206
|
+
logger.info("[Redis:Cache] Redis connection successful", {
|
|
207
|
+
purpose: "cache",
|
|
208
|
+
responseTime: `${responseTime}ms`,
|
|
209
|
+
pingResult
|
|
210
|
+
});
|
|
211
|
+
return {
|
|
212
|
+
success: true,
|
|
213
|
+
details: {
|
|
214
|
+
purpose: "cache",
|
|
215
|
+
responseTime,
|
|
216
|
+
pingResult,
|
|
217
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
} else {
|
|
221
|
+
const error = `Redis PING response differs from expected: ${pingResult}`;
|
|
222
|
+
logger.error("[Redis:Cache] Redis connection failed: PING response error", {
|
|
223
|
+
purpose: "cache",
|
|
224
|
+
expected: "PONG",
|
|
225
|
+
received: pingResult,
|
|
226
|
+
responseTime: `${responseTime}ms`
|
|
227
|
+
});
|
|
228
|
+
return { success: false, error };
|
|
229
|
+
}
|
|
230
|
+
} catch (error) {
|
|
231
|
+
const responseTime = Date.now() - startTime;
|
|
232
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
233
|
+
logger.error("[Redis:Cache] Redis connection failed: Exception occurred", {
|
|
234
|
+
purpose: "cache",
|
|
235
|
+
error: errorMessage,
|
|
236
|
+
responseTime: `${responseTime}ms`,
|
|
237
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
238
|
+
nodeEnv: getEnv().NODE_ENV,
|
|
239
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
240
|
+
});
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
error: errorMessage,
|
|
244
|
+
details: {
|
|
245
|
+
purpose: "cache",
|
|
246
|
+
responseTime,
|
|
247
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
248
|
+
errorType: (_a = error == null ? void 0 : error.constructor) == null ? void 0 : _a.name
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function isRedisAvailableNow() {
|
|
254
|
+
if (isRedisGloballyDisabled()) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
return isCacheEnabled() && getConfig().isRedisAvailable();
|
|
258
|
+
}
|
|
259
|
+
var _redisClient = null;
|
|
260
|
+
var _redisInitialized = false;
|
|
261
|
+
function getRedisClient() {
|
|
262
|
+
if (isRedisGloballyDisabled()) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
if (_redisInitialized) {
|
|
266
|
+
return _redisClient;
|
|
267
|
+
}
|
|
268
|
+
_redisInitialized = true;
|
|
269
|
+
if (!isRedisAvailableNow()) {
|
|
270
|
+
_redisClient = null;
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
const env = getEnv();
|
|
274
|
+
if (!env.UPSTASH_REDIS_REST_URL || !env.UPSTASH_REDIS_REST_TOKEN) {
|
|
275
|
+
_redisClient = null;
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
_redisClient = new Redis({
|
|
279
|
+
url: env.UPSTASH_REDIS_REST_URL,
|
|
280
|
+
token: env.UPSTASH_REDIS_REST_TOKEN
|
|
281
|
+
});
|
|
282
|
+
return _redisClient;
|
|
283
|
+
}
|
|
284
|
+
function logRedisInitialization() {
|
|
285
|
+
var _a;
|
|
286
|
+
if (typeof globalThis !== "undefined" && globalThis.__redisCacheInitLogged) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const redis = getRedisClient();
|
|
290
|
+
const env = getEnv();
|
|
291
|
+
if (isRedisAvailableNow() && redis) {
|
|
292
|
+
logger.info("[Redis:Cache] Upstash Redis cache connection initialization complete", {
|
|
293
|
+
purpose: "cache",
|
|
294
|
+
url: ((_a = env.UPSTASH_REDIS_REST_URL) == null ? void 0 : _a.substring(0, 50)) + "...",
|
|
295
|
+
cacheEnabled: isCacheEnabled()
|
|
296
|
+
});
|
|
297
|
+
} else if (!isCacheEnabled()) {
|
|
298
|
+
logger.info("[Redis:Cache] Redis cache disabled (CACHE_ENABLED=false)", {
|
|
299
|
+
purpose: "cache",
|
|
300
|
+
cacheEnabled: false,
|
|
301
|
+
redisUrlSet: !!env.UPSTASH_REDIS_REST_URL,
|
|
302
|
+
redisTokenSet: !!env.UPSTASH_REDIS_REST_TOKEN
|
|
303
|
+
});
|
|
304
|
+
} else {
|
|
305
|
+
logger.warn("[Redis:Cache] Cache disabled due to missing Redis environment variables", {
|
|
306
|
+
purpose: "cache",
|
|
307
|
+
cacheEnabled: isCacheEnabled(),
|
|
308
|
+
redisUrlSet: !!env.UPSTASH_REDIS_REST_URL,
|
|
309
|
+
redisTokenSet: !!env.UPSTASH_REDIS_REST_TOKEN
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
if (typeof globalThis !== "undefined") {
|
|
313
|
+
globalThis.__redisCacheInitLogged = true;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export {
|
|
318
|
+
isRedisGloballyDisabled,
|
|
319
|
+
notifyRedisError,
|
|
320
|
+
resetRedisGlobalState,
|
|
321
|
+
getRedisGlobalStatus,
|
|
322
|
+
checkRedisConnection,
|
|
323
|
+
isRedisAvailableNow,
|
|
324
|
+
getRedisClient,
|
|
325
|
+
logRedisInitialization
|
|
326
|
+
};
|