dn-react-router-toolkit 0.1.12 → 0.2.1

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 (195) 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} +10 -11
  6. package/dist/{auth-kit/repository.d.ts → auth/auth_repository.d.ts} +10 -11
  7. package/dist/{file-kit/repository.js → auth/auth_repository.js} +3 -3
  8. package/dist/{auth-kit → auth}/auth_service.d.mts +12 -23
  9. package/dist/{auth-kit → auth}/auth_service.d.ts +12 -23
  10. package/dist/{auth-kit → auth}/auth_service.js +24 -77
  11. package/dist/{auth-kit → auth}/auth_service.mjs +24 -77
  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 +26 -0
  17. package/dist/auth/client/provider.d.ts +26 -0
  18. package/dist/auth/client/provider.js +152 -0
  19. package/dist/auth/client/provider.mjs +116 -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/request_password_reset.d.mts +10 -0
  47. package/dist/auth/handlers/request_password_reset.d.ts +10 -0
  48. package/dist/auth/handlers/request_password_reset.js +87 -0
  49. package/dist/auth/handlers/request_password_reset.mjs +60 -0
  50. package/dist/auth/handlers/reset_password.d.mts +10 -0
  51. package/dist/auth/handlers/reset_password.d.ts +10 -0
  52. package/dist/auth/handlers/reset_password.js +88 -0
  53. package/dist/auth/handlers/reset_password.mjs +61 -0
  54. package/dist/auth/handlers/signup.d.mts +15 -0
  55. package/dist/auth/handlers/signup.d.ts +15 -0
  56. package/dist/auth/handlers/signup.js +147 -0
  57. package/dist/auth/handlers/signup.mjs +112 -0
  58. package/dist/auth/handlers/signup_with_thirdparty.d.mts +17 -0
  59. package/dist/auth/handlers/signup_with_thirdparty.d.ts +17 -0
  60. package/dist/auth/handlers/signup_with_thirdparty.js +123 -0
  61. package/dist/auth/handlers/signup_with_thirdparty.mjs +98 -0
  62. package/dist/auth/handlers/thirdparty_auth_callback.d.mts +16 -0
  63. package/dist/auth/handlers/thirdparty_auth_callback.d.ts +16 -0
  64. package/dist/{route/auth/callback/[provider]/route.js → auth/handlers/thirdparty_auth_callback.js} +54 -45
  65. package/dist/{route/auth/callback/[provider]/route.mjs → auth/handlers/thirdparty_auth_callback.mjs} +49 -40
  66. package/dist/{auth-kit/jwt.d.mts → auth/jwt_manager.d.mts} +11 -1
  67. package/dist/{auth-kit/jwt.d.ts → auth/jwt_manager.d.ts} +11 -1
  68. package/dist/{auth-kit/jwt.js → auth/jwt_manager.js} +25 -11
  69. package/dist/{auth-kit/jwt.mjs → auth/jwt_manager.mjs} +22 -8
  70. package/dist/auth/kakao_auth.d.mts +27 -0
  71. package/dist/auth/kakao_auth.d.ts +27 -0
  72. package/dist/auth/kakao_auth.js +56 -0
  73. package/dist/auth/kakao_auth.mjs +31 -0
  74. package/dist/auth/password_recovery.d.mts +34 -0
  75. package/dist/auth/password_recovery.d.ts +34 -0
  76. package/dist/auth/password_recovery.js +169 -0
  77. package/dist/auth/password_recovery.mjs +134 -0
  78. package/dist/auth/thirdparty_auth.d.mts +41 -0
  79. package/dist/auth/thirdparty_auth.d.ts +41 -0
  80. package/dist/{auth-kit/kakao_auth.js → auth/thirdparty_auth.js} +31 -33
  81. package/dist/{auth-kit/kakao_auth.mjs → auth/thirdparty_auth.mjs} +26 -28
  82. package/dist/{auth-kit → auth}/with_auth.d.mts +5 -6
  83. package/dist/{auth-kit → auth}/with_auth.d.ts +5 -6
  84. package/dist/{auth-kit → auth}/with_auth.js +26 -10
  85. package/dist/auth/with_auth.mjs +63 -0
  86. package/dist/date.d.mts +2 -0
  87. package/dist/date.d.ts +2 -0
  88. package/dist/date.js +4 -2
  89. package/dist/date.mjs +2 -1
  90. package/dist/{file-kit → file}/cdn.js +1 -1
  91. package/dist/{file-kit → file}/cdn.mjs +1 -1
  92. package/dist/{file-kit → file}/client/drop_file_input.js +3 -3
  93. package/dist/{file-kit → file}/client/drop_file_input.mjs +3 -3
  94. package/dist/{file-kit → file}/client/file_upload_button.js +1 -1
  95. package/dist/{file-kit → file}/client/file_upload_button.mjs +1 -1
  96. package/dist/{file-kit → file}/client/file_uploader.js +3 -3
  97. package/dist/{file-kit → file}/client/file_uploader.mjs +2 -2
  98. package/dist/{file-kit → file}/client/format_size.js +1 -1
  99. package/dist/{file-kit → file}/client/format_size.mjs +1 -1
  100. package/dist/{file-kit → file}/client/metadata.js +1 -1
  101. package/dist/{file-kit → file}/client/metadata.mjs +1 -1
  102. package/dist/{file-kit/repository.d.mts → file/file_repository.d.mts} +4 -4
  103. package/dist/{file-kit/repository.d.ts → file/file_repository.d.ts} +4 -4
  104. package/dist/{auth-kit/repository.js → file/file_repository.js} +3 -3
  105. package/dist/file/file_service.d.mts +32 -0
  106. package/dist/file/file_service.d.ts +32 -0
  107. package/dist/{file-kit → file}/file_service.js +27 -21
  108. package/dist/file/file_service.mjs +41 -0
  109. package/dist/file/handlers/delete_file.d.mts +17 -0
  110. package/dist/file/handlers/delete_file.d.ts +17 -0
  111. package/dist/{route/api/files/[fileId]/route.js → file/handlers/delete_file.js} +15 -15
  112. package/dist/{route/api/files/[fileId]/route.mjs → file/handlers/delete_file.mjs} +10 -10
  113. package/dist/file/handlers/upload_file.d.mts +16 -0
  114. package/dist/file/handlers/upload_file.d.ts +16 -0
  115. package/dist/{route/api/files/route.js → file/handlers/upload_file.js} +13 -13
  116. package/dist/{route/api/files/route.mjs → file/handlers/upload_file.mjs} +8 -8
  117. package/dist/{file-kit → file}/object_storage.d.mts +3 -1
  118. package/dist/{file-kit → file}/object_storage.d.ts +3 -1
  119. package/dist/{file-kit → file}/object_storage.js +2 -2
  120. package/dist/{file-kit → file}/object_storage.mjs +2 -2
  121. package/dist/{file-kit → file}/responsive_image.d.mts +4 -4
  122. package/dist/{file-kit → file}/responsive_image.d.ts +4 -4
  123. package/dist/{file-kit → file}/responsive_image.js +18 -9
  124. package/dist/{file-kit → file}/responsive_image.mjs +18 -9
  125. package/dist/{http-kit → http}/index.js +5 -5
  126. package/dist/{http-kit → http}/index.mjs +1 -1
  127. package/dist/{http-kit → http}/response.js +1 -1
  128. package/dist/{http-kit → http}/response.mjs +1 -1
  129. package/dist/index.d.mts +1 -0
  130. package/dist/index.d.ts +1 -0
  131. package/dist/index.js +2 -0
  132. package/dist/index.mjs +1 -0
  133. package/dist/route/api.d.mts +17 -25
  134. package/dist/route/api.d.ts +17 -25
  135. package/dist/route/api.js +367 -178
  136. package/dist/route/api.mjs +356 -177
  137. package/dist/{seo-kit → seo}/seo.js +1 -1
  138. package/dist/{seo-kit → seo}/seo.mjs +1 -1
  139. package/package.json +76 -74
  140. package/dist/auth-kit/apple_auth.d.mts +0 -24
  141. package/dist/auth-kit/apple_auth.d.ts +0 -24
  142. package/dist/auth-kit/apple_auth.mjs +0 -50
  143. package/dist/auth-kit/client/google_login_button.d.mts +0 -9
  144. package/dist/auth-kit/client/google_login_button.d.ts +0 -9
  145. package/dist/auth-kit/client/google_login_button.mjs +0 -32
  146. package/dist/auth-kit/client/logout.d.mts +0 -3
  147. package/dist/auth-kit/client/logout.d.ts +0 -3
  148. package/dist/auth-kit/client/logout.js +0 -49
  149. package/dist/auth-kit/client/logout.mjs +0 -24
  150. package/dist/auth-kit/google_auth.d.mts +0 -27
  151. package/dist/auth-kit/google_auth.d.ts +0 -27
  152. package/dist/auth-kit/kakao_auth.d.mts +0 -24
  153. package/dist/auth-kit/kakao_auth.d.ts +0 -24
  154. package/dist/auth-kit/with_auth.mjs +0 -47
  155. package/dist/file-kit/file_service.d.mts +0 -26
  156. package/dist/file-kit/file_service.d.ts +0 -26
  157. package/dist/file-kit/file_service.mjs +0 -35
  158. package/dist/route/api/auth/login/_provider_/route.d.mts +0 -20
  159. package/dist/route/api/auth/login/_provider_/route.d.ts +0 -20
  160. package/dist/route/api/auth/login/route.d.mts +0 -14
  161. package/dist/route/api/auth/login/route.d.ts +0 -14
  162. package/dist/route/api/auth/logout/route.d.mts +0 -14
  163. package/dist/route/api/auth/logout/route.d.ts +0 -14
  164. package/dist/route/api/auth/refresh/route.d.mts +0 -13
  165. package/dist/route/api/auth/refresh/route.d.ts +0 -13
  166. package/dist/route/api/auth/route.d.mts +0 -13
  167. package/dist/route/api/auth/route.d.ts +0 -13
  168. package/dist/route/api/files/_fileId_/route.d.mts +0 -17
  169. package/dist/route/api/files/_fileId_/route.d.ts +0 -17
  170. package/dist/route/api/files/route.d.mts +0 -16
  171. package/dist/route/api/files/route.d.ts +0 -16
  172. package/dist/route/auth/callback/_provider_/route.d.mts +0 -20
  173. package/dist/route/auth/callback/_provider_/route.d.ts +0 -20
  174. /package/dist/{auth-kit/repository.mjs → auth/auth_repository.mjs} +0 -0
  175. /package/dist/{auth-kit → auth}/client/redirect_page.d.mts +0 -0
  176. /package/dist/{auth-kit → auth}/client/redirect_page.d.ts +0 -0
  177. /package/dist/{file-kit → file}/cdn.d.mts +0 -0
  178. /package/dist/{file-kit → file}/cdn.d.ts +0 -0
  179. /package/dist/{file-kit → file}/client/drop_file_input.d.mts +0 -0
  180. /package/dist/{file-kit → file}/client/drop_file_input.d.ts +0 -0
  181. /package/dist/{file-kit → file}/client/file_upload_button.d.mts +0 -0
  182. /package/dist/{file-kit → file}/client/file_upload_button.d.ts +0 -0
  183. /package/dist/{file-kit → file}/client/file_uploader.d.mts +0 -0
  184. /package/dist/{file-kit → file}/client/file_uploader.d.ts +0 -0
  185. /package/dist/{file-kit → file}/client/format_size.d.mts +0 -0
  186. /package/dist/{file-kit → file}/client/format_size.d.ts +0 -0
  187. /package/dist/{file-kit → file}/client/metadata.d.mts +0 -0
  188. /package/dist/{file-kit → file}/client/metadata.d.ts +0 -0
  189. /package/dist/{file-kit/repository.mjs → file/file_repository.mjs} +0 -0
  190. /package/dist/{http-kit → http}/index.d.mts +0 -0
  191. /package/dist/{http-kit → http}/index.d.ts +0 -0
  192. /package/dist/{http-kit → http}/response.d.mts +0 -0
  193. /package/dist/{http-kit → http}/response.d.ts +0 -0
  194. /package/dist/{seo-kit → seo}/seo.d.mts +0 -0
  195. /package/dist/{seo-kit → seo}/seo.d.ts +0 -0
@@ -1,4 +1,4 @@
1
- // src/http-kit/response.ts
1
+ // src/http/response.ts
2
2
  var createJsonResponse = (status) => {
3
3
  return (data = {}, init) => {
4
4
  return Response.json(data, { status, ...init });
@@ -42,52 +42,61 @@ var INTERNAL_SERVER_ERROR = createException(
42
42
  "\uC608\uAE30\uCE58 \uBABB\uD55C \uC624\uB958\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4."
43
43
  );
44
44
 
45
- // src/route/auth/callback/[provider]/route.tsx
46
- var thirdPartyAuthCallbackHandler = async (request, {
47
- provider
48
- }, {
49
- AUTH,
50
- GOOGLE_AUTH,
51
- APPLE_AUTH,
52
- SITE_ORIGIN
45
+ // src/auth/handlers/thirdparty_auth_callback.tsx
46
+ var thirdpartyAuthCallbackHandler = async (request, {
47
+ provider,
48
+ authService,
49
+ getThirdPartyAuth
53
50
  }) => {
54
51
  const url = new URL(request.url);
55
52
  const code = url.searchParams.get("code");
56
53
  if (!code) {
57
54
  throw BAD_REQUEST("\uCF54\uB4DC\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
58
55
  }
59
- const getThirdPartyAuth = (provider2) => {
60
- switch (provider2) {
61
- case "google":
62
- return GOOGLE_AUTH;
63
- case "apple":
64
- return APPLE_AUTH;
65
- default:
66
- throw BAD_REQUEST("\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC778\uC99D \uC81C\uACF5\uC790\uC785\uB2C8\uB2E4.");
56
+ try {
57
+ const { accessToken, refreshToken } = await getThirdPartyAuth(
58
+ provider
59
+ ).login(code);
60
+ const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
61
+ authService.getAccessTokenSetCookie(accessToken),
62
+ authService.getRefreshTokenSetCookie(refreshToken)
63
+ ]);
64
+ const headers = new Headers();
65
+ headers.append("Set-Cookie", accessTokenSetCookie);
66
+ headers.append("Set-Cookie", refreshTokenSetCookie);
67
+ const redirectUrl = url.searchParams.get("state") || "/";
68
+ return new Response("Temporary Redirect", {
69
+ status: 307,
70
+ headers: {
71
+ ...headers,
72
+ Location: new URL(
73
+ `/r?redirectUrl=${encodeURIComponent(redirectUrl)}`,
74
+ request.url
75
+ ).toString()
76
+ }
77
+ });
78
+ } catch (error) {
79
+ if (error instanceof Response) {
80
+ if (error.status == 404) {
81
+ const body = await error.json();
82
+ const token = body.token;
83
+ return new Response(
84
+ "Temporary Redirect",
85
+ {
86
+ status: 307,
87
+ headers: {
88
+ Location: new URL(
89
+ `/signup?token=${token}`,
90
+ request.url
91
+ ).toString()
92
+ }
93
+ }
94
+ );
95
+ }
67
96
  }
68
- };
69
- const { accessToken, refreshToken } = await getThirdPartyAuth(
70
- provider
71
- ).signIn(code);
72
- const [accessTokenSetCookie, refreshTokenSetCookie] = await Promise.all([
73
- AUTH.getAccessTokenSetCookie(accessToken),
74
- AUTH.getRefreshTokenSetCookie(refreshToken)
75
- ]);
76
- const headers = new Headers();
77
- headers.append("Set-Cookie", accessTokenSetCookie);
78
- headers.append("Set-Cookie", refreshTokenSetCookie);
79
- const redirectUrl = url.searchParams.get("state") || SITE_ORIGIN;
80
- return new Response("Temporary Redirect", {
81
- status: 307,
82
- headers: {
83
- ...headers,
84
- Location: new URL(
85
- `/r?redirectUrl=${encodeURIComponent(redirectUrl)}`,
86
- request.url
87
- ).toString()
88
- }
89
- });
97
+ throw error;
98
+ }
90
99
  };
91
100
  export {
92
- thirdPartyAuthCallbackHandler
101
+ thirdpartyAuthCallbackHandler
93
102
  };
@@ -2,7 +2,17 @@ import { JWTPayload } from 'jose';
2
2
 
3
3
  declare class JWTManager {
4
4
  siteOrigin?: string;
5
- constructor(siteOrigin?: string);
5
+ accessTokenSecret: string;
6
+ accessTokenExpiresIn: string;
7
+ refreshTokenSecret: string;
8
+ refreshTokenExpiresIn: string;
9
+ constructor({ siteOrigin, accessTokenSecret, accessTokenExpiresIn, refreshTokenSecret, refreshTokenExpiresIn, }: {
10
+ siteOrigin?: string;
11
+ accessTokenSecret: string;
12
+ accessTokenExpiresIn?: string;
13
+ refreshTokenSecret: string;
14
+ refreshTokenExpiresIn?: string;
15
+ });
6
16
  verify(token: string, secret: string): Promise<JWTPayload | undefined>;
7
17
  verifyAccessToken(token: string): Promise<JWTPayload | undefined>;
8
18
  verifyRefreshToken(token: string): Promise<JWTPayload | undefined>;
@@ -2,7 +2,17 @@ import { JWTPayload } from 'jose';
2
2
 
3
3
  declare class JWTManager {
4
4
  siteOrigin?: string;
5
- constructor(siteOrigin?: string);
5
+ accessTokenSecret: string;
6
+ accessTokenExpiresIn: string;
7
+ refreshTokenSecret: string;
8
+ refreshTokenExpiresIn: string;
9
+ constructor({ siteOrigin, accessTokenSecret, accessTokenExpiresIn, refreshTokenSecret, refreshTokenExpiresIn, }: {
10
+ siteOrigin?: string;
11
+ accessTokenSecret: string;
12
+ accessTokenExpiresIn?: string;
13
+ refreshTokenSecret: string;
14
+ refreshTokenExpiresIn?: string;
15
+ });
6
16
  verify(token: string, secret: string): Promise<JWTPayload | undefined>;
7
17
  verifyAccessToken(token: string): Promise<JWTPayload | undefined>;
8
18
  verifyRefreshToken(token: string): Promise<JWTPayload | undefined>;
@@ -17,17 +17,31 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/auth-kit/jwt.ts
21
- var jwt_exports = {};
22
- __export(jwt_exports, {
20
+ // src/auth/jwt_manager.ts
21
+ var jwt_manager_exports = {};
22
+ __export(jwt_manager_exports, {
23
23
  JWTManager: () => JWTManager
24
24
  });
25
- module.exports = __toCommonJS(jwt_exports);
25
+ module.exports = __toCommonJS(jwt_manager_exports);
26
26
  var import_jose = require("jose");
27
27
  var JWTManager = class {
28
28
  siteOrigin;
29
- constructor(siteOrigin) {
29
+ accessTokenSecret;
30
+ accessTokenExpiresIn;
31
+ refreshTokenSecret;
32
+ refreshTokenExpiresIn;
33
+ constructor({
34
+ siteOrigin,
35
+ accessTokenSecret,
36
+ accessTokenExpiresIn = "10s",
37
+ refreshTokenSecret,
38
+ refreshTokenExpiresIn = "1h"
39
+ }) {
30
40
  this.siteOrigin = siteOrigin;
41
+ this.accessTokenSecret = accessTokenSecret;
42
+ this.accessTokenExpiresIn = accessTokenExpiresIn;
43
+ this.refreshTokenSecret = refreshTokenSecret;
44
+ this.refreshTokenExpiresIn = refreshTokenExpiresIn;
31
45
  }
32
46
  async verify(token, secret) {
33
47
  try {
@@ -38,10 +52,10 @@ var JWTManager = class {
38
52
  }
39
53
  }
40
54
  async verifyAccessToken(token) {
41
- return this.verify(token, process.env.ACCESS_TOKEN_SECRET);
55
+ return this.verify(token, this.accessTokenSecret);
42
56
  }
43
57
  async verifyRefreshToken(token) {
44
- return this.verify(token, process.env.REFRESH_TOKEN_SECRET);
58
+ return this.verify(token, this.refreshTokenSecret);
45
59
  }
46
60
  async sign(payload, secret, { expiresIn } = {}) {
47
61
  let builder = new import_jose.SignJWT(payload).setProtectedHeader({ alg: "HS256", typ: "JWT" }).setIssuedAt();
@@ -54,13 +68,13 @@ var JWTManager = class {
54
68
  return builder.sign(new TextEncoder().encode(secret));
55
69
  }
56
70
  async signAccessToken(payload) {
57
- return this.sign(payload, process.env.ACCESS_TOKEN_SECRET, {
58
- expiresIn: process.env.ACCESS_TOKEN_EXPIRES_IN || "10s"
71
+ return this.sign(payload, this.accessTokenSecret, {
72
+ expiresIn: this.accessTokenExpiresIn
59
73
  });
60
74
  }
61
75
  async signRefreshToken(payload) {
62
- return this.sign(payload, process.env.REFRESH_TOKEN_SECRET, {
63
- expiresIn: process.env.REFRESH_TOKEN_EXPIRES_IN || "1d"
76
+ return this.sign(payload, this.refreshTokenSecret, {
77
+ expiresIn: this.refreshTokenExpiresIn
64
78
  });
65
79
  }
66
80
  decode(token) {
@@ -1,9 +1,23 @@
1
- // src/auth-kit/jwt.ts
1
+ // src/auth/jwt_manager.ts
2
2
  import { SignJWT, decodeJwt, jwtVerify } from "jose";
3
3
  var JWTManager = class {
4
4
  siteOrigin;
5
- constructor(siteOrigin) {
5
+ accessTokenSecret;
6
+ accessTokenExpiresIn;
7
+ refreshTokenSecret;
8
+ refreshTokenExpiresIn;
9
+ constructor({
10
+ siteOrigin,
11
+ accessTokenSecret,
12
+ accessTokenExpiresIn = "10s",
13
+ refreshTokenSecret,
14
+ refreshTokenExpiresIn = "1h"
15
+ }) {
6
16
  this.siteOrigin = siteOrigin;
17
+ this.accessTokenSecret = accessTokenSecret;
18
+ this.accessTokenExpiresIn = accessTokenExpiresIn;
19
+ this.refreshTokenSecret = refreshTokenSecret;
20
+ this.refreshTokenExpiresIn = refreshTokenExpiresIn;
7
21
  }
8
22
  async verify(token, secret) {
9
23
  try {
@@ -14,10 +28,10 @@ var JWTManager = class {
14
28
  }
15
29
  }
16
30
  async verifyAccessToken(token) {
17
- return this.verify(token, process.env.ACCESS_TOKEN_SECRET);
31
+ return this.verify(token, this.accessTokenSecret);
18
32
  }
19
33
  async verifyRefreshToken(token) {
20
- return this.verify(token, process.env.REFRESH_TOKEN_SECRET);
34
+ return this.verify(token, this.refreshTokenSecret);
21
35
  }
22
36
  async sign(payload, secret, { expiresIn } = {}) {
23
37
  let builder = new SignJWT(payload).setProtectedHeader({ alg: "HS256", typ: "JWT" }).setIssuedAt();
@@ -30,13 +44,13 @@ var JWTManager = class {
30
44
  return builder.sign(new TextEncoder().encode(secret));
31
45
  }
32
46
  async signAccessToken(payload) {
33
- return this.sign(payload, process.env.ACCESS_TOKEN_SECRET, {
34
- expiresIn: process.env.ACCESS_TOKEN_EXPIRES_IN || "10s"
47
+ return this.sign(payload, this.accessTokenSecret, {
48
+ expiresIn: this.accessTokenExpiresIn
35
49
  });
36
50
  }
37
51
  async signRefreshToken(payload) {
38
- return this.sign(payload, process.env.REFRESH_TOKEN_SECRET, {
39
- expiresIn: process.env.REFRESH_TOKEN_EXPIRES_IN || "1d"
52
+ return this.sign(payload, this.refreshTokenSecret, {
53
+ expiresIn: this.refreshTokenExpiresIn
40
54
  });
41
55
  }
42
56
  decode(token) {
@@ -0,0 +1,27 @@
1
+ import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.mjs';
2
+ import './auth_service.mjs';
3
+ import 'jose';
4
+ import 'react-router';
5
+ import './jwt_manager.mjs';
6
+ import '../file/object_storage.mjs';
7
+ import '@aws-sdk/client-s3';
8
+ import './auth_repository.mjs';
9
+
10
+ declare class KakaoAuth implements ThirdpartyAuth {
11
+ thirdpartyAuth: ThirdpartyAuthService;
12
+ constructor({ thirdpartyAuth, }: {
13
+ thirdpartyAuth: ThirdpartyAuthService;
14
+ });
15
+ login(kakaoAccessToken: string): Promise<{
16
+ user: {
17
+ id: string;
18
+ role: string;
19
+ name: string;
20
+ refreshToken: string | null;
21
+ };
22
+ accessToken: string;
23
+ refreshToken: string;
24
+ }>;
25
+ }
26
+
27
+ export { KakaoAuth };
@@ -0,0 +1,27 @@
1
+ import { ThirdpartyAuth, ThirdpartyAuthService } from './thirdparty_auth.js';
2
+ import './auth_service.js';
3
+ import 'jose';
4
+ import 'react-router';
5
+ import './jwt_manager.js';
6
+ import '../file/object_storage.js';
7
+ import '@aws-sdk/client-s3';
8
+ import './auth_repository.js';
9
+
10
+ declare class KakaoAuth implements ThirdpartyAuth {
11
+ thirdpartyAuth: ThirdpartyAuthService;
12
+ constructor({ thirdpartyAuth, }: {
13
+ thirdpartyAuth: ThirdpartyAuthService;
14
+ });
15
+ login(kakaoAccessToken: string): Promise<{
16
+ user: {
17
+ id: string;
18
+ role: string;
19
+ name: string;
20
+ refreshToken: string | null;
21
+ };
22
+ accessToken: string;
23
+ refreshToken: string;
24
+ }>;
25
+ }
26
+
27
+ export { KakaoAuth };
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/auth/kakao_auth.ts
21
+ var kakao_auth_exports = {};
22
+ __export(kakao_auth_exports, {
23
+ KakaoAuth: () => KakaoAuth
24
+ });
25
+ module.exports = __toCommonJS(kakao_auth_exports);
26
+ var KakaoAuth = class {
27
+ thirdpartyAuth;
28
+ constructor({
29
+ thirdpartyAuth
30
+ }) {
31
+ this.thirdpartyAuth = thirdpartyAuth;
32
+ }
33
+ async login(kakaoAccessToken) {
34
+ const userRes = await fetch("https://kapi.kakao.com/v2/user/me", {
35
+ headers: {
36
+ Authorization: `Bearer ${kakaoAccessToken}`
37
+ }
38
+ });
39
+ if (!userRes.ok) {
40
+ throw new Error("\uC720\uC800 \uC815\uBCF4\uB97C \uAC00\uC838\uC624\uB294\uB370 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4.");
41
+ }
42
+ const { id, kakao_account } = await userRes.json();
43
+ const { email, profile } = kakao_account;
44
+ const payload = {
45
+ id,
46
+ email,
47
+ name: profile.nickname,
48
+ picture: profile.thumbnail_image_url
49
+ };
50
+ return this.thirdpartyAuth.issueTokensIfUserFound("kakao", payload);
51
+ }
52
+ };
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ KakaoAuth
56
+ });
@@ -0,0 +1,31 @@
1
+ // src/auth/kakao_auth.ts
2
+ var KakaoAuth = class {
3
+ thirdpartyAuth;
4
+ constructor({
5
+ thirdpartyAuth
6
+ }) {
7
+ this.thirdpartyAuth = thirdpartyAuth;
8
+ }
9
+ async login(kakaoAccessToken) {
10
+ const userRes = await fetch("https://kapi.kakao.com/v2/user/me", {
11
+ headers: {
12
+ Authorization: `Bearer ${kakaoAccessToken}`
13
+ }
14
+ });
15
+ if (!userRes.ok) {
16
+ throw new Error("\uC720\uC800 \uC815\uBCF4\uB97C \uAC00\uC838\uC624\uB294\uB370 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4.");
17
+ }
18
+ const { id, kakao_account } = await userRes.json();
19
+ const { email, profile } = kakao_account;
20
+ const payload = {
21
+ id,
22
+ email,
23
+ name: profile.nickname,
24
+ picture: profile.thumbnail_image_url
25
+ };
26
+ return this.thirdpartyAuth.issueTokensIfUserFound("kakao", payload);
27
+ }
28
+ };
29
+ export {
30
+ KakaoAuth
31
+ };
@@ -0,0 +1,34 @@
1
+ import { AuthRepository } from './auth_repository.mjs';
2
+ import { JWTManager } from './jwt_manager.mjs';
3
+ import 'jose';
4
+
5
+ declare class PasswordRecoveryService {
6
+ siteOrigin: string;
7
+ siteName: string;
8
+ jwtManager: JWTManager;
9
+ authRepository: AuthRepository;
10
+ emailCredentials: {
11
+ service: string;
12
+ user: string;
13
+ pass: string;
14
+ };
15
+ resetPasswordTokenSecret: string;
16
+ resetPasswordTokenExpiresIn: string;
17
+ constructor({ siteOrigin, siteName, jwtManager, authRepository, emailCredentials, resetPasswordTokenSecret, resetPasswordTokenExpiresIn, }: {
18
+ siteOrigin: string;
19
+ siteName: string;
20
+ jwtManager: JWTManager;
21
+ authRepository: AuthRepository;
22
+ emailCredentials: {
23
+ service: string;
24
+ user: string;
25
+ pass: string;
26
+ };
27
+ resetPasswordTokenSecret: string;
28
+ resetPasswordTokenExpiresIn?: string;
29
+ });
30
+ requestPasswordReset(email: string): Promise<void>;
31
+ resetPassword(token: string, password: string, passwordConfirm: string): Promise<void>;
32
+ }
33
+
34
+ export { PasswordRecoveryService };
@@ -0,0 +1,34 @@
1
+ import { AuthRepository } from './auth_repository.js';
2
+ import { JWTManager } from './jwt_manager.js';
3
+ import 'jose';
4
+
5
+ declare class PasswordRecoveryService {
6
+ siteOrigin: string;
7
+ siteName: string;
8
+ jwtManager: JWTManager;
9
+ authRepository: AuthRepository;
10
+ emailCredentials: {
11
+ service: string;
12
+ user: string;
13
+ pass: string;
14
+ };
15
+ resetPasswordTokenSecret: string;
16
+ resetPasswordTokenExpiresIn: string;
17
+ constructor({ siteOrigin, siteName, jwtManager, authRepository, emailCredentials, resetPasswordTokenSecret, resetPasswordTokenExpiresIn, }: {
18
+ siteOrigin: string;
19
+ siteName: string;
20
+ jwtManager: JWTManager;
21
+ authRepository: AuthRepository;
22
+ emailCredentials: {
23
+ service: string;
24
+ user: string;
25
+ pass: string;
26
+ };
27
+ resetPasswordTokenSecret: string;
28
+ resetPasswordTokenExpiresIn?: string;
29
+ });
30
+ requestPasswordReset(email: string): Promise<void>;
31
+ resetPassword(token: string, password: string, passwordConfirm: string): Promise<void>;
32
+ }
33
+
34
+ export { PasswordRecoveryService };
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
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
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/auth/password_recovery.ts
31
+ var password_recovery_exports = {};
32
+ __export(password_recovery_exports, {
33
+ PasswordRecoveryService: () => PasswordRecoveryService
34
+ });
35
+ module.exports = __toCommonJS(password_recovery_exports);
36
+ var import_nodemailer = __toESM(require("nodemailer"));
37
+
38
+ // src/http/response.ts
39
+ var createJsonResponse = (status) => {
40
+ return (data = {}, init) => {
41
+ return Response.json(data, { status, ...init });
42
+ };
43
+ };
44
+ var OK = createJsonResponse(200);
45
+ var CREATED = createJsonResponse(201);
46
+ var ACCEPTED = createJsonResponse(202);
47
+ var createException = (status, defaultMessage = "\uC624\uB958\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4.") => {
48
+ return (message = defaultMessage, init) => {
49
+ return createJsonResponse(status)({ message }, init);
50
+ };
51
+ };
52
+ var BAD_REQUEST = createException(400, "\uC694\uCCAD\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
53
+ var UNAUTHORIZED = createException(401, "\uC778\uC99D\uC774 \uD544\uC694\uD569\uB2C8\uB2E4.");
54
+ var FORBIDDEN = createException(403, "\uAD8C\uD55C\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.");
55
+ var NOT_FOUND = createException(
56
+ 404,
57
+ "\uC694\uCCAD\uD55C \uB9AC\uC18C\uC2A4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
58
+ );
59
+ var METHOD_NOT_ALLOWED = createException(
60
+ 405,
61
+ "\uBA54\uC11C\uB4DC\uB97C \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
62
+ );
63
+ var NOT_ACCEPTABLE = createException(
64
+ 406,
65
+ "\uC694\uCCAD\uD55C \uD615\uC2DD\uC744 \uC0AC\uC6A9\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."
66
+ );
67
+ var REQUEST_TIMEOUT = createException(
68
+ 408,
69
+ "\uC694\uCCAD \uC2DC\uAC04\uC774 \uCD08\uACFC\uB418\uC5C8\uC2B5\uB2C8\uB2E4."
70
+ );
71
+ var CONFLICT = createException(409, "\uC694\uCCAD\uC774 \uCDA9\uB3CC\uD588\uC2B5\uB2C8\uB2E4.");
72
+ var UNPROCESSABLE_ENTITY = createException(
73
+ 422,
74
+ "\uCC98\uB9AC\uD560 \uC218 \uC5C6\uB294 \uC5D4\uD2F0\uD2F0\uC785\uB2C8\uB2E4."
75
+ );
76
+ var TOO_MANY_REQUESTS = createException(429, "\uC694\uCCAD\uC774 \uB108\uBB34 \uB9CE\uC2B5\uB2C8\uB2E4.");
77
+ var INTERNAL_SERVER_ERROR = createException(
78
+ 500,
79
+ "\uC608\uAE30\uCE58 \uBABB\uD55C \uC624\uB958\uAC00 \uBC1C\uC0DD\uD588\uC2B5\uB2C8\uB2E4."
80
+ );
81
+
82
+ // src/auth/password_recovery.ts
83
+ var import_bcryptjs = __toESM(require("bcryptjs"));
84
+ var PasswordRecoveryService = class {
85
+ siteOrigin;
86
+ siteName;
87
+ jwtManager;
88
+ authRepository;
89
+ emailCredentials;
90
+ resetPasswordTokenSecret;
91
+ resetPasswordTokenExpiresIn;
92
+ constructor({
93
+ siteOrigin,
94
+ siteName,
95
+ jwtManager,
96
+ authRepository,
97
+ emailCredentials,
98
+ resetPasswordTokenSecret,
99
+ resetPasswordTokenExpiresIn = "1h"
100
+ }) {
101
+ this.siteOrigin = siteOrigin;
102
+ this.siteName = siteName;
103
+ this.jwtManager = jwtManager;
104
+ this.authRepository = authRepository;
105
+ this.emailCredentials = emailCredentials;
106
+ this.resetPasswordTokenSecret = resetPasswordTokenSecret;
107
+ this.resetPasswordTokenExpiresIn = resetPasswordTokenExpiresIn;
108
+ }
109
+ async requestPasswordReset(email) {
110
+ const credential = await this.authRepository.findCredentialById(email);
111
+ if (!credential) {
112
+ throw NOT_FOUND("\uAC00\uC785\uB418\uC9C0 \uC54A\uC740 \uC774\uBA54\uC77C\uC785\uB2C8\uB2E4.");
113
+ }
114
+ const transporter = import_nodemailer.default.createTransport({
115
+ service: this.emailCredentials.service,
116
+ auth: {
117
+ user: this.emailCredentials.user,
118
+ pass: this.emailCredentials.pass
119
+ }
120
+ });
121
+ const token = await this.jwtManager.sign(
122
+ {
123
+ id: credential.id
124
+ },
125
+ this.resetPasswordTokenSecret,
126
+ {
127
+ expiresIn: this.resetPasswordTokenExpiresIn
128
+ }
129
+ );
130
+ const link = `${this.siteOrigin}/reset-password?token=${token}`;
131
+ const mailOptions = {
132
+ from: process.env.EMAIL_USER,
133
+ to: email,
134
+ subject: `${this.siteName} \uBE44\uBC00\uBC88\uD638 \uC7AC\uC124\uC815`,
135
+ html: `<main>
136
+ <p>\uBE44\uBC00\uBC88\uD638 \uC7AC\uC124\uC815\uC744 \uC704\uD574 \uC544\uB798 \uB9C1\uD06C\uB97C \uD074\uB9AD\uD574 \uC8FC\uC138\uC694. \uB9C1\uD06C\uB294 \uD55C \uC2DC\uAC04 \uB3D9\uC548 \uC720\uD6A8\uD569\uB2C8\uB2E4. \uB2E4\uB978 \uC0AC\uB78C\uC5D0\uAC8C \uACF5\uC720\uD558\uC9C0 \uB9C8\uC138\uC694.</p>
137
+ <a href="${link}" target="_blank">${link}</a>
138
+ </main>`
139
+ };
140
+ await transporter.sendMail(mailOptions);
141
+ }
142
+ async resetPassword(token, password, passwordConfirm) {
143
+ const payload = await this.jwtManager.verify(
144
+ token,
145
+ this.resetPasswordTokenSecret
146
+ );
147
+ if (!payload) {
148
+ throw UNAUTHORIZED("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 \uD1A0\uD070\uC785\uB2C8\uB2E4.");
149
+ }
150
+ if (typeof payload.id !== "string") {
151
+ throw UNAUTHORIZED("\uD1A0\uD070\uC774 \uC704\uC870\uB418\uC5C8\uC2B5\uB2C8\uB2E4.");
152
+ }
153
+ const credential = await this.authRepository.findCredentialById(payload.id);
154
+ if (!credential) {
155
+ throw NOT_FOUND("\uC874\uC7AC\uD558\uC9C0 \uC54A\uB294 \uACC4\uC815\uC785\uB2C8\uB2E4.");
156
+ }
157
+ if (typeof password !== "string" || !password.trim()) {
158
+ throw BAD_REQUEST("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 \uBE44\uBC00\uBC88\uD638\uC785\uB2C8\uB2E4.");
159
+ }
160
+ if (password !== passwordConfirm) {
161
+ throw BAD_REQUEST("\uBE44\uBC00\uBC88\uD638\uAC00 \uC77C\uCE58\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
162
+ }
163
+ await this.authRepository.updatePassword(credential.id, import_bcryptjs.default.hashSync(password, 10));
164
+ }
165
+ };
166
+ // Annotate the CommonJS export names for ESM import in node:
167
+ 0 && (module.exports = {
168
+ PasswordRecoveryService
169
+ });