@withwiz/toolkit 0.2.3 → 0.2.5
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/dist/auth/core/jwt/index.d.ts +1 -1
- package/dist/auth/core/jwt/index.js +1 -1
- package/dist/auth/index.js +19 -19
- package/dist/cache/cache-config.js +3 -3
- package/dist/cache/cache-env.js +2 -2
- package/dist/cache/cache-factory.js +9 -9
- package/dist/cache/cache-invalidation.js +10 -10
- package/dist/cache/cache-redis.js +3 -3
- package/dist/cache/cache-wrapper.js +10 -10
- package/dist/cache/cache.js +11 -11
- package/dist/cache/hybrid-cache-manager.js +5 -5
- package/dist/cache/index.js +11 -11
- package/dist/cache/inmemory-cache-manager.js +2 -2
- package/dist/cache/noop-cache-manager.js +4 -4
- package/dist/cache/redis-cache-manager.js +4 -4
- package/dist/{chunk-T3LJYAMO.js → chunk-2ATBAIRL.js} +5 -9
- package/dist/{chunk-XPASCCUA.js → chunk-45PS6FPL.js} +3 -3
- package/dist/{chunk-4KJXENRM.js → chunk-56BKKJOG.js} +1 -1
- package/dist/{chunk-HV3DGSSH.js → chunk-6FDDVTJY.js} +4 -4
- package/dist/{chunk-2KAPUVIS.js → chunk-7JWIX5BS.js} +1 -1
- package/dist/{chunk-TMVS4F7E.js → chunk-7T6EAU4I.js} +33 -8
- package/dist/{chunk-26Y7VEYG.js → chunk-BCCXV7VY.js} +1 -1
- package/dist/{chunk-6LTZCXNC.js → chunk-BYQ6VG44.js} +2 -2
- package/dist/{chunk-Q7IP4JMW.js → chunk-DM6ANZVI.js} +2 -2
- package/dist/chunk-ELD6UH57.js +68 -0
- package/dist/{chunk-KAWVMIRJ.js → chunk-GJGLG2MN.js} +1 -1
- package/dist/{chunk-4DPSCTX4.js → chunk-HC7574TB.js} +2 -2
- package/dist/{chunk-N4YGR5WH.js → chunk-HCF3C3AQ.js} +11 -10
- package/dist/{chunk-EZR55KV2.js → chunk-HJIKCR6I.js} +1 -1
- package/dist/{chunk-I47QEDTX.js → chunk-HJL63P7P.js} +1 -1
- package/dist/{chunk-YBSHN67U.js → chunk-HWIINS3Q.js} +4 -4
- package/dist/{chunk-3DZA6AGS.js → chunk-IJCVFLEY.js} +11 -4
- package/dist/{chunk-AIHQBQ3E.js → chunk-IVL62PFY.js} +8 -8
- package/dist/{chunk-KXAWBFJN.js → chunk-IYXMGIEP.js} +11 -10
- package/dist/{chunk-GPBOMJSZ.js → chunk-JVDJKMEF.js} +75 -17
- package/dist/{chunk-MLGO3HLS.js → chunk-KXXROUA5.js} +20 -5
- package/dist/{chunk-TXGNSECL.js → chunk-L26D4FDX.js} +1 -1
- package/dist/{chunk-G4NI37NN.js → chunk-L7AJJ3LC.js} +2 -2
- package/dist/{chunk-UXQRU3EM.js → chunk-MNORDAW2.js} +4 -4
- package/dist/{chunk-BKGVSC6S.js → chunk-MP66AGW5.js} +1 -1
- package/dist/{chunk-KWTBD4CM.js → chunk-P62T7AWY.js} +1 -1
- package/dist/{chunk-SLG26KHZ.js → chunk-PDQCJR4E.js} +10 -10
- package/dist/{chunk-WHR7HPWF.js → chunk-PJMXRAHZ.js} +2 -2
- package/dist/{chunk-Z4D4CMDA.js → chunk-PQ6GH2RP.js} +1 -1
- package/dist/{chunk-POKGHK3L.js → chunk-S54PFAEU.js} +2 -2
- package/dist/{chunk-WSQMXMTL.js → chunk-SKCYXBDR.js} +6 -2
- package/dist/{chunk-Y3OTJH2S.js → chunk-SNVGJPPX.js} +36 -13
- package/dist/{chunk-TZAP5T4N.js → chunk-T7J2OS63.js} +1 -1
- package/dist/{chunk-H5I5GWAA.js → chunk-UZDNS7TE.js} +3 -3
- package/dist/{chunk-GL2NANFH.js → chunk-VK23K5W7.js} +3 -3
- package/dist/{chunk-65LHDFU3.js → chunk-VQCW6FKJ.js} +2 -2
- package/dist/{chunk-L76O3X3D.js → chunk-WVPCER6E.js} +2 -2
- package/dist/{chunk-EEUBKZV4.js → chunk-Y2JYA2AR.js} +2 -2
- package/dist/{chunk-4ODT3Q4A.js → chunk-YGZBEEW2.js} +1 -1
- package/dist/constants/error-codes.d.ts +19 -12
- package/dist/constants/error-codes.js +3 -1
- package/dist/constants/index.js +3 -1
- package/dist/error/app-error.d.ts +1 -0
- package/dist/error/app-error.js +2 -2
- package/dist/error/error-display.d.ts +1 -1
- package/dist/error/error-display.js +7 -3
- package/dist/error/error-handler.d.ts +51 -12
- package/dist/error/error-handler.js +7 -4
- package/dist/error/friendly-messages-v2.js +5 -5
- package/dist/error/friendly-messages.d.ts +3 -0
- package/dist/error/friendly-messages.js +113 -5
- package/dist/error/index.js +23 -21
- package/dist/error/messages/en.js +1 -1
- package/dist/error/messages/index.js +3 -3
- package/dist/error/messages/ko.js +1 -1
- package/dist/geolocation/batch-processor.js +2 -2
- package/dist/geolocation/index.js +2 -2
- package/dist/logger/logger.js +1 -1
- package/dist/middleware/auth.js +5 -5
- package/dist/middleware/cors.d.ts +39 -6
- package/dist/middleware/cors.js +4 -2
- package/dist/middleware/error-handler.js +9 -7
- package/dist/middleware/index.js +19 -18
- package/dist/middleware/middleware-chain.js +2 -2
- package/dist/middleware/rate-limit.js +4 -4
- package/dist/middleware/response-logger.js +2 -2
- package/dist/middleware/security.js +2 -1
- package/dist/middleware/wrappers.js +16 -15
- package/dist/storage/r2-storage.js +7 -3
- package/dist/system/cpu.js +3 -3
- package/dist/system/disk.js +3 -3
- package/dist/system/environment.js +3 -3
- package/dist/system/health-check.js +3 -3
- package/dist/system/index.js +10 -10
- package/dist/system/memory.js +3 -3
- package/dist/system/network.js +3 -3
- package/dist/system/utils.js +2 -2
- package/dist/utils/api-helpers.js +2 -2
- package/dist/utils/csv-export.js +2 -2
- package/dist/utils/error-processor.js +4 -4
- package/dist/utils/index.js +19 -19
- package/dist/utils/input-validation.d.ts +2 -0
- package/dist/utils/input-validation.js +4 -5
- package/dist/utils/optimistic-lock.js +2 -2
- package/package.json +2 -1
- package/dist/chunk-2DVWSDST.js +0 -119
- package/dist/chunk-FOKAATUQ.js +0 -62
|
@@ -61,6 +61,16 @@ var enMessages = {
|
|
|
61
61
|
description: "Your session has expired for security.",
|
|
62
62
|
action: "Please login again."
|
|
63
63
|
},
|
|
64
|
+
40104: {
|
|
65
|
+
title: "Password required",
|
|
66
|
+
description: "You must enter a password.",
|
|
67
|
+
action: "Please enter the password."
|
|
68
|
+
},
|
|
69
|
+
40105: {
|
|
70
|
+
title: "Incorrect password",
|
|
71
|
+
description: "The password is incorrect.",
|
|
72
|
+
action: "Please check again."
|
|
73
|
+
},
|
|
64
74
|
40106: {
|
|
65
75
|
title: "Login failed",
|
|
66
76
|
description: "Email or password is incorrect.",
|
|
@@ -173,16 +183,7 @@ var enMessages = {
|
|
|
173
183
|
description: "Usage has been stopped.",
|
|
174
184
|
action: "Please contact the owner."
|
|
175
185
|
},
|
|
176
|
-
42206:
|
|
177
|
-
title: "Password required",
|
|
178
|
-
description: "You must enter a password.",
|
|
179
|
-
action: "Please enter the password."
|
|
180
|
-
},
|
|
181
|
-
42207: {
|
|
182
|
-
title: "Incorrect password",
|
|
183
|
-
description: "The password is incorrect.",
|
|
184
|
-
action: "Please check again."
|
|
185
|
-
},
|
|
186
|
+
// 42206, 42207: moved to 401xx → see 40104, 40105 below
|
|
186
187
|
42208: {
|
|
187
188
|
title: "Alias not allowed",
|
|
188
189
|
description: "This is a system reserved word.",
|
|
@@ -30,7 +30,7 @@ var colors = {
|
|
|
30
30
|
debug: "blue"
|
|
31
31
|
};
|
|
32
32
|
winston.addColors(colors);
|
|
33
|
-
var isTestEnv = process.env.NODE_ENV === "test" || process.env.JEST_WORKER_ID !== void 0;
|
|
33
|
+
var isTestEnv = process.env.NODE_ENV === "test" || process.env.VITEST !== void 0 || process.env.JEST_WORKER_ID !== void 0;
|
|
34
34
|
var isBuildTime = process.env.NEXT_PHASE === "phase-production-build" || process.argv.some((arg) => arg.includes("build"));
|
|
35
35
|
var canWriteToLogDir = (() => {
|
|
36
36
|
if (isTestEnv || isBuildTime) return false;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getCacheManager,
|
|
3
3
|
getEffectiveCacheBackend
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-IVL62PFY.js";
|
|
5
5
|
import {
|
|
6
6
|
getCacheConfig,
|
|
7
7
|
getCacheTTL
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-L26D4FDX.js";
|
|
9
9
|
import {
|
|
10
10
|
isCacheEnabled
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-HJL63P7P.js";
|
|
12
12
|
import {
|
|
13
13
|
logger
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-HJIKCR6I.js";
|
|
15
15
|
|
|
16
16
|
// src/cache/cache-wrapper.ts
|
|
17
17
|
function getCacheBackendLabel() {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getErrorDisplayInfo,
|
|
3
3
|
getFriendlyMessage
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-S54PFAEU.js";
|
|
5
|
+
import {
|
|
6
|
+
AppError
|
|
7
|
+
} from "./chunk-KXXROUA5.js";
|
|
5
8
|
import {
|
|
6
9
|
getErrorCategory
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-SNVGJPPX.js";
|
|
8
11
|
|
|
9
12
|
// src/error/error-display.ts
|
|
10
13
|
import { toast } from "sonner";
|
|
@@ -51,7 +54,7 @@ function showFriendlyError(errorOrCode, options) {
|
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
async function handleApiResponse(response, options) {
|
|
54
|
-
var _a;
|
|
57
|
+
var _a, _b;
|
|
55
58
|
if (response.ok) {
|
|
56
59
|
const data = await response.json();
|
|
57
60
|
return data.data;
|
|
@@ -63,7 +66,11 @@ async function handleApiResponse(response, options) {
|
|
|
63
66
|
onAuthError: options == null ? void 0 : options.onAuthError
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
|
-
|
|
69
|
+
const errorCode = (_a = errorData.error) == null ? void 0 : _a.code;
|
|
70
|
+
if (errorCode) {
|
|
71
|
+
throw new AppError(errorCode, (_b = errorData.error) == null ? void 0 : _b.message);
|
|
72
|
+
}
|
|
73
|
+
throw AppError.fromKey("SERVER_ERROR", `Request failed with status ${response.status}`);
|
|
67
74
|
}
|
|
68
75
|
function formatInlineError(code, locale) {
|
|
69
76
|
const lang = locale || getLocale();
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
HybridCacheManager
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6FDDVTJY.js";
|
|
4
4
|
import {
|
|
5
5
|
InMemoryCacheManager
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-PQ6GH2RP.js";
|
|
7
7
|
import {
|
|
8
8
|
NoopCacheManager
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-DM6ANZVI.js";
|
|
10
10
|
import {
|
|
11
11
|
RedisCacheManager
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-VK23K5W7.js";
|
|
13
13
|
import {
|
|
14
14
|
getCacheConfig
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-L26D4FDX.js";
|
|
16
16
|
import {
|
|
17
17
|
isRedisAvailableNow,
|
|
18
18
|
isRedisGloballyDisabled
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-BYQ6VG44.js";
|
|
20
20
|
import {
|
|
21
21
|
getENV,
|
|
22
22
|
isCacheEnabled
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-HJL63P7P.js";
|
|
24
24
|
import {
|
|
25
25
|
logger
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-HJIKCR6I.js";
|
|
27
27
|
|
|
28
28
|
// src/cache/cache-factory.ts
|
|
29
29
|
function getInMemoryConfig() {
|
|
@@ -61,6 +61,16 @@ var koMessages = {
|
|
|
61
61
|
description: "\uBCF4\uC548\uC744 \uC704\uD574 \uC138\uC158\uC774 \uB9CC\uB8CC\uB418\uC5C8\uC2B5\uB2C8\uB2E4.",
|
|
62
62
|
action: "\uB2E4\uC2DC \uB85C\uADF8\uC778\uD574 \uC8FC\uC138\uC694."
|
|
63
63
|
},
|
|
64
|
+
40104: {
|
|
65
|
+
title: "\uBE44\uBC00\uBC88\uD638\uAC00 \uD544\uC694\uD574\uC694",
|
|
66
|
+
description: "\uBE44\uBC00\uBC88\uD638\uB97C \uC785\uB825\uD574\uC57C \uD569\uB2C8\uB2E4.",
|
|
67
|
+
action: "\uBE44\uBC00\uBC88\uD638\uB97C \uC785\uB825\uD574 \uC8FC\uC138\uC694."
|
|
68
|
+
},
|
|
69
|
+
40105: {
|
|
70
|
+
title: "\uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC5B4\uC694",
|
|
71
|
+
description: "\uBE44\uBC00\uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
|
|
72
|
+
action: "\uB2E4\uC2DC \uD655\uC778\uD574 \uC8FC\uC138\uC694."
|
|
73
|
+
},
|
|
64
74
|
40106: {
|
|
65
75
|
title: "\uB85C\uADF8\uC778\uC5D0 \uC2E4\uD328\uD588\uC5B4\uC694",
|
|
66
76
|
description: "\uC774\uBA54\uC77C \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
|
|
@@ -173,16 +183,7 @@ var koMessages = {
|
|
|
173
183
|
description: "\uC0AC\uC6A9\uC774 \uC911\uC9C0\uB418\uC5C8\uC2B5\uB2C8\uB2E4.",
|
|
174
184
|
action: "\uC18C\uC720\uC790\uC5D0\uAC8C \uBB38\uC758\uD574 \uC8FC\uC138\uC694."
|
|
175
185
|
},
|
|
176
|
-
42206:
|
|
177
|
-
title: "\uBE44\uBC00\uBC88\uD638\uAC00 \uD544\uC694\uD574\uC694",
|
|
178
|
-
description: "\uBE44\uBC00\uBC88\uD638\uB97C \uC785\uB825\uD574\uC57C \uD569\uB2C8\uB2E4.",
|
|
179
|
-
action: "\uBE44\uBC00\uBC88\uD638\uB97C \uC785\uB825\uD574 \uC8FC\uC138\uC694."
|
|
180
|
-
},
|
|
181
|
-
42207: {
|
|
182
|
-
title: "\uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC5B4\uC694",
|
|
183
|
-
description: "\uBE44\uBC00\uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
|
|
184
|
-
action: "\uB2E4\uC2DC \uD655\uC778\uD574 \uC8FC\uC138\uC694."
|
|
185
|
-
},
|
|
186
|
+
// 42206, 42207: 401xx로 이동 → 아래 40104, 40105 참조
|
|
186
187
|
42208: {
|
|
187
188
|
title: "\uC0AC\uC6A9\uD560 \uC218 \uC5C6\uB294 \uBCC4\uCE6D\uC774\uC5D0\uC694",
|
|
188
189
|
description: "\uC2DC\uC2A4\uD15C \uC608\uC57D\uC5B4\uC785\uB2C8\uB2E4.",
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AppError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KXXROUA5.js";
|
|
4
4
|
import {
|
|
5
5
|
ERROR_CODES,
|
|
6
|
+
classifyError,
|
|
6
7
|
formatErrorMessage,
|
|
7
8
|
getHttpStatus
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-SNVGJPPX.js";
|
|
10
|
+
import {
|
|
11
|
+
AuthError
|
|
12
|
+
} from "./chunk-AIH3F7JV.js";
|
|
9
13
|
import {
|
|
10
14
|
logger
|
|
11
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-HJIKCR6I.js";
|
|
12
16
|
import {
|
|
13
17
|
__spreadProps,
|
|
14
18
|
__spreadValues
|
|
@@ -17,6 +21,37 @@ import {
|
|
|
17
21
|
// src/error/error-handler.ts
|
|
18
22
|
import { NextResponse } from "next/server";
|
|
19
23
|
import { z } from "zod";
|
|
24
|
+
var AUTH_ERROR_CODE_MAP = {
|
|
25
|
+
// JWT
|
|
26
|
+
TOKEN_EXPIRED: ERROR_CODES.TOKEN_EXPIRED.code,
|
|
27
|
+
TOKEN_INVALID: ERROR_CODES.INVALID_TOKEN.code,
|
|
28
|
+
TOKEN_CREATION_FAILED: ERROR_CODES.SERVER_ERROR.code,
|
|
29
|
+
TOKEN_VERIFICATION_FAILED: ERROR_CODES.INVALID_TOKEN.code,
|
|
30
|
+
REFRESH_TOKEN_EXPIRED: ERROR_CODES.TOKEN_EXPIRED.code,
|
|
31
|
+
INVALID_PAYLOAD: ERROR_CODES.INVALID_TOKEN.code,
|
|
32
|
+
// OAuth
|
|
33
|
+
OAUTH_PROVIDER_NOT_CONFIGURED: ERROR_CODES.EXTERNAL_SERVICE_ERROR.code,
|
|
34
|
+
OAUTH_TOKEN_EXCHANGE_FAILED: ERROR_CODES.EXTERNAL_SERVICE_ERROR.code,
|
|
35
|
+
OAUTH_USER_INFO_FAILED: ERROR_CODES.EXTERNAL_SERVICE_ERROR.code,
|
|
36
|
+
// Password
|
|
37
|
+
PASSWORD_TOO_SHORT: ERROR_CODES.PASSWORD_TOO_WEAK.code,
|
|
38
|
+
PASSWORD_TOO_LONG: ERROR_CODES.PASSWORD_TOO_WEAK.code,
|
|
39
|
+
PASSWORD_MISSING_NUMBER: ERROR_CODES.PASSWORD_TOO_WEAK.code,
|
|
40
|
+
PASSWORD_MISSING_UPPERCASE: ERROR_CODES.PASSWORD_TOO_WEAK.code,
|
|
41
|
+
PASSWORD_MISSING_LOWERCASE: ERROR_CODES.PASSWORD_TOO_WEAK.code,
|
|
42
|
+
PASSWORD_MISSING_SPECIAL_CHAR: ERROR_CODES.PASSWORD_TOO_WEAK.code,
|
|
43
|
+
PASSWORD_HASH_FAILED: ERROR_CODES.SERVER_ERROR.code,
|
|
44
|
+
PASSWORD_VERIFY_FAILED: ERROR_CODES.SERVER_ERROR.code,
|
|
45
|
+
// Email
|
|
46
|
+
EMAIL_SEND_FAILED: ERROR_CODES.EMAIL_SEND_FAILED.code,
|
|
47
|
+
EMAIL_TOKEN_EXPIRED: ERROR_CODES.TOKEN_EXPIRED.code,
|
|
48
|
+
EMAIL_TOKEN_INVALID: ERROR_CODES.INVALID_TOKEN.code,
|
|
49
|
+
// Generic
|
|
50
|
+
INVALID_CREDENTIALS: ERROR_CODES.INVALID_CREDENTIALS.code,
|
|
51
|
+
USER_NOT_FOUND: ERROR_CODES.USER_NOT_FOUND.code,
|
|
52
|
+
EMAIL_ALREADY_EXISTS: ERROR_CODES.EMAIL_ALREADY_EXISTS.code,
|
|
53
|
+
UNAUTHORIZED: ERROR_CODES.UNAUTHORIZED.code
|
|
54
|
+
};
|
|
20
55
|
var PRISMA_ERROR_MAP = {
|
|
21
56
|
P2000: { code: 40001, message: "\uC785\uB825\uAC12\uC774 \uB108\uBB34 \uAE41\uB2C8\uB2E4." },
|
|
22
57
|
P2001: { code: 40401, message: "\uB808\uCF54\uB4DC\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4." },
|
|
@@ -50,6 +85,14 @@ function processError(error) {
|
|
|
50
85
|
details: { issues }
|
|
51
86
|
};
|
|
52
87
|
}
|
|
88
|
+
if (error instanceof AuthError) {
|
|
89
|
+
const mappedCode = AUTH_ERROR_CODE_MAP[error.code];
|
|
90
|
+
if (mappedCode) {
|
|
91
|
+
return { code: mappedCode, message: formatErrorMessage(mappedCode, error.message), status: getHttpStatus(mappedCode) };
|
|
92
|
+
}
|
|
93
|
+
const fallbackCode = error.statusCode === 401 ? ERROR_CODES.UNAUTHORIZED.code : ERROR_CODES.BAD_REQUEST.code;
|
|
94
|
+
return { code: fallbackCode, message: formatErrorMessage(fallbackCode, error.message), status: error.statusCode };
|
|
95
|
+
}
|
|
53
96
|
if (error instanceof Error) {
|
|
54
97
|
const prismaMatch = error.message.match(/P\d{4}/);
|
|
55
98
|
if (prismaMatch) {
|
|
@@ -58,13 +101,8 @@ function processError(error) {
|
|
|
58
101
|
return { code: mapping.code, message: formatErrorMessage(mapping.code, mapping.message), status: getHttpStatus(mapping.code) };
|
|
59
102
|
}
|
|
60
103
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
if (error.message.toLowerCase().includes("unauthorized")) {
|
|
65
|
-
return { code: ERROR_CODES.UNAUTHORIZED.code, message: formatErrorMessage(ERROR_CODES.UNAUTHORIZED.code), status: 401 };
|
|
66
|
-
}
|
|
67
|
-
return { code: ERROR_CODES.SERVER_ERROR.code, message: formatErrorMessage(ERROR_CODES.SERVER_ERROR.code), status: 500 };
|
|
104
|
+
const classified = classifyError(error);
|
|
105
|
+
return { code: classified.code, message: formatErrorMessage(classified.code), status: classified.status };
|
|
68
106
|
}
|
|
69
107
|
return { code: ERROR_CODES.INTERNAL_SERVER_ERROR.code, message: formatErrorMessage(ERROR_CODES.INTERNAL_SERVER_ERROR.code), status: 500 };
|
|
70
108
|
}
|
|
@@ -81,13 +119,18 @@ var ErrorResponse = {
|
|
|
81
119
|
// 400xx
|
|
82
120
|
validation: (message, details) => errorToResponse(AppError.validation(message, details ? __spreadValues({}, details) : void 0)),
|
|
83
121
|
badRequest: (message) => errorToResponse(AppError.badRequest(message)),
|
|
122
|
+
invalidInput: (message) => errorToResponse(AppError.invalidInput(message)),
|
|
123
|
+
missingField: (fieldName) => errorToResponse(AppError.missingField(fieldName)),
|
|
84
124
|
invalidUrl: () => errorToResponse(AppError.invalidUrl()),
|
|
85
125
|
invalidEmail: () => errorToResponse(AppError.invalidEmail()),
|
|
126
|
+
weakPassword: () => errorToResponse(AppError.weakPassword()),
|
|
86
127
|
invalidAlias: () => errorToResponse(AppError.invalidAlias()),
|
|
87
128
|
// 401xx
|
|
88
129
|
unauthorized: (message) => errorToResponse(AppError.unauthorized(message)),
|
|
89
130
|
invalidToken: () => errorToResponse(AppError.invalidToken()),
|
|
90
131
|
tokenExpired: () => errorToResponse(AppError.tokenExpired()),
|
|
132
|
+
linkPasswordRequired: () => errorToResponse(AppError.linkPasswordRequired()),
|
|
133
|
+
linkPasswordIncorrect: () => errorToResponse(AppError.linkPasswordIncorrect()),
|
|
91
134
|
invalidCredentials: () => errorToResponse(AppError.invalidCredentials()),
|
|
92
135
|
sessionExpired: () => errorToResponse(AppError.sessionExpired()),
|
|
93
136
|
// 403xx
|
|
@@ -99,6 +142,9 @@ var ErrorResponse = {
|
|
|
99
142
|
notFound: (message) => errorToResponse(AppError.notFound(message)),
|
|
100
143
|
userNotFound: () => errorToResponse(AppError.userNotFound()),
|
|
101
144
|
linkNotFound: () => errorToResponse(AppError.linkNotFound()),
|
|
145
|
+
tagNotFound: () => errorToResponse(AppError.tagNotFound()),
|
|
146
|
+
favoriteNotFound: () => errorToResponse(AppError.favoriteNotFound()),
|
|
147
|
+
groupNotFound: () => errorToResponse(AppError.groupNotFound()),
|
|
102
148
|
// 409xx
|
|
103
149
|
conflict: (message) => errorToResponse(AppError.conflict(message)),
|
|
104
150
|
duplicate: (resource) => errorToResponse(AppError.duplicate(resource)),
|
|
@@ -106,28 +152,40 @@ var ErrorResponse = {
|
|
|
106
152
|
aliasExists: () => errorToResponse(AppError.aliasExists()),
|
|
107
153
|
// 422xx
|
|
108
154
|
businessRule: (message) => errorToResponse(AppError.businessRule(message)),
|
|
155
|
+
invalidOperation: (message) => errorToResponse(AppError.invalidOperation(message)),
|
|
109
156
|
linkExpired: () => errorToResponse(AppError.linkExpired()),
|
|
110
157
|
linkInactive: () => errorToResponse(AppError.linkInactive()),
|
|
111
|
-
linkPasswordRequired: () => errorToResponse(AppError.linkPasswordRequired()),
|
|
112
|
-
linkPasswordIncorrect: () => errorToResponse(AppError.linkPasswordIncorrect()),
|
|
113
158
|
reservedWord: () => errorToResponse(AppError.reservedWord()),
|
|
114
159
|
quotaExceeded: () => errorToResponse(AppError.quotaExceeded()),
|
|
160
|
+
alreadyFavorited: () => errorToResponse(AppError.alreadyFavorited()),
|
|
161
|
+
fileTooLarge: (maxSize) => errorToResponse(AppError.fileTooLarge(maxSize)),
|
|
162
|
+
unsupportedFileType: (fileType) => errorToResponse(AppError.unsupportedFileType(fileType)),
|
|
115
163
|
// 429xx
|
|
116
164
|
rateLimit: () => errorToResponse(AppError.rateLimit()),
|
|
117
165
|
dailyLimit: () => errorToResponse(AppError.dailyLimit()),
|
|
166
|
+
apiQuotaExceeded: () => errorToResponse(AppError.apiQuotaExceeded()),
|
|
118
167
|
// 500xx
|
|
119
168
|
serverError: (message) => errorToResponse(AppError.serverError(message)),
|
|
120
|
-
|
|
169
|
+
internalError: (message) => errorToResponse(AppError.internalError(message)),
|
|
170
|
+
databaseError: (message) => errorToResponse(AppError.databaseError(message)),
|
|
171
|
+
emailSendFailed: () => errorToResponse(AppError.emailSendFailed()),
|
|
172
|
+
cacheError: () => errorToResponse(AppError.cacheError()),
|
|
173
|
+
fileUploadFailed: () => errorToResponse(AppError.fileUploadFailed()),
|
|
121
174
|
// 503xx
|
|
122
|
-
serviceUnavailable: () => errorToResponse(AppError.serviceUnavailable()),
|
|
175
|
+
serviceUnavailable: (message) => errorToResponse(AppError.serviceUnavailable(message)),
|
|
123
176
|
externalServiceError: (service) => errorToResponse(AppError.externalServiceError(service)),
|
|
124
|
-
// 보안
|
|
125
|
-
accessBlocked: () => errorToResponse(AppError.accessBlocked()),
|
|
126
|
-
|
|
177
|
+
// 보안 (403xx 71~79)
|
|
178
|
+
accessBlocked: (reason) => errorToResponse(AppError.accessBlocked(reason)),
|
|
179
|
+
securityValidationFailed: () => errorToResponse(AppError.securityValidationFailed()),
|
|
180
|
+
blockedUrl: (url) => errorToResponse(AppError.blockedUrl(url)),
|
|
181
|
+
suspiciousActivity: () => errorToResponse(AppError.suspiciousActivity()),
|
|
182
|
+
ipBlocked: (ip) => errorToResponse(AppError.ipBlocked(ip)),
|
|
183
|
+
corsViolation: (origin) => errorToResponse(AppError.corsViolation(origin))
|
|
127
184
|
};
|
|
128
185
|
var error_handler_default = { errorToResponse, processError, withErrorHandler, ErrorResponse };
|
|
129
186
|
|
|
130
187
|
export {
|
|
188
|
+
AUTH_ERROR_CODE_MAP,
|
|
131
189
|
errorToResponse,
|
|
132
190
|
processError,
|
|
133
191
|
withErrorHandler,
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ERROR_CODES,
|
|
3
|
+
classifyError,
|
|
3
4
|
formatErrorMessage,
|
|
4
5
|
getErrorCategory,
|
|
5
6
|
getHttpStatus
|
|
6
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-SNVGJPPX.js";
|
|
7
8
|
|
|
8
9
|
// src/error/app-error.ts
|
|
9
10
|
var AppError = class _AppError extends Error {
|
|
10
11
|
constructor(code, message, details, requestId) {
|
|
11
12
|
const formattedMessage = formatErrorMessage(code, message);
|
|
12
13
|
super(formattedMessage);
|
|
14
|
+
if (!Number.isInteger(code) || code < 1e4 || code > 59999) {
|
|
15
|
+
const safeCode = ERROR_CODES.INTERNAL_SERVER_ERROR.code;
|
|
16
|
+
this.name = "AppError";
|
|
17
|
+
this.code = safeCode;
|
|
18
|
+
this.status = getHttpStatus(safeCode);
|
|
19
|
+
this.key = "INTERNAL_SERVER_ERROR";
|
|
20
|
+
this.category = getErrorCategory(safeCode);
|
|
21
|
+
this.details = details;
|
|
22
|
+
this.timestamp = /* @__PURE__ */ new Date();
|
|
23
|
+
this.requestId = requestId;
|
|
24
|
+
Object.setPrototypeOf(this, _AppError.prototype);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
13
27
|
this.name = "AppError";
|
|
14
28
|
this.code = code;
|
|
15
29
|
this.status = getHttpStatus(code);
|
|
@@ -97,10 +111,8 @@ var AppError = class _AppError extends Error {
|
|
|
97
111
|
const code = parseInt(codeMatch[1], 10);
|
|
98
112
|
return new _AppError(code, error.message.replace(/\s*\[\d{5}\]$/, ""));
|
|
99
113
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
fallbackMessage || ERROR_CODES.SERVER_ERROR.message
|
|
103
|
-
);
|
|
114
|
+
const classified = classifyError(error);
|
|
115
|
+
return new _AppError(classified.code, fallbackMessage || classified.message);
|
|
104
116
|
}
|
|
105
117
|
return new _AppError(
|
|
106
118
|
ERROR_CODES.INTERNAL_SERVER_ERROR.code,
|
|
@@ -320,6 +332,9 @@ var AppError = class _AppError extends Error {
|
|
|
320
332
|
static ipBlocked(ip) {
|
|
321
333
|
return _AppError.fromKey("IP_BLOCKED", void 0, { value: ip });
|
|
322
334
|
}
|
|
335
|
+
static corsViolation(origin) {
|
|
336
|
+
return _AppError.fromKey("CORS_VIOLATION", void 0, { value: origin });
|
|
337
|
+
}
|
|
323
338
|
};
|
|
324
339
|
var app_error_default = AppError;
|
|
325
340
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AppError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KXXROUA5.js";
|
|
4
4
|
import {
|
|
5
5
|
ERROR_CODES
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SNVGJPPX.js";
|
|
7
7
|
import {
|
|
8
8
|
JWTManager
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-2ATBAIRL.js";
|
|
10
10
|
import {
|
|
11
11
|
logger
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-HJIKCR6I.js";
|
|
13
13
|
|
|
14
14
|
// src/middleware/auth.ts
|
|
15
15
|
function setAccessTokenBlacklistChecker(checker) {
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
initRequestMiddleware
|
|
3
|
+
} from "./chunk-62Q7DN5G.js";
|
|
1
4
|
import {
|
|
2
5
|
MiddlewareChain
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-YGZBEEW2.js";
|
|
4
7
|
import {
|
|
5
8
|
rateLimitMiddleware
|
|
6
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-UZDNS7TE.js";
|
|
7
10
|
import {
|
|
8
11
|
responseLoggerMiddleware
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-GJGLG2MN.js";
|
|
10
13
|
import {
|
|
11
14
|
securityMiddleware
|
|
12
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-SKCYXBDR.js";
|
|
13
16
|
import {
|
|
14
17
|
adminMiddleware,
|
|
15
18
|
authMiddleware,
|
|
16
19
|
optionalAuthMiddleware
|
|
17
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-MNORDAW2.js";
|
|
18
21
|
import {
|
|
19
22
|
corsMiddleware
|
|
20
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-ELD6UH57.js";
|
|
21
24
|
import {
|
|
22
25
|
errorHandlerMiddleware
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import {
|
|
25
|
-
initRequestMiddleware
|
|
26
|
-
} from "./chunk-62Q7DN5G.js";
|
|
26
|
+
} from "./chunk-7T6EAU4I.js";
|
|
27
27
|
|
|
28
28
|
// src/middleware/wrappers.ts
|
|
29
29
|
function withPublicApi(handler) {
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
} from "./chunk-OIVXOT2X.js";
|
|
5
5
|
import {
|
|
6
6
|
getPlatform
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-P62T7AWY.js";
|
|
8
8
|
import {
|
|
9
9
|
logger
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-HJIKCR6I.js";
|
|
11
11
|
|
|
12
12
|
// src/system/health-check.ts
|
|
13
13
|
async function checkServiceHealth(prismaClient) {
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logger
|
|
3
|
+
} from "./chunk-HJIKCR6I.js";
|
|
4
|
+
|
|
1
5
|
// src/middleware/security.ts
|
|
2
6
|
import { NextResponse } from "next/server";
|
|
3
7
|
var BLOCKED_METHODS = ["TRACE", "TRACK"];
|
|
@@ -112,8 +116,8 @@ var securityMiddleware = async (context, next) => {
|
|
|
112
116
|
return response;
|
|
113
117
|
};
|
|
114
118
|
function validateSecurityConfiguration() {
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
logger.info("[Security Middleware] Blocked methods: " + BLOCKED_METHODS.join(", "));
|
|
120
|
+
logger.info("[Security Middleware] Allowed Content-Types: " + ALLOWED_CONTENT_TYPES.join(", "));
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
export {
|