@withwiz/toolkit 0.3.2 → 0.4.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/dist/auth/core/jwt/cookie.d.ts +21 -0
- package/dist/auth/core/jwt/cookie.js +9 -0
- package/dist/auth/core/jwt/index.d.ts +2 -0
- package/dist/auth/core/jwt/index.js +8 -2
- package/dist/auth/index.js +18 -17
- package/dist/{chunk-E54MAI4I.js → chunk-2F6KNGOD.js} +2 -2
- package/dist/{chunk-BKJPYZYO.js → chunk-3YUKCYHI.js} +4 -4
- package/dist/{chunk-S54PFAEU.js → chunk-7VTBRP5M.js} +2 -2
- package/dist/chunk-AJLUPYCQ.js +50 -0
- package/dist/{chunk-HCF3C3AQ.js → chunk-AKD4YMJU.js} +0 -61
- package/dist/{chunk-6MI4XLWC.js → chunk-AQJAY5FA.js} +2 -2
- package/dist/{chunk-TQJDNWBL.js → chunk-BJSEYZBH.js} +3 -3
- package/dist/{chunk-KXXROUA5.js → chunk-EOEMOXNT.js} +1 -44
- package/dist/{chunk-A6V6XVPZ.js → chunk-J5AISIJS.js} +18 -12
- package/dist/{chunk-Y2JYA2AR.js → chunk-JNJALNRR.js} +2 -2
- package/dist/{chunk-2KDLKHTO.js → chunk-L6AU74EI.js} +2 -14
- package/dist/{chunk-IYXMGIEP.js → chunk-ON4ENPUS.js} +0 -61
- package/dist/{chunk-SNVGJPPX.js → chunk-SNTLJ646.js} +0 -80
- package/dist/{chunk-7JWIX5BS.js → chunk-WMJ5M45N.js} +1 -1
- package/dist/{chunk-QVWDWROP.js → chunk-WMQE2YK7.js} +58 -0
- package/dist/{chunk-NQS7UT6X.js → chunk-YP5SAHAP.js} +4 -4
- package/dist/constants/error-codes.d.ts +0 -78
- package/dist/constants/error-codes.js +1 -1
- package/dist/constants/index.js +23 -23
- package/dist/error/app-error.d.ts +3 -16
- package/dist/error/app-error.js +2 -2
- package/dist/error/error-display.js +7 -7
- package/dist/error/error-handler.d.ts +0 -24
- package/dist/error/error-handler.js +3 -3
- package/dist/error/friendly-messages-v2.js +5 -5
- package/dist/error/friendly-messages.js +1 -15
- package/dist/error/index.js +8 -8
- 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/middleware/auth.d.ts +5 -2
- package/dist/middleware/auth.js +5 -4
- package/dist/middleware/error-handler.js +7 -7
- package/dist/middleware/index.d.ts +1 -1
- package/dist/middleware/index.js +15 -12
- package/dist/middleware/rate-limit.js +3 -3
- package/dist/middleware/security.d.ts +4 -0
- package/dist/middleware/security.js +3 -1
- package/dist/middleware/wrappers.js +13 -12
- package/dist/storage/r2-storage.js +2 -2
- package/dist/utils/api-helpers.js +2 -2
- package/dist/utils/error-processor.js +3 -3
- package/dist/utils/index.js +4 -4
- package/dist/utils/optimistic-lock.js +2 -2
- package/package.json +1 -1
- /package/dist/{chunk-R6YVUU6I.js → chunk-3GAY2T2A.js} +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JWT 토큰을 HttpOnly 쿠키로 설정/삭제하는 유틸리티
|
|
3
|
+
*
|
|
4
|
+
* NextResponse 타입을 제네릭으로 처리하여
|
|
5
|
+
* symlink 환경에서의 next 패키지 경로 충돌을 방지합니다.
|
|
6
|
+
*/
|
|
7
|
+
import type { TokenPair } from '@withwiz/auth/types';
|
|
8
|
+
/** cookies.set()을 지원하는 Response 타입 */
|
|
9
|
+
interface CookieSettableResponse {
|
|
10
|
+
cookies: {
|
|
11
|
+
set(name: string, value: string, options?: Record<string, unknown>): void;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface CookieOptions {
|
|
15
|
+
secure?: boolean;
|
|
16
|
+
sameSite?: 'lax' | 'strict' | 'none';
|
|
17
|
+
domain?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function setTokenCookies<T extends CookieSettableResponse>(response: T, tokenPair: TokenPair, options?: CookieOptions): T;
|
|
20
|
+
export declare function clearTokenCookies<T extends CookieSettableResponse>(response: T, options?: CookieOptions): T;
|
|
21
|
+
export {};
|
|
@@ -107,4 +107,6 @@ export declare class JWTService {
|
|
|
107
107
|
*/
|
|
108
108
|
extractTokenFromHeader(authHeader: string | undefined): string | null;
|
|
109
109
|
}
|
|
110
|
+
export { setTokenCookies, clearTokenCookies } from './cookie';
|
|
111
|
+
export type { CookieOptions } from './cookie';
|
|
110
112
|
export type { JWTConfig, JWTPayload, TokenPair };
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JWTManager,
|
|
3
3
|
JWTService
|
|
4
|
-
} from "../../../chunk-
|
|
4
|
+
} from "../../../chunk-3GAY2T2A.js";
|
|
5
|
+
import {
|
|
6
|
+
clearTokenCookies,
|
|
7
|
+
setTokenCookies
|
|
8
|
+
} from "../../../chunk-AJLUPYCQ.js";
|
|
5
9
|
import "../../../chunk-AIH3F7JV.js";
|
|
6
10
|
import "../../../chunk-ORMEWXMH.js";
|
|
7
11
|
export {
|
|
8
12
|
JWTManager,
|
|
9
|
-
JWTService
|
|
13
|
+
JWTService,
|
|
14
|
+
clearTokenCookies,
|
|
15
|
+
setTokenCookies
|
|
10
16
|
};
|
package/dist/auth/index.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TokenGenerator
|
|
3
3
|
} from "../chunk-GDWEDUHO.js";
|
|
4
|
-
import {
|
|
5
|
-
JWTClientManager,
|
|
6
|
-
clearStoredTokens,
|
|
7
|
-
clearTokens,
|
|
8
|
-
createApiHeaders,
|
|
9
|
-
createAuthHeader,
|
|
10
|
-
decodeJWTPayload,
|
|
11
|
-
extractUserFromToken,
|
|
12
|
-
getStoredTokens,
|
|
13
|
-
getTokenExpirationString,
|
|
14
|
-
getTokenIssuedAtString,
|
|
15
|
-
getTokenRemainingTime,
|
|
16
|
-
isTokenExpired,
|
|
17
|
-
isTokenExpiringSoon,
|
|
18
|
-
storeTokens
|
|
19
|
-
} from "../chunk-XRRPEBKB.js";
|
|
20
4
|
import {
|
|
21
5
|
OAuthManager
|
|
22
6
|
} from "../chunk-V5K5FYU7.js";
|
|
@@ -35,6 +19,22 @@ import {
|
|
|
35
19
|
defaultPasswordSchema,
|
|
36
20
|
strongPasswordSchema
|
|
37
21
|
} from "../chunk-IHXRF3BH.js";
|
|
22
|
+
import {
|
|
23
|
+
JWTClientManager,
|
|
24
|
+
clearStoredTokens,
|
|
25
|
+
clearTokens,
|
|
26
|
+
createApiHeaders,
|
|
27
|
+
createAuthHeader,
|
|
28
|
+
decodeJWTPayload,
|
|
29
|
+
extractUserFromToken,
|
|
30
|
+
getStoredTokens,
|
|
31
|
+
getTokenExpirationString,
|
|
32
|
+
getTokenIssuedAtString,
|
|
33
|
+
getTokenRemainingTime,
|
|
34
|
+
isTokenExpired,
|
|
35
|
+
isTokenExpiringSoon,
|
|
36
|
+
storeTokens
|
|
37
|
+
} from "../chunk-XRRPEBKB.js";
|
|
38
38
|
import {
|
|
39
39
|
OAuthProvider,
|
|
40
40
|
PasswordStrength,
|
|
@@ -44,7 +44,8 @@ import {
|
|
|
44
44
|
import {
|
|
45
45
|
JWTManager,
|
|
46
46
|
JWTService
|
|
47
|
-
} from "../chunk-
|
|
47
|
+
} from "../chunk-3GAY2T2A.js";
|
|
48
|
+
import "../chunk-AJLUPYCQ.js";
|
|
48
49
|
import {
|
|
49
50
|
AUTH_ERROR_CODES,
|
|
50
51
|
AuthError,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AUTH_ERROR_CODE_MAP
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-L6AU74EI.js";
|
|
4
4
|
import {
|
|
5
5
|
AppError
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-EOEMOXNT.js";
|
|
7
7
|
import {
|
|
8
8
|
getErrorMessage
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-JNJALNRR.js";
|
|
10
10
|
import {
|
|
11
11
|
ERROR_CODES,
|
|
12
12
|
classifyError
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-SNTLJ646.js";
|
|
14
14
|
import {
|
|
15
15
|
AuthError
|
|
16
16
|
} from "./chunk-AIH3F7JV.js";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadValues
|
|
3
|
+
} from "./chunk-ORMEWXMH.js";
|
|
4
|
+
|
|
5
|
+
// src/auth/core/jwt/cookie.ts
|
|
6
|
+
var DEFAULT_OPTIONS = {
|
|
7
|
+
secure: process.env.NODE_ENV === "production",
|
|
8
|
+
sameSite: "lax"
|
|
9
|
+
};
|
|
10
|
+
function setTokenCookies(response, tokenPair, options = {}) {
|
|
11
|
+
const opts = __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options);
|
|
12
|
+
response.cookies.set("access_token", tokenPair.accessToken, {
|
|
13
|
+
httpOnly: true,
|
|
14
|
+
secure: opts.secure,
|
|
15
|
+
sameSite: opts.sameSite,
|
|
16
|
+
path: "/",
|
|
17
|
+
maxAge: 15 * 60
|
|
18
|
+
});
|
|
19
|
+
response.cookies.set("refresh_token", tokenPair.refreshToken, {
|
|
20
|
+
httpOnly: true,
|
|
21
|
+
secure: opts.secure,
|
|
22
|
+
sameSite: opts.sameSite,
|
|
23
|
+
path: "/api/auth",
|
|
24
|
+
maxAge: 7 * 24 * 60 * 60
|
|
25
|
+
});
|
|
26
|
+
return response;
|
|
27
|
+
}
|
|
28
|
+
function clearTokenCookies(response, options = {}) {
|
|
29
|
+
const opts = __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options);
|
|
30
|
+
response.cookies.set("access_token", "", {
|
|
31
|
+
httpOnly: true,
|
|
32
|
+
secure: opts.secure,
|
|
33
|
+
sameSite: opts.sameSite,
|
|
34
|
+
path: "/",
|
|
35
|
+
maxAge: 0
|
|
36
|
+
});
|
|
37
|
+
response.cookies.set("refresh_token", "", {
|
|
38
|
+
httpOnly: true,
|
|
39
|
+
secure: opts.secure,
|
|
40
|
+
sameSite: opts.sameSite,
|
|
41
|
+
path: "/api/auth",
|
|
42
|
+
maxAge: 0
|
|
43
|
+
});
|
|
44
|
+
return response;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
setTokenCookies,
|
|
49
|
+
clearTokenCookies
|
|
50
|
+
};
|
|
@@ -38,11 +38,6 @@ var enMessages = {
|
|
|
38
38
|
description: "8+ characters with letters, numbers, and symbols",
|
|
39
39
|
action: "Please set a more complex password."
|
|
40
40
|
},
|
|
41
|
-
40008: {
|
|
42
|
-
title: "Please check alias format",
|
|
43
|
-
description: "Only letters, numbers, and hyphens (-) allowed",
|
|
44
|
-
action: "Example: my-link-123"
|
|
45
|
-
},
|
|
46
41
|
// ============================================
|
|
47
42
|
// Authentication Errors (401xx)
|
|
48
43
|
// ============================================
|
|
@@ -61,16 +56,6 @@ var enMessages = {
|
|
|
61
56
|
description: "Your session has expired for security.",
|
|
62
57
|
action: "Please login again."
|
|
63
58
|
},
|
|
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
|
-
},
|
|
74
59
|
40106: {
|
|
75
60
|
title: "Login failed",
|
|
76
61
|
description: "Email or password is incorrect.",
|
|
@@ -116,23 +101,6 @@ var enMessages = {
|
|
|
116
101
|
title: "User not found",
|
|
117
102
|
description: "The user does not exist."
|
|
118
103
|
},
|
|
119
|
-
40403: {
|
|
120
|
-
title: "Link not found",
|
|
121
|
-
description: "The shortened link does not exist.",
|
|
122
|
-
action: "Please check the link address."
|
|
123
|
-
},
|
|
124
|
-
40408: {
|
|
125
|
-
title: "Tag not found",
|
|
126
|
-
description: "The tag does not exist."
|
|
127
|
-
},
|
|
128
|
-
40409: {
|
|
129
|
-
title: "Favorite not found",
|
|
130
|
-
description: "The item does not exist."
|
|
131
|
-
},
|
|
132
|
-
40410: {
|
|
133
|
-
title: "Group not found",
|
|
134
|
-
description: "The group does not exist."
|
|
135
|
-
},
|
|
136
104
|
// ============================================
|
|
137
105
|
// Conflict Errors (409xx)
|
|
138
106
|
// ============================================
|
|
@@ -151,11 +119,6 @@ var enMessages = {
|
|
|
151
119
|
description: "This email is already in use by another account.",
|
|
152
120
|
action: "Please use a different email."
|
|
153
121
|
},
|
|
154
|
-
40907: {
|
|
155
|
-
title: "Alias already in use",
|
|
156
|
-
description: "This alias is being used by another link.",
|
|
157
|
-
action: "Please enter a different alias."
|
|
158
|
-
},
|
|
159
122
|
// ============================================
|
|
160
123
|
// Business Logic Errors (422xx)
|
|
161
124
|
// ============================================
|
|
@@ -173,30 +136,6 @@ var enMessages = {
|
|
|
173
136
|
description: "You have exceeded the limit.",
|
|
174
137
|
action: "Please consider upgrading your plan."
|
|
175
138
|
},
|
|
176
|
-
42204: {
|
|
177
|
-
title: "Link expired",
|
|
178
|
-
description: "The validity period has passed.",
|
|
179
|
-
action: "Please create a new link."
|
|
180
|
-
},
|
|
181
|
-
42205: {
|
|
182
|
-
title: "Link disabled",
|
|
183
|
-
description: "Usage has been stopped.",
|
|
184
|
-
action: "Please contact the owner."
|
|
185
|
-
},
|
|
186
|
-
// 42206, 42207: moved to 401xx → see 40104, 40105 below
|
|
187
|
-
42208: {
|
|
188
|
-
title: "Alias not allowed",
|
|
189
|
-
description: "This is a system reserved word.",
|
|
190
|
-
action: "Please choose a different alias."
|
|
191
|
-
},
|
|
192
|
-
42209: {
|
|
193
|
-
title: "Already in favorites",
|
|
194
|
-
description: "Already added."
|
|
195
|
-
},
|
|
196
|
-
42210: {
|
|
197
|
-
title: "Cannot delete",
|
|
198
|
-
description: "Cannot delete your own admin account."
|
|
199
|
-
},
|
|
200
139
|
42211: {
|
|
201
140
|
title: "File too large",
|
|
202
141
|
description: "The maximum size has been exceeded.",
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AppError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EOEMOXNT.js";
|
|
4
4
|
import {
|
|
5
5
|
getErrorDisplayInfo,
|
|
6
6
|
getFriendlyMessage
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-7VTBRP5M.js";
|
|
8
8
|
import {
|
|
9
9
|
getErrorCategory
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-SNTLJ646.js";
|
|
11
11
|
|
|
12
12
|
// src/error/error-display.ts
|
|
13
13
|
import { toast } from "sonner";
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
formatErrorMessage,
|
|
5
5
|
getErrorCategory,
|
|
6
6
|
getHttpStatus
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-SNTLJ646.js";
|
|
8
8
|
|
|
9
9
|
// src/error/app-error.ts
|
|
10
10
|
var AppError = class _AppError extends Error {
|
|
@@ -149,11 +149,6 @@ var AppError = class _AppError extends Error {
|
|
|
149
149
|
static weakPassword() {
|
|
150
150
|
return _AppError.fromKey("PASSWORD_TOO_WEAK");
|
|
151
151
|
}
|
|
152
|
-
static invalidAlias(alias) {
|
|
153
|
-
return _AppError.fromKey("INVALID_ALIAS_FORMAT", void 0, {
|
|
154
|
-
value: alias
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
152
|
// ============================================
|
|
158
153
|
// 인증 에러 (401xx)
|
|
159
154
|
// ============================================
|
|
@@ -196,18 +191,6 @@ var AppError = class _AppError extends Error {
|
|
|
196
191
|
static userNotFound() {
|
|
197
192
|
return _AppError.fromKey("USER_NOT_FOUND");
|
|
198
193
|
}
|
|
199
|
-
static linkNotFound() {
|
|
200
|
-
return _AppError.fromKey("LINK_NOT_FOUND");
|
|
201
|
-
}
|
|
202
|
-
static tagNotFound() {
|
|
203
|
-
return _AppError.fromKey("TAG_NOT_FOUND");
|
|
204
|
-
}
|
|
205
|
-
static favoriteNotFound() {
|
|
206
|
-
return _AppError.fromKey("FAVORITE_NOT_FOUND");
|
|
207
|
-
}
|
|
208
|
-
static groupNotFound() {
|
|
209
|
-
return _AppError.fromKey("GROUP_NOT_FOUND");
|
|
210
|
-
}
|
|
211
194
|
// ============================================
|
|
212
195
|
// 충돌 에러 (409xx)
|
|
213
196
|
// ============================================
|
|
@@ -223,11 +206,6 @@ var AppError = class _AppError extends Error {
|
|
|
223
206
|
value: email
|
|
224
207
|
});
|
|
225
208
|
}
|
|
226
|
-
static aliasExists(alias) {
|
|
227
|
-
return _AppError.fromKey("ALIAS_ALREADY_EXISTS", void 0, {
|
|
228
|
-
value: alias
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
209
|
// ============================================
|
|
232
210
|
// 비즈니스 로직 에러 (422xx)
|
|
233
211
|
// ============================================
|
|
@@ -241,27 +219,6 @@ var AppError = class _AppError extends Error {
|
|
|
241
219
|
const message = quotaType ? `${quotaType} \uC0AC\uC6A9\uB7C9\uC744 \uCD08\uACFC\uD588\uC2B5\uB2C8\uB2E4.` : void 0;
|
|
242
220
|
return _AppError.fromKey("QUOTA_EXCEEDED", message);
|
|
243
221
|
}
|
|
244
|
-
static linkExpired() {
|
|
245
|
-
return _AppError.fromKey("LINK_EXPIRED");
|
|
246
|
-
}
|
|
247
|
-
static linkInactive() {
|
|
248
|
-
return _AppError.fromKey("LINK_INACTIVE");
|
|
249
|
-
}
|
|
250
|
-
static linkPasswordRequired() {
|
|
251
|
-
return _AppError.fromKey("LINK_PASSWORD_REQUIRED");
|
|
252
|
-
}
|
|
253
|
-
static linkPasswordIncorrect() {
|
|
254
|
-
return _AppError.fromKey("LINK_PASSWORD_INCORRECT");
|
|
255
|
-
}
|
|
256
|
-
static reservedWord(word) {
|
|
257
|
-
return _AppError.fromKey("RESERVED_WORD_USED", void 0, { value: word });
|
|
258
|
-
}
|
|
259
|
-
static alreadyFavorited() {
|
|
260
|
-
return _AppError.fromKey("ALREADY_FAVORITED");
|
|
261
|
-
}
|
|
262
|
-
static cannotDeleteOwnAccount() {
|
|
263
|
-
return _AppError.fromKey("CANNOT_DELETE_OWN_ACCOUNT");
|
|
264
|
-
}
|
|
265
222
|
static fileTooLarge(maxSize) {
|
|
266
223
|
const message = maxSize ? `\uD30C\uC77C \uD06C\uAE30\uAC00 ${maxSize}\uB97C \uCD08\uACFC\uD588\uC2B5\uB2C8\uB2E4.` : void 0;
|
|
267
224
|
return _AppError.fromKey("FILE_TOO_LARGE", message);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AppError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EOEMOXNT.js";
|
|
4
4
|
import {
|
|
5
5
|
ERROR_CODES
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-SNTLJ646.js";
|
|
7
7
|
import {
|
|
8
8
|
getAuthConfig
|
|
9
9
|
} from "./chunk-OZE5KUS3.js";
|
|
10
10
|
import {
|
|
11
11
|
JWTManager
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-3GAY2T2A.js";
|
|
13
13
|
import {
|
|
14
14
|
logger
|
|
15
15
|
} from "./chunk-GQVBWZLH.js";
|
|
@@ -72,7 +72,7 @@ function initializeAuthMiddleware() {
|
|
|
72
72
|
return jwtManager !== null;
|
|
73
73
|
}
|
|
74
74
|
var authMiddleware = async (context, next) => {
|
|
75
|
-
var _a, _b;
|
|
75
|
+
var _a, _b, _c, _d;
|
|
76
76
|
try {
|
|
77
77
|
const jwtManager = getJWTManager();
|
|
78
78
|
if (!jwtManager) {
|
|
@@ -84,8 +84,11 @@ var authMiddleware = async (context, next) => {
|
|
|
84
84
|
"Authentication not configured. Contact administrator."
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
let token = (_b = (_a = context.request.cookies.get("access_token")) == null ? void 0 : _a.value) != null ? _b : null;
|
|
88
|
+
if (!token) {
|
|
89
|
+
const authHeader = context.request.headers.get("authorization");
|
|
90
|
+
token = jwtManager.extractTokenFromHeader(authHeader);
|
|
91
|
+
}
|
|
89
92
|
if (!token) {
|
|
90
93
|
throw new AppError(ERROR_CODES.UNAUTHORIZED.code);
|
|
91
94
|
}
|
|
@@ -105,7 +108,7 @@ var authMiddleware = async (context, next) => {
|
|
|
105
108
|
const payload = await jwtManager.verifyAccessToken(token);
|
|
106
109
|
context.user = {
|
|
107
110
|
id: payload.userId,
|
|
108
|
-
email: (
|
|
111
|
+
email: (_c = payload.email) != null ? _c : "",
|
|
109
112
|
name: void 0,
|
|
110
113
|
// 필요시 DB에서 조회
|
|
111
114
|
role: payload.role === "ADMIN" ? "ADMIN" : "USER"
|
|
@@ -114,7 +117,7 @@ var authMiddleware = async (context, next) => {
|
|
|
114
117
|
if (error instanceof AppError) {
|
|
115
118
|
throw error;
|
|
116
119
|
}
|
|
117
|
-
if (error.code === "TOKEN_EXPIRED" || ((
|
|
120
|
+
if (error.code === "TOKEN_EXPIRED" || ((_d = error.message) == null ? void 0 : _d.includes("expired"))) {
|
|
118
121
|
throw new AppError(ERROR_CODES.TOKEN_EXPIRED.code, error.message);
|
|
119
122
|
}
|
|
120
123
|
throw new AppError(
|
|
@@ -125,12 +128,15 @@ var authMiddleware = async (context, next) => {
|
|
|
125
128
|
return await next();
|
|
126
129
|
};
|
|
127
130
|
var optionalAuthMiddleware = async (context, next) => {
|
|
128
|
-
var _a;
|
|
131
|
+
var _a, _b, _c;
|
|
129
132
|
try {
|
|
130
133
|
const jwtManager = getJWTManager();
|
|
131
134
|
if (jwtManager) {
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
let token = (_b = (_a = context.request.cookies.get("access_token")) == null ? void 0 : _a.value) != null ? _b : null;
|
|
136
|
+
if (!token) {
|
|
137
|
+
const authHeader = context.request.headers.get("authorization");
|
|
138
|
+
token = jwtManager.extractTokenFromHeader(authHeader);
|
|
139
|
+
}
|
|
134
140
|
if (token) {
|
|
135
141
|
const tokenChecker = getAccessTokenChecker();
|
|
136
142
|
let isRevoked = false;
|
|
@@ -141,7 +147,7 @@ var optionalAuthMiddleware = async (context, next) => {
|
|
|
141
147
|
const payload = await jwtManager.verifyAccessToken(token);
|
|
142
148
|
context.user = {
|
|
143
149
|
id: payload.userId,
|
|
144
|
-
email: (
|
|
150
|
+
email: (_c = payload.email) != null ? _c : "",
|
|
145
151
|
name: void 0,
|
|
146
152
|
role: payload.role === "ADMIN" ? "ADMIN" : "USER"
|
|
147
153
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AppError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-EOEMOXNT.js";
|
|
4
4
|
import {
|
|
5
5
|
ERROR_CODES,
|
|
6
6
|
classifyError,
|
|
7
7
|
formatErrorMessage,
|
|
8
8
|
getHttpStatus
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-SNTLJ646.js";
|
|
10
10
|
import {
|
|
11
11
|
AuthError
|
|
12
12
|
} from "./chunk-AIH3F7JV.js";
|
|
@@ -124,13 +124,10 @@ var ErrorResponse = {
|
|
|
124
124
|
invalidUrl: () => errorToResponse(AppError.invalidUrl()),
|
|
125
125
|
invalidEmail: () => errorToResponse(AppError.invalidEmail()),
|
|
126
126
|
weakPassword: () => errorToResponse(AppError.weakPassword()),
|
|
127
|
-
invalidAlias: () => errorToResponse(AppError.invalidAlias()),
|
|
128
127
|
// 401xx
|
|
129
128
|
unauthorized: (message) => errorToResponse(AppError.unauthorized(message)),
|
|
130
129
|
invalidToken: () => errorToResponse(AppError.invalidToken()),
|
|
131
130
|
tokenExpired: () => errorToResponse(AppError.tokenExpired()),
|
|
132
|
-
linkPasswordRequired: () => errorToResponse(AppError.linkPasswordRequired()),
|
|
133
|
-
linkPasswordIncorrect: () => errorToResponse(AppError.linkPasswordIncorrect()),
|
|
134
131
|
invalidCredentials: () => errorToResponse(AppError.invalidCredentials()),
|
|
135
132
|
sessionExpired: () => errorToResponse(AppError.sessionExpired()),
|
|
136
133
|
// 403xx
|
|
@@ -141,23 +138,14 @@ var ErrorResponse = {
|
|
|
141
138
|
// 404xx
|
|
142
139
|
notFound: (message) => errorToResponse(AppError.notFound(message)),
|
|
143
140
|
userNotFound: () => errorToResponse(AppError.userNotFound()),
|
|
144
|
-
linkNotFound: () => errorToResponse(AppError.linkNotFound()),
|
|
145
|
-
tagNotFound: () => errorToResponse(AppError.tagNotFound()),
|
|
146
|
-
favoriteNotFound: () => errorToResponse(AppError.favoriteNotFound()),
|
|
147
|
-
groupNotFound: () => errorToResponse(AppError.groupNotFound()),
|
|
148
141
|
// 409xx
|
|
149
142
|
conflict: (message) => errorToResponse(AppError.conflict(message)),
|
|
150
143
|
duplicate: (resource) => errorToResponse(AppError.duplicate(resource)),
|
|
151
144
|
emailExists: () => errorToResponse(AppError.emailExists()),
|
|
152
|
-
aliasExists: () => errorToResponse(AppError.aliasExists()),
|
|
153
145
|
// 422xx
|
|
154
146
|
businessRule: (message) => errorToResponse(AppError.businessRule(message)),
|
|
155
147
|
invalidOperation: (message) => errorToResponse(AppError.invalidOperation(message)),
|
|
156
|
-
linkExpired: () => errorToResponse(AppError.linkExpired()),
|
|
157
|
-
linkInactive: () => errorToResponse(AppError.linkInactive()),
|
|
158
|
-
reservedWord: () => errorToResponse(AppError.reservedWord()),
|
|
159
148
|
quotaExceeded: () => errorToResponse(AppError.quotaExceeded()),
|
|
160
|
-
alreadyFavorited: () => errorToResponse(AppError.alreadyFavorited()),
|
|
161
149
|
fileTooLarge: (maxSize) => errorToResponse(AppError.fileTooLarge(maxSize)),
|
|
162
150
|
unsupportedFileType: (fileType) => errorToResponse(AppError.unsupportedFileType(fileType)),
|
|
163
151
|
// 429xx
|
|
@@ -38,11 +38,6 @@ var koMessages = {
|
|
|
38
38
|
description: "8\uC790 \uC774\uC0C1, \uC601\uBB38/\uC22B\uC790/\uD2B9\uC218\uBB38\uC790 \uD3EC\uD568",
|
|
39
39
|
action: "\uB354 \uBCF5\uC7A1\uD55C \uBE44\uBC00\uBC88\uD638\uB97C \uC124\uC815\uD574 \uC8FC\uC138\uC694."
|
|
40
40
|
},
|
|
41
|
-
40008: {
|
|
42
|
-
title: "\uBCC4\uCE6D \uD615\uC2DD\uC744 \uD655\uC778\uD574 \uC8FC\uC138\uC694",
|
|
43
|
-
description: "\uC601\uBB38, \uC22B\uC790, \uD558\uC774\uD508(-)\uB9CC \uC0AC\uC6A9 \uAC00\uB2A5",
|
|
44
|
-
action: "\uC608: my-link-123"
|
|
45
|
-
},
|
|
46
41
|
// ============================================
|
|
47
42
|
// 인증 관련 (401xx)
|
|
48
43
|
// ============================================
|
|
@@ -61,16 +56,6 @@ var koMessages = {
|
|
|
61
56
|
description: "\uBCF4\uC548\uC744 \uC704\uD574 \uC138\uC158\uC774 \uB9CC\uB8CC\uB418\uC5C8\uC2B5\uB2C8\uB2E4.",
|
|
62
57
|
action: "\uB2E4\uC2DC \uB85C\uADF8\uC778\uD574 \uC8FC\uC138\uC694."
|
|
63
58
|
},
|
|
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
|
-
},
|
|
74
59
|
40106: {
|
|
75
60
|
title: "\uB85C\uADF8\uC778\uC5D0 \uC2E4\uD328\uD588\uC5B4\uC694",
|
|
76
61
|
description: "\uC774\uBA54\uC77C \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
|
|
@@ -116,23 +101,6 @@ var koMessages = {
|
|
|
116
101
|
title: "\uC0AC\uC6A9\uC790\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC5B4\uC694",
|
|
117
102
|
description: "\uD574\uB2F9 \uC0AC\uC6A9\uC790\uAC00 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
118
103
|
},
|
|
119
|
-
40403: {
|
|
120
|
-
title: "\uB9C1\uD06C\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC5B4\uC694",
|
|
121
|
-
description: "\uB2E8\uCD95 \uB9C1\uD06C\uAC00 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.",
|
|
122
|
-
action: "\uB9C1\uD06C \uC8FC\uC18C\uB97C \uD655\uC778\uD574 \uC8FC\uC138\uC694."
|
|
123
|
-
},
|
|
124
|
-
40408: {
|
|
125
|
-
title: "\uD0DC\uADF8\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC5B4\uC694",
|
|
126
|
-
description: "\uD0DC\uADF8\uAC00 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
127
|
-
},
|
|
128
|
-
40409: {
|
|
129
|
-
title: "\uC990\uACA8\uCC3E\uAE30\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC5B4\uC694",
|
|
130
|
-
description: "\uD56D\uBAA9\uC774 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
131
|
-
},
|
|
132
|
-
40410: {
|
|
133
|
-
title: "\uADF8\uB8F9\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC5B4\uC694",
|
|
134
|
-
description: "\uADF8\uB8F9\uC774 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
135
|
-
},
|
|
136
104
|
// ============================================
|
|
137
105
|
// 충돌 (409xx)
|
|
138
106
|
// ============================================
|
|
@@ -151,11 +119,6 @@ var koMessages = {
|
|
|
151
119
|
description: "\uB2E4\uB978 \uACC4\uC815\uC5D0\uC11C \uC0AC\uC6A9 \uC911\uC785\uB2C8\uB2E4.",
|
|
152
120
|
action: "\uB2E4\uB978 \uC774\uBA54\uC77C\uC744 \uC0AC\uC6A9\uD574 \uC8FC\uC138\uC694."
|
|
153
121
|
},
|
|
154
|
-
40907: {
|
|
155
|
-
title: "\uC774\uBBF8 \uC0AC\uC6A9 \uC911\uC778 \uBCC4\uCE6D\uC774\uC5D0\uC694",
|
|
156
|
-
description: "\uB2E4\uB978 \uB9C1\uD06C\uC5D0\uC11C \uC0AC\uC6A9 \uC911\uC785\uB2C8\uB2E4.",
|
|
157
|
-
action: "\uB2E4\uB978 \uBCC4\uCE6D\uC744 \uC785\uB825\uD574 \uC8FC\uC138\uC694."
|
|
158
|
-
},
|
|
159
122
|
// ============================================
|
|
160
123
|
// 비즈니스 로직 (422xx)
|
|
161
124
|
// ============================================
|
|
@@ -173,30 +136,6 @@ var koMessages = {
|
|
|
173
136
|
description: "\uD55C\uB3C4\uB97C \uCD08\uACFC\uD588\uC2B5\uB2C8\uB2E4.",
|
|
174
137
|
action: "\uD50C\uB79C \uC5C5\uADF8\uB808\uC774\uB4DC\uB97C \uACE0\uB824\uD574 \uC8FC\uC138\uC694."
|
|
175
138
|
},
|
|
176
|
-
42204: {
|
|
177
|
-
title: "\uB9CC\uB8CC\uB41C \uB9C1\uD06C\uC608\uC694",
|
|
178
|
-
description: "\uC720\uD6A8 \uAE30\uAC04\uC774 \uC9C0\uB0AC\uC2B5\uB2C8\uB2E4.",
|
|
179
|
-
action: "\uC0C8 \uB9C1\uD06C\uB97C \uC0DD\uC131\uD574 \uC8FC\uC138\uC694."
|
|
180
|
-
},
|
|
181
|
-
42205: {
|
|
182
|
-
title: "\uBE44\uD65C\uC131\uD654\uB41C \uB9C1\uD06C\uC608\uC694",
|
|
183
|
-
description: "\uC0AC\uC6A9\uC774 \uC911\uC9C0\uB418\uC5C8\uC2B5\uB2C8\uB2E4.",
|
|
184
|
-
action: "\uC18C\uC720\uC790\uC5D0\uAC8C \uBB38\uC758\uD574 \uC8FC\uC138\uC694."
|
|
185
|
-
},
|
|
186
|
-
// 42206, 42207: 401xx로 이동 → 아래 40104, 40105 참조
|
|
187
|
-
42208: {
|
|
188
|
-
title: "\uC0AC\uC6A9\uD560 \uC218 \uC5C6\uB294 \uBCC4\uCE6D\uC774\uC5D0\uC694",
|
|
189
|
-
description: "\uC2DC\uC2A4\uD15C \uC608\uC57D\uC5B4\uC785\uB2C8\uB2E4.",
|
|
190
|
-
action: "\uB2E4\uB978 \uBCC4\uCE6D\uC744 \uC120\uD0DD\uD574 \uC8FC\uC138\uC694."
|
|
191
|
-
},
|
|
192
|
-
42209: {
|
|
193
|
-
title: "\uC774\uBBF8 \uC990\uACA8\uCC3E\uAE30\uC5D0 \uC788\uC5B4\uC694",
|
|
194
|
-
description: "\uC774\uBBF8 \uCD94\uAC00\uB418\uC5B4 \uC788\uC2B5\uB2C8\uB2E4."
|
|
195
|
-
},
|
|
196
|
-
42210: {
|
|
197
|
-
title: "\uC0AD\uC81C\uD560 \uC218 \uC5C6\uC5B4\uC694",
|
|
198
|
-
description: "\uBCF8\uC778 \uAD00\uB9AC\uC790 \uACC4\uC815\uC740 \uC0AD\uC81C \uBD88\uAC00\uD569\uB2C8\uB2E4."
|
|
199
|
-
},
|
|
200
139
|
42211: {
|
|
201
140
|
title: "\uD30C\uC77C\uC774 \uB108\uBB34 \uCEE4\uC694",
|
|
202
141
|
description: "\uCD5C\uB300 \uD06C\uAE30\uB97C \uCD08\uACFC\uD588\uC2B5\uB2C8\uB2E4.",
|