dn-react-router-toolkit 0.1.12 → 0.2.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.
Files changed (183) hide show
  1. package/dist/auth/apple_auth.d.mts +38 -0
  2. package/dist/auth/apple_auth.d.ts +38 -0
  3. package/dist/{auth-kit → auth}/apple_auth.js +31 -18
  4. package/dist/auth/apple_auth.mjs +63 -0
  5. package/dist/{auth-kit/repository.d.mts → auth/auth_repository.d.mts} +6 -9
  6. package/dist/{auth-kit/repository.d.ts → auth/auth_repository.d.ts} +6 -9
  7. package/dist/{file-kit/repository.js → auth/auth_repository.js} +3 -3
  8. package/dist/{auth-kit → auth}/auth_service.d.mts +11 -22
  9. package/dist/{auth-kit → auth}/auth_service.d.ts +11 -22
  10. package/dist/{auth-kit → auth}/auth_service.js +23 -76
  11. package/dist/{auth-kit → auth}/auth_service.mjs +23 -76
  12. package/dist/auth/client/google_login_button.d.mts +7 -0
  13. package/dist/auth/client/google_login_button.d.ts +7 -0
  14. package/dist/{auth-kit → auth}/client/google_login_button.js +24 -19
  15. package/dist/auth/client/google_login_button.mjs +37 -0
  16. package/dist/auth/client/provider.d.mts +23 -0
  17. package/dist/auth/client/provider.d.ts +23 -0
  18. package/dist/auth/client/provider.js +137 -0
  19. package/dist/auth/client/provider.mjs +101 -0
  20. package/dist/{auth-kit → auth}/client/redirect_page.js +1 -1
  21. package/dist/{auth-kit → auth}/client/redirect_page.mjs +1 -1
  22. package/dist/auth/google_auth.d.mts +33 -0
  23. package/dist/auth/google_auth.d.ts +33 -0
  24. package/dist/{auth-kit → auth}/google_auth.js +23 -32
  25. package/dist/{auth-kit → auth}/google_auth.mjs +22 -31
  26. package/dist/auth/handlers/find_auth.d.mts +13 -0
  27. package/dist/auth/handlers/find_auth.d.ts +13 -0
  28. package/dist/{route/api/auth/route.js → auth/handlers/find_auth.js} +10 -10
  29. package/dist/{route/api/auth/route.mjs → auth/handlers/find_auth.mjs} +5 -5
  30. package/dist/auth/handlers/login.d.mts +13 -0
  31. package/dist/auth/handlers/login.d.ts +13 -0
  32. package/dist/{route/api/auth/login/route.js → auth/handlers/login.js} +17 -17
  33. package/dist/{route/api/auth/login/route.mjs → auth/handlers/login.mjs} +12 -12
  34. package/dist/auth/handlers/login_with_thirdparty.d.mts +15 -0
  35. package/dist/auth/handlers/login_with_thirdparty.d.ts +15 -0
  36. package/dist/{route/api/auth/login/[provider]/route.js → auth/handlers/login_with_thirdparty.js} +12 -27
  37. package/dist/{route/api/auth/login/[provider]/route.mjs → auth/handlers/login_with_thirdparty.mjs} +7 -22
  38. package/dist/auth/handlers/logout.d.mts +13 -0
  39. package/dist/auth/handlers/logout.d.ts +13 -0
  40. package/dist/{route/api/auth/logout/route.js → auth/handlers/logout.js} +15 -11
  41. package/dist/{route/api/auth/logout/route.mjs → auth/handlers/logout.mjs} +11 -7
  42. package/dist/auth/handlers/refresh.d.mts +13 -0
  43. package/dist/auth/handlers/refresh.d.ts +13 -0
  44. package/dist/{route/api/auth/refresh/route.js → auth/handlers/refresh.js} +12 -12
  45. package/dist/{route/api/auth/refresh/route.mjs → auth/handlers/refresh.mjs} +7 -7
  46. package/dist/auth/handlers/signup.d.mts +15 -0
  47. package/dist/auth/handlers/signup.d.ts +15 -0
  48. package/dist/auth/handlers/signup.js +135 -0
  49. package/dist/auth/handlers/signup.mjs +100 -0
  50. package/dist/auth/handlers/signup_with_thirdparty.d.mts +17 -0
  51. package/dist/auth/handlers/signup_with_thirdparty.d.ts +17 -0
  52. package/dist/auth/handlers/signup_with_thirdparty.js +123 -0
  53. package/dist/auth/handlers/signup_with_thirdparty.mjs +98 -0
  54. package/dist/auth/handlers/thirdparty_auth_callback.d.mts +16 -0
  55. package/dist/auth/handlers/thirdparty_auth_callback.d.ts +16 -0
  56. package/dist/{route/auth/callback/[provider]/route.js → auth/handlers/thirdparty_auth_callback.js} +54 -45
  57. package/dist/{route/auth/callback/[provider]/route.mjs → auth/handlers/thirdparty_auth_callback.mjs} +49 -40
  58. package/dist/{auth-kit/jwt.d.mts → auth/jwt_manager.d.mts} +11 -1
  59. package/dist/{auth-kit/jwt.d.ts → auth/jwt_manager.d.ts} +11 -1
  60. package/dist/{auth-kit/jwt.js → auth/jwt_manager.js} +25 -11
  61. package/dist/{auth-kit/jwt.mjs → auth/jwt_manager.mjs} +22 -8
  62. package/dist/auth/kakao_auth.d.mts +27 -0
  63. package/dist/auth/kakao_auth.d.ts +27 -0
  64. package/dist/auth/kakao_auth.js +56 -0
  65. package/dist/auth/kakao_auth.mjs +31 -0
  66. package/dist/auth/thirdparty_auth.d.mts +41 -0
  67. package/dist/auth/thirdparty_auth.d.ts +41 -0
  68. package/dist/{auth-kit/kakao_auth.js → auth/thirdparty_auth.js} +31 -33
  69. package/dist/{auth-kit/kakao_auth.mjs → auth/thirdparty_auth.mjs} +26 -28
  70. package/dist/{auth-kit → auth}/with_auth.d.mts +5 -6
  71. package/dist/{auth-kit → auth}/with_auth.d.ts +5 -6
  72. package/dist/{auth-kit → auth}/with_auth.js +26 -10
  73. package/dist/auth/with_auth.mjs +63 -0
  74. package/dist/date.d.mts +2 -0
  75. package/dist/date.d.ts +2 -0
  76. package/dist/date.js +4 -2
  77. package/dist/date.mjs +2 -1
  78. package/dist/{file-kit → file}/cdn.js +1 -1
  79. package/dist/{file-kit → file}/cdn.mjs +1 -1
  80. package/dist/{file-kit → file}/client/drop_file_input.js +3 -3
  81. package/dist/{file-kit → file}/client/drop_file_input.mjs +3 -3
  82. package/dist/{file-kit → file}/client/file_upload_button.js +1 -1
  83. package/dist/{file-kit → file}/client/file_upload_button.mjs +1 -1
  84. package/dist/{file-kit → file}/client/file_uploader.js +3 -3
  85. package/dist/{file-kit → file}/client/file_uploader.mjs +2 -2
  86. package/dist/{file-kit → file}/client/format_size.js +1 -1
  87. package/dist/{file-kit → file}/client/format_size.mjs +1 -1
  88. package/dist/{file-kit → file}/client/metadata.js +1 -1
  89. package/dist/{file-kit → file}/client/metadata.mjs +1 -1
  90. package/dist/{file-kit/repository.d.mts → file/file_repository.d.mts} +4 -4
  91. package/dist/{file-kit/repository.d.ts → file/file_repository.d.ts} +4 -4
  92. package/dist/{auth-kit/repository.js → file/file_repository.js} +3 -3
  93. package/dist/file/file_service.d.mts +32 -0
  94. package/dist/file/file_service.d.ts +32 -0
  95. package/dist/{file-kit → file}/file_service.js +27 -21
  96. package/dist/file/file_service.mjs +41 -0
  97. package/dist/file/handlers/delete_file.d.mts +17 -0
  98. package/dist/file/handlers/delete_file.d.ts +17 -0
  99. package/dist/{route/api/files/[fileId]/route.js → file/handlers/delete_file.js} +15 -15
  100. package/dist/{route/api/files/[fileId]/route.mjs → file/handlers/delete_file.mjs} +10 -10
  101. package/dist/file/handlers/upload_file.d.mts +16 -0
  102. package/dist/file/handlers/upload_file.d.ts +16 -0
  103. package/dist/{route/api/files/route.js → file/handlers/upload_file.js} +13 -13
  104. package/dist/{route/api/files/route.mjs → file/handlers/upload_file.mjs} +8 -8
  105. package/dist/{file-kit → file}/object_storage.d.mts +3 -1
  106. package/dist/{file-kit → file}/object_storage.d.ts +3 -1
  107. package/dist/{file-kit → file}/object_storage.js +2 -2
  108. package/dist/{file-kit → file}/object_storage.mjs +2 -2
  109. package/dist/{file-kit → file}/responsive_image.d.mts +4 -4
  110. package/dist/{file-kit → file}/responsive_image.d.ts +4 -4
  111. package/dist/{file-kit → file}/responsive_image.js +18 -9
  112. package/dist/{file-kit → file}/responsive_image.mjs +18 -9
  113. package/dist/{http-kit → http}/index.js +5 -5
  114. package/dist/{http-kit → http}/index.mjs +1 -1
  115. package/dist/{http-kit → http}/response.js +1 -1
  116. package/dist/{http-kit → http}/response.mjs +1 -1
  117. package/dist/index.d.mts +1 -0
  118. package/dist/index.d.ts +1 -0
  119. package/dist/index.js +2 -0
  120. package/dist/index.mjs +1 -0
  121. package/dist/route/api.d.mts +15 -25
  122. package/dist/route/api.d.ts +15 -25
  123. package/dist/route/api.js +325 -178
  124. package/dist/route/api.mjs +314 -177
  125. package/dist/{seo-kit → seo}/seo.js +1 -1
  126. package/dist/{seo-kit → seo}/seo.mjs +1 -1
  127. package/package.json +74 -74
  128. package/dist/auth-kit/apple_auth.d.mts +0 -24
  129. package/dist/auth-kit/apple_auth.d.ts +0 -24
  130. package/dist/auth-kit/apple_auth.mjs +0 -50
  131. package/dist/auth-kit/client/google_login_button.d.mts +0 -9
  132. package/dist/auth-kit/client/google_login_button.d.ts +0 -9
  133. package/dist/auth-kit/client/google_login_button.mjs +0 -32
  134. package/dist/auth-kit/client/logout.d.mts +0 -3
  135. package/dist/auth-kit/client/logout.d.ts +0 -3
  136. package/dist/auth-kit/client/logout.js +0 -49
  137. package/dist/auth-kit/client/logout.mjs +0 -24
  138. package/dist/auth-kit/google_auth.d.mts +0 -27
  139. package/dist/auth-kit/google_auth.d.ts +0 -27
  140. package/dist/auth-kit/kakao_auth.d.mts +0 -24
  141. package/dist/auth-kit/kakao_auth.d.ts +0 -24
  142. package/dist/auth-kit/with_auth.mjs +0 -47
  143. package/dist/file-kit/file_service.d.mts +0 -26
  144. package/dist/file-kit/file_service.d.ts +0 -26
  145. package/dist/file-kit/file_service.mjs +0 -35
  146. package/dist/route/api/auth/login/_provider_/route.d.mts +0 -20
  147. package/dist/route/api/auth/login/_provider_/route.d.ts +0 -20
  148. package/dist/route/api/auth/login/route.d.mts +0 -14
  149. package/dist/route/api/auth/login/route.d.ts +0 -14
  150. package/dist/route/api/auth/logout/route.d.mts +0 -14
  151. package/dist/route/api/auth/logout/route.d.ts +0 -14
  152. package/dist/route/api/auth/refresh/route.d.mts +0 -13
  153. package/dist/route/api/auth/refresh/route.d.ts +0 -13
  154. package/dist/route/api/auth/route.d.mts +0 -13
  155. package/dist/route/api/auth/route.d.ts +0 -13
  156. package/dist/route/api/files/_fileId_/route.d.mts +0 -17
  157. package/dist/route/api/files/_fileId_/route.d.ts +0 -17
  158. package/dist/route/api/files/route.d.mts +0 -16
  159. package/dist/route/api/files/route.d.ts +0 -16
  160. package/dist/route/auth/callback/_provider_/route.d.mts +0 -20
  161. package/dist/route/auth/callback/_provider_/route.d.ts +0 -20
  162. /package/dist/{auth-kit/repository.mjs → auth/auth_repository.mjs} +0 -0
  163. /package/dist/{auth-kit → auth}/client/redirect_page.d.mts +0 -0
  164. /package/dist/{auth-kit → auth}/client/redirect_page.d.ts +0 -0
  165. /package/dist/{file-kit → file}/cdn.d.mts +0 -0
  166. /package/dist/{file-kit → file}/cdn.d.ts +0 -0
  167. /package/dist/{file-kit → file}/client/drop_file_input.d.mts +0 -0
  168. /package/dist/{file-kit → file}/client/drop_file_input.d.ts +0 -0
  169. /package/dist/{file-kit → file}/client/file_upload_button.d.mts +0 -0
  170. /package/dist/{file-kit → file}/client/file_upload_button.d.ts +0 -0
  171. /package/dist/{file-kit → file}/client/file_uploader.d.mts +0 -0
  172. /package/dist/{file-kit → file}/client/file_uploader.d.ts +0 -0
  173. /package/dist/{file-kit → file}/client/format_size.d.mts +0 -0
  174. /package/dist/{file-kit → file}/client/format_size.d.ts +0 -0
  175. /package/dist/{file-kit → file}/client/metadata.d.mts +0 -0
  176. /package/dist/{file-kit → file}/client/metadata.d.ts +0 -0
  177. /package/dist/{file-kit/repository.mjs → file/file_repository.mjs} +0 -0
  178. /package/dist/{http-kit → http}/index.d.mts +0 -0
  179. /package/dist/{http-kit → http}/index.d.ts +0 -0
  180. /package/dist/{http-kit → http}/response.d.mts +0 -0
  181. /package/dist/{http-kit → http}/response.d.ts +0 -0
  182. /package/dist/{seo-kit → seo}/seo.d.mts +0 -0
  183. /package/dist/{seo-kit → seo}/seo.d.ts +0 -0
package/dist/route/api.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,16 +17,24 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/route/api.ts
21
31
  var api_exports = {};
22
32
  __export(api_exports, {
23
- createAuthAPIHandler: () => createAuthAPIHandler
33
+ createAPIHandler: () => createAPIHandler
24
34
  });
25
35
  module.exports = __toCommonJS(api_exports);
26
36
 
27
- // src/http-kit/response.ts
37
+ // src/http/response.ts
28
38
  var createJsonResponse = (status) => {
29
39
  return (data = {}, init) => {
30
40
  return Response.json(data, { status, ...init });
@@ -74,59 +84,68 @@ var INTERNAL_SERVER_ERROR = createException(
74
84
  "\uC608\uAE30\uCE58 \uBABB\uD55C \uC624\uB958\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4."
75
85
  );
76
86
 
77
- // src/route/auth/callback/[provider]/route.tsx
78
- var thirdPartyAuthCallbackHandler = async (request, {
79
- provider
80
- }, {
81
- AUTH,
82
- GOOGLE_AUTH,
83
- APPLE_AUTH,
84
- SITE_ORIGIN
87
+ // src/auth/handlers/thirdparty_auth_callback.tsx
88
+ var thirdpartyAuthCallbackHandler = async (request, {
89
+ provider,
90
+ authService,
91
+ getThirdPartyAuth
85
92
  }) => {
86
93
  const url = new URL(request.url);
87
94
  const code = url.searchParams.get("code");
88
95
  if (!code) {
89
96
  throw BAD_REQUEST("\uCF54\uB4DC\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
90
97
  }
91
- const getThirdPartyAuth = (provider2) => {
92
- switch (provider2) {
93
- case "google":
94
- return GOOGLE_AUTH;
95
- case "apple":
96
- return APPLE_AUTH;
97
- default:
98
- throw BAD_REQUEST("\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC778\uC99D \uC81C\uACF5\uC790\uC785\uB2C8\uB2E4.");
99
- }
100
- };
101
- const { accessToken, refreshToken } = await getThirdPartyAuth(
102
- provider
103
- ).signIn(code);
104
- const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
105
- AUTH.getAccessTokenSetCookie(accessToken),
106
- AUTH.getRefreshTokenSetCookie(refreshToken)
107
- ]);
108
- const headers = new Headers();
109
- headers.append("Set-Cookie", accessTokenSetCookie);
110
- headers.append("Set-Cookie", refreshTokenSetCookie);
111
- const redirectUrl = url.searchParams.get("state") || SITE_ORIGIN;
112
- return new Response("Temporary Redirect", {
113
- status: 307,
114
- headers: {
115
- ...headers,
116
- Location: new URL(
117
- `/r?redirectUrl=${encodeURIComponent(redirectUrl)}`,
118
- request.url
119
- ).toString()
98
+ try {
99
+ const { accessToken, refreshToken } = await getThirdPartyAuth(
100
+ provider
101
+ ).login(code);
102
+ const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
103
+ authService.getAccessTokenSetCookie(accessToken),
104
+ authService.getRefreshTokenSetCookie(refreshToken)
105
+ ]);
106
+ const headers = new Headers();
107
+ headers.append("Set-Cookie", accessTokenSetCookie);
108
+ headers.append("Set-Cookie", refreshTokenSetCookie);
109
+ const redirectUrl = url.searchParams.get("state") || "/";
110
+ return new Response("Temporary Redirect", {
111
+ status: 307,
112
+ headers: {
113
+ ...headers,
114
+ Location: new URL(
115
+ `/r?redirectUrl=${encodeURIComponent(redirectUrl)}`,
116
+ request.url
117
+ ).toString()
118
+ }
119
+ });
120
+ } catch (error) {
121
+ if (error instanceof Response) {
122
+ if (error.status == 404) {
123
+ const body = await error.json();
124
+ const token = body.token;
125
+ return new Response(
126
+ "Temporary Redirect",
127
+ {
128
+ status: 307,
129
+ headers: {
130
+ Location: new URL(
131
+ `/signup?token=${token}`,
132
+ request.url
133
+ ).toString()
134
+ }
135
+ }
136
+ );
137
+ }
120
138
  }
121
- });
139
+ throw error;
140
+ }
122
141
  };
123
142
 
124
- // src/route/api/files/route.ts
125
- var fileUploadHandler = async (request, {
126
- AUTH,
127
- FILE_SERVICE
143
+ // src/file/handlers/upload_file.ts
144
+ var uploadFileHandler = async (request, {
145
+ authService,
146
+ fileService
128
147
  }) => {
129
- const auth = await AUTH.verifyOrRefresh(request);
148
+ const auth = await authService.verifyOrRefresh(request);
130
149
  const { name, type, size, metadata } = await request.json();
131
150
  const headers = {
132
151
  "Access-Control-Allow-Origin": "*"
@@ -138,7 +157,7 @@ var fileUploadHandler = async (request, {
138
157
  return BAD_REQUEST("\uD30C\uC77C \uD0C0\uC785\uC774 \uD544\uC694\uD574\uC694.", { headers });
139
158
  }
140
159
  try {
141
- const result = await FILE_SERVICE.generateSignedUrl({
160
+ const result = await fileService.generateSignedUrl({
142
161
  userId: auth?.userId,
143
162
  name,
144
163
  type,
@@ -154,63 +173,48 @@ var fileUploadHandler = async (request, {
154
173
  }
155
174
  };
156
175
 
157
- // src/route/api/files/[fileId]/route.ts
158
- var fileDeleteHandler = async (request, { fileId }, {
159
- AUTH,
160
- repository
176
+ // src/file/handlers/delete_file.ts
177
+ var deleteFileHandler = async (request, { fileId }, {
178
+ authService,
179
+ fileRepository
161
180
  }) => {
162
- const auth = await AUTH.verifyOrRefresh(request);
163
- const file = await repository.findFileById(fileId);
181
+ const auth = await authService.verifyOrRefresh(request);
182
+ const file = await fileRepository.findFileById(fileId);
164
183
  const headers = {
165
184
  "Access-Control-Allow-Origin": "*"
166
185
  };
167
186
  if (!file) {
168
187
  return NOT_FOUND("\uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.", { headers });
169
188
  }
170
- if (!repository.hasPermission(file, auth?.userId)) {
189
+ if (!fileRepository.hasPermission(file, auth?.userId)) {
171
190
  return FORBIDDEN("\uD30C\uC77C\uC744 \uC0AD\uC81C\uD560 \uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.", { headers });
172
191
  }
173
- await repository.deleteFile(fileId);
192
+ await fileRepository.deleteFile(fileId);
174
193
  return NO_CONTENT({ headers });
175
194
  };
176
195
 
177
- // src/route/api/auth/route.ts
178
- var getAuthHandler = async (request, { AUTH }) => {
179
- const auth = await AUTH.verifyOrRefresh(request);
196
+ // src/auth/handlers/find_auth.ts
197
+ var findAuthHandler = async (request, { authService }) => {
198
+ const auth = await authService.verifyOrRefresh(request);
180
199
  if (!auth) {
181
200
  return UNAUTHORIZED();
182
201
  }
183
202
  return OK(auth);
184
203
  };
185
204
 
186
- // src/route/api/auth/login/[provider]/route.ts
187
- var loginThirdPartyHandler = async (request, {
188
- provider
189
- }, {
190
- GOOGLE_AUTH,
191
- APPLE_AUTH,
192
- KAKAO_AUTH
205
+ // src/auth/handlers/login_with_thirdparty.ts
206
+ var loginWithThirdPartyHandler = async (request, {
207
+ provider,
208
+ getThirdPartyAuth
193
209
  }) => {
194
210
  const { code } = await request.json();
195
211
  if (!code) {
196
212
  return BAD_REQUEST("\uCF54\uB4DC\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
197
213
  }
198
- const getThirdPartyAuth = (provider2) => {
199
- switch (provider2) {
200
- case "google":
201
- return GOOGLE_AUTH;
202
- case "apple":
203
- return APPLE_AUTH;
204
- case "kakao":
205
- return KAKAO_AUTH;
206
- default:
207
- throw BAD_REQUEST("\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC778\uC99D \uC81C\uACF5\uC790\uC785\uB2C8\uB2E4.");
208
- }
209
- };
210
214
  try {
211
215
  const { accessToken, refreshToken } = await getThirdPartyAuth(
212
216
  provider
213
- ).signIn(code);
217
+ ).login(code);
214
218
  return CREATED({
215
219
  accessToken,
216
220
  refreshToken
@@ -223,26 +227,26 @@ var loginThirdPartyHandler = async (request, {
223
227
  }
224
228
  };
225
229
 
226
- // src/route/api/auth/login/route.ts
227
- var loginCredentialHandler = async (request, {
228
- AUTH,
229
- JWT_MANAGER
230
+ // src/auth/handlers/login.ts
231
+ var loginHandler = async (request, {
232
+ authService
230
233
  }) => {
231
- const searchParams = new URL(request.url).searchParams;
232
234
  const { id, password } = await request.json();
233
235
  try {
234
- const { accessToken, refreshToken } = await AUTH.signIn({
236
+ const { accessToken, refreshToken } = await authService.signIn({
235
237
  id,
236
238
  password
237
239
  });
238
- if (searchParams.get("type") === "json") {
240
+ const searchParams = new URL(request.url).searchParams;
241
+ const type = searchParams.get("type");
242
+ if (type === "json") {
239
243
  return CREATED({ accessToken, refreshToken });
240
244
  }
241
245
  const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
242
- AUTH.getAccessTokenSetCookie(accessToken),
243
- AUTH.getRefreshTokenSetCookie(refreshToken)
246
+ authService.getAccessTokenSetCookie(accessToken),
247
+ authService.getRefreshTokenSetCookie(refreshToken)
244
248
  ]);
245
- const payload = JWT_MANAGER.decode(accessToken);
249
+ const payload = authService.jwtManager.decode(accessToken);
246
250
  const headers = new Headers();
247
251
  headers.append("Set-Cookie", accessTokenSetCookie);
248
252
  headers.append("Set-Cookie", refreshTokenSetCookie);
@@ -257,17 +261,21 @@ var loginCredentialHandler = async (request, {
257
261
  }
258
262
  };
259
263
 
260
- // src/route/api/auth/logout/route.ts
261
- var logoutHandler = async (request, { AUTH, repository }) => {
262
- const auth = await AUTH.verifyOrRefresh(request);
264
+ // src/auth/handlers/logout.ts
265
+ var logoutHandler = async (request, { authService }) => {
266
+ const auth = await authService.verifyOrRefresh(request);
263
267
  if (!auth) {
264
268
  return UNAUTHORIZED();
265
269
  }
266
- await repository.updateUserRefreshToken(auth.userId, null);
270
+ await authService.authRepository.updateUserRefreshToken(auth.userId, null);
271
+ const type = new URL(request.url).searchParams.get("type");
272
+ if (type === "json") {
273
+ return NO_CONTENT();
274
+ }
267
275
  const headers = new Headers();
268
276
  const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
269
- AUTH.getAccessTokenSetCookie(null),
270
- AUTH.getRefreshTokenSetCookie(null)
277
+ authService.getAccessTokenSetCookie(null),
278
+ authService.getRefreshTokenSetCookie(null)
271
279
  ]);
272
280
  headers.append("Set-Cookie", accessTokenSetCookie);
273
281
  headers.append("Set-Cookie", refreshTokenSetCookie);
@@ -276,16 +284,16 @@ var logoutHandler = async (request, { AUTH, repository }) => {
276
284
  });
277
285
  };
278
286
 
279
- // src/route/api/auth/refresh/route.ts
280
- var authRefreshHandler = async (request, {
281
- AUTH
287
+ // src/auth/handlers/refresh.ts
288
+ var refreshHandler = async (request, {
289
+ authService
282
290
  }) => {
283
- const refreshToken = request?.headers.get("Authorization")?.replace("Bearer ", "") || await AUTH.getRefreshTokenFromCookies(request);
291
+ const refreshToken = request?.headers.get("Authorization")?.replace("Bearer ", "") || await authService.getRefreshTokenFromCookies(request);
284
292
  if (!refreshToken) {
285
293
  return BAD_REQUEST();
286
294
  }
287
295
  try {
288
- const accessToken = await AUTH.refreshAccessToken(refreshToken);
296
+ const accessToken = await authService.refreshAccessToken(refreshToken);
289
297
  return CREATED({ accessToken });
290
298
  } catch (e) {
291
299
  if (e instanceof Error) {
@@ -295,101 +303,240 @@ var authRefreshHandler = async (request, {
295
303
  }
296
304
  };
297
305
 
298
- // src/route/api.ts
299
- var createAuthAPIHandler = ({
300
- AUTH,
301
- GOOGLE_AUTH,
302
- APPLE_AUTH,
303
- KAKAO_AUTH,
304
- JWT_MANAGER,
305
- FILE_SERVICE,
306
- SITE_ORIGIN,
307
- authRepository,
306
+ // src/auth/handlers/signup.ts
307
+ var import_uuid = require("uuid");
308
+ var bcrypt = __toESM(require("bcryptjs"));
309
+ var signupHandler = async (request, {
310
+ authService,
308
311
  fileRepository
309
312
  }) => {
310
- const handler = async ({
311
- request,
312
- params
313
- }) => {
313
+ const body = await request.json();
314
+ const {
315
+ email,
316
+ password,
317
+ passwordConfirm,
318
+ name,
319
+ profileImageId
320
+ } = body;
321
+ if (!email) {
322
+ return BAD_REQUEST("\uC774\uBA54\uC77C\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694.");
323
+ }
324
+ if (!password) {
325
+ return BAD_REQUEST("\uBE44\uBC00\uBC88\uD638\uB97C \uC785\uB825\uD574\uC8FC\uC138\uC694.");
326
+ }
327
+ if (!passwordConfirm) {
328
+ return BAD_REQUEST("\uBE44\uBC00\uBC88\uD638 \uD655\uC778\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694.");
329
+ }
330
+ if (!name) {
331
+ return BAD_REQUEST("\uC774\uB984\uC744 \uC785\uB825\uD574\uC8FC\uC138\uC694.");
332
+ }
333
+ const existing = await authService.authRepository.findCredentialById(email);
334
+ if (existing) {
335
+ return CONFLICT("\uC774\uBA54\uC77C\uC774 \uC774\uBBF8 \uC874\uC7AC\uD569\uB2C8\uB2E4.");
336
+ }
337
+ if (password !== passwordConfirm) {
338
+ return BAD_REQUEST("\uBE44\uBC00\uBC88\uD638\uAC00 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
339
+ }
340
+ const profileImage = profileImageId ? await fileRepository.findFileById(profileImageId) : void 0;
341
+ const userId = (0, import_uuid.v5)(email, import_uuid.v5.DNS);
342
+ const user = await authService.authRepository.createUser({
343
+ id: userId,
344
+ name,
345
+ role: "user",
346
+ email,
347
+ profileImage
348
+ });
349
+ await authService.authRepository.createCredential({
350
+ id: email,
351
+ userId,
352
+ password: bcrypt.hashSync(password, 10)
353
+ });
354
+ const { accessToken, refreshToken } = await authService.issueTokenPair(user);
355
+ return CREATED({ accessToken, refreshToken });
356
+ };
357
+
358
+ // src/auth/handlers/signup_with_thirdparty.ts
359
+ var import_uuid2 = require("uuid");
360
+ var signUpWithThirdpartyHandler = async (request, {
361
+ authService,
362
+ fileService,
363
+ signupTokenSecret
364
+ }) => {
365
+ const body = await request.json();
366
+ const {
367
+ token
368
+ } = body;
369
+ const payload = await authService.jwtManager.verify(token, signupTokenSecret);
370
+ const { provider, id: thirdpartyId, email, name, picture } = payload;
371
+ const existing = await authService.authRepository.findThirdPartyAuth(
372
+ provider,
373
+ thirdpartyId
374
+ );
375
+ if (existing) {
376
+ return CONFLICT("\uC774\uBBF8 \uAC00\uC785\uB41C \uC81C3\uC790 \uC778\uC99D \uC815\uBCF4\uC785\uB2C8\uB2E4.");
377
+ }
378
+ const userId = (0, import_uuid2.v5)(thirdpartyId, import_uuid2.v5.DNS);
379
+ const profileImage = await (async () => {
380
+ if (!picture) {
381
+ return;
382
+ }
383
+ const arrayBuffer = await fetch(picture).then((res) => res.arrayBuffer());
384
+ const { file } = await fileService.putFile(Buffer.from(arrayBuffer), {
385
+ userId,
386
+ name: "profile.jpg",
387
+ type: "image/jpeg",
388
+ size: arrayBuffer.byteLength
389
+ });
390
+ return file;
391
+ })();
392
+ const user = await authService.authRepository.createUser({
393
+ id: userId,
394
+ name,
395
+ role: "user",
396
+ email,
397
+ profileImage
398
+ });
399
+ await authService.authRepository.createThirdPartyAuth({
400
+ id: thirdpartyId,
401
+ provider,
402
+ userId
403
+ });
404
+ const { accessToken, refreshToken } = await authService.issueTokenPair(user);
405
+ return CREATED({ accessToken, refreshToken });
406
+ };
407
+
408
+ // src/route/api.ts
409
+ var createAPIHandler = ({
410
+ authService,
411
+ fileService,
412
+ getThirdPartyAuth,
413
+ signupTokenSecret
414
+ }) => {
415
+ const handler = async ({ request, params }) => {
314
416
  const method = request.method.toUpperCase();
315
- const slug = params["*"].split("/");
316
- if (slug[0] === "auth") {
317
- if (!slug[1]) {
318
- if (method === "GET") {
319
- return getAuthHandler(request, { AUTH });
320
- }
321
- }
322
- if (slug[1] === "login") {
323
- if (slug[2]) {
324
- const provider = slug[2];
325
- if (method === "POST") {
326
- return loginThirdPartyHandler(
327
- request,
328
- { provider },
329
- { GOOGLE_AUTH, KAKAO_AUTH, APPLE_AUTH }
330
- );
417
+ const slug = params["*"] ? params["*"].split("/") : [];
418
+ switch (slug[0]) {
419
+ case "auth": {
420
+ switch (slug[1]) {
421
+ case void 0: {
422
+ switch (method) {
423
+ case "GET": {
424
+ return findAuthHandler(request, { authService });
425
+ }
426
+ }
331
427
  }
332
- }
333
- if (method === "POST") {
334
- return loginCredentialHandler(request, {
335
- AUTH,
336
- JWT_MANAGER
337
- });
338
- }
339
- }
340
- if (slug[1] === "logout") {
341
- if (method === "POST") {
342
- return logoutHandler(request, {
343
- AUTH,
344
- repository: authRepository
345
- });
346
- }
347
- }
348
- if (slug[1] === "refresh") {
349
- if (method === "GET") {
350
- return authRefreshHandler(request, { AUTH });
351
- }
352
- }
353
- if (slug[1] === "callback") {
354
- if (slug[2]) {
355
- const provider = slug[2];
356
- if (method === "GET") {
357
- return thirdPartyAuthCallbackHandler(
358
- request,
359
- { provider },
360
- {
361
- AUTH,
362
- GOOGLE_AUTH,
363
- APPLE_AUTH,
364
- SITE_ORIGIN
428
+ case "login": {
429
+ switch (slug[2]) {
430
+ case void 0: {
431
+ switch (method) {
432
+ case "POST": {
433
+ return loginHandler(request, {
434
+ authService
435
+ });
436
+ }
437
+ }
438
+ }
439
+ default: {
440
+ const provider = slug[2];
441
+ switch (method) {
442
+ case "POST": {
443
+ return loginWithThirdPartyHandler(
444
+ request,
445
+ { provider, getThirdPartyAuth }
446
+ );
447
+ }
448
+ }
449
+ }
450
+ }
451
+ }
452
+ case "logout": {
453
+ switch (method) {
454
+ case "POST": {
455
+ return logoutHandler(request, {
456
+ authService
457
+ });
458
+ }
459
+ }
460
+ }
461
+ case "refresh": {
462
+ switch (method) {
463
+ case "GET": {
464
+ return refreshHandler(request, { authService });
465
+ }
466
+ }
467
+ }
468
+ case "signup": {
469
+ switch (slug[2]) {
470
+ case void 0: {
471
+ switch (method) {
472
+ case "POST": {
473
+ return signupHandler(request, {
474
+ authService,
475
+ fileRepository: fileService.fileRepository
476
+ });
477
+ }
478
+ }
365
479
  }
366
- );
480
+ default: {
481
+ switch (method) {
482
+ case "POST": {
483
+ return signUpWithThirdpartyHandler(
484
+ request,
485
+ { authService, fileService, signupTokenSecret }
486
+ );
487
+ }
488
+ }
489
+ }
490
+ }
491
+ }
492
+ case "callback": {
493
+ if (slug[2]) {
494
+ const provider = slug[2];
495
+ if (method === "GET") {
496
+ return thirdpartyAuthCallbackHandler(
497
+ request,
498
+ {
499
+ provider,
500
+ authService,
501
+ getThirdPartyAuth
502
+ }
503
+ );
504
+ }
505
+ }
367
506
  }
368
507
  }
369
508
  }
370
- }
371
- if (slug[0] === "files") {
372
- if (!slug[1]) {
373
- if (method === "POST") {
374
- return fileUploadHandler(request, { AUTH, FILE_SERVICE });
509
+ case "files": {
510
+ switch (slug[1]) {
511
+ case void 0: {
512
+ switch (method) {
513
+ case "POST": {
514
+ return uploadFileHandler(request, { authService, fileService });
515
+ }
516
+ }
517
+ }
518
+ default: {
519
+ switch (method) {
520
+ case "DELETE": {
521
+ const fileId = slug[1];
522
+ return deleteFileHandler(
523
+ request,
524
+ { fileId },
525
+ { authService, fileRepository: fileService.fileRepository }
526
+ );
527
+ }
528
+ }
529
+ }
375
530
  }
376
531
  }
377
- if (slug[1]) {
378
- if (method === "DELETE") {
379
- const fileId = slug[1];
380
- return fileDeleteHandler(
381
- request,
382
- { fileId },
383
- { AUTH, repository: fileRepository }
384
- );
385
- }
532
+ default: {
533
+ return NOT_FOUND();
386
534
  }
387
535
  }
388
- return new Response("Not Found", { status: 404 });
389
536
  };
390
537
  return handler;
391
538
  };
392
539
  // Annotate the CommonJS export names for ESM import in node:
393
540
  0 && (module.exports = {
394
- createAuthAPIHandler
541
+ createAPIHandler
395
542
  });