dn-react-router-toolkit 0.1.11 → 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 +12 -22
  9. package/dist/{auth-kit → auth}/auth_service.d.ts +12 -22
  10. package/dist/{auth-kit → auth}/auth_service.js +30 -77
  11. package/dist/{auth-kit → auth}/auth_service.mjs +30 -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 +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 -42
  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 -67
  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
@@ -0,0 +1,38 @@
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 AppleAuth implements ThirdpartyAuth {
11
+ thirdpartyAuth: ThirdpartyAuthService;
12
+ appleAuthKey: string;
13
+ appleClientId: string;
14
+ appleTeamId: string;
15
+ appleKeyId: string;
16
+ appleServiceId: string;
17
+ constructor({ thirdpartyAuth, appleAuthKey, appleClientId, appleTeamId, appleKeyId, appleServiceId, }: {
18
+ thirdpartyAuth: ThirdpartyAuthService;
19
+ appleAuthKey: string;
20
+ appleClientId: string;
21
+ appleTeamId: string;
22
+ appleKeyId: string;
23
+ appleServiceId: string;
24
+ });
25
+ login(code: string, type?: "web" | "app"): Promise<{
26
+ user: {
27
+ id: string;
28
+ role: string;
29
+ name: string;
30
+ refreshToken: string | null;
31
+ };
32
+ accessToken: string;
33
+ refreshToken: string;
34
+ }>;
35
+ private generateAppleClientSecret;
36
+ }
37
+
38
+ export { AppleAuth };
@@ -0,0 +1,38 @@
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 AppleAuth implements ThirdpartyAuth {
11
+ thirdpartyAuth: ThirdpartyAuthService;
12
+ appleAuthKey: string;
13
+ appleClientId: string;
14
+ appleTeamId: string;
15
+ appleKeyId: string;
16
+ appleServiceId: string;
17
+ constructor({ thirdpartyAuth, appleAuthKey, appleClientId, appleTeamId, appleKeyId, appleServiceId, }: {
18
+ thirdpartyAuth: ThirdpartyAuthService;
19
+ appleAuthKey: string;
20
+ appleClientId: string;
21
+ appleTeamId: string;
22
+ appleKeyId: string;
23
+ appleServiceId: string;
24
+ });
25
+ login(code: string, type?: "web" | "app"): Promise<{
26
+ user: {
27
+ id: string;
28
+ role: string;
29
+ name: string;
30
+ refreshToken: string | null;
31
+ };
32
+ accessToken: string;
33
+ refreshToken: string;
34
+ }>;
35
+ private generateAppleClientSecret;
36
+ }
37
+
38
+ export { AppleAuth };
@@ -17,7 +17,7 @@ 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/apple_auth.ts
20
+ // src/auth/apple_auth.ts
21
21
  var apple_auth_exports = {};
22
22
  __export(apple_auth_exports, {
23
23
  AppleAuth: () => AppleAuth
@@ -25,11 +25,28 @@ __export(apple_auth_exports, {
25
25
  module.exports = __toCommonJS(apple_auth_exports);
26
26
  var import_jose = require("jose");
27
27
  var AppleAuth = class {
28
- AUTH;
29
- constructor(AUTH) {
30
- this.AUTH = AUTH;
28
+ thirdpartyAuth;
29
+ appleAuthKey;
30
+ appleClientId;
31
+ appleTeamId;
32
+ appleKeyId;
33
+ appleServiceId;
34
+ constructor({
35
+ thirdpartyAuth,
36
+ appleAuthKey,
37
+ appleClientId,
38
+ appleTeamId,
39
+ appleKeyId,
40
+ appleServiceId
41
+ }) {
42
+ this.thirdpartyAuth = thirdpartyAuth;
43
+ this.appleAuthKey = appleAuthKey;
44
+ this.appleClientId = appleClientId;
45
+ this.appleTeamId = appleTeamId;
46
+ this.appleKeyId = appleKeyId;
47
+ this.appleServiceId = appleServiceId;
31
48
  }
32
- async signIn(code, type = "web") {
49
+ async login(code, type = "web") {
33
50
  const url = "https://appleid.apple.com/auth/token";
34
51
  const client_secret = await this.generateAppleClientSecret(type);
35
52
  const res = await fetch(url, {
@@ -38,7 +55,7 @@ var AppleAuth = class {
38
55
  "Content-Type": "application/x-www-form-urlencoded"
39
56
  },
40
57
  body: new URLSearchParams({
41
- client_id: type === "web" ? process.env.APPLE_SERVICE_ID : process.env.APPLE_CLIENT_ID,
58
+ client_id: type === "web" ? this.appleServiceId : this.appleClientId,
42
59
  client_secret,
43
60
  code,
44
61
  grant_type: "authorization_code"
@@ -50,23 +67,19 @@ var AppleAuth = class {
50
67
  }
51
68
  const data = await res.json();
52
69
  const { id_token } = data;
53
- const payload = (0, import_jose.decodeJwt)(id_token);
54
- const { sub, email, name } = payload;
55
- const user = await this.AUTH.getOrCreateUser("apple", {
70
+ const appleAuth = (0, import_jose.decodeJwt)(id_token);
71
+ const { sub, email, name } = appleAuth;
72
+ const payload = {
56
73
  id: sub,
57
74
  email,
58
75
  name
59
- });
60
- const { accessToken, refreshToken } = await this.AUTH.issueTokenPair(user);
61
- return { user, accessToken, refreshToken };
76
+ };
77
+ return this.thirdpartyAuth.issueTokensIfUserFound("apple", payload);
62
78
  }
63
79
  async generateAppleClientSecret(type = "web") {
64
- const authKey = process.env.APPLE_AUTH_KEY;
65
- const teamId = process.env.APPLE_TEAM_ID;
66
- const keyId = process.env.APPLE_KEY_ID;
67
- const clientId = type === "web" ? process.env.APPLE_SERVICE_ID : process.env.APPLE_CLIENT_ID;
68
- const keyObject = await (0, import_jose.importPKCS8)(authKey, "ES256");
69
- return new import_jose.SignJWT().setProtectedHeader({ alg: "ES256", kid: keyId }).setIssuedAt().setIssuer(teamId).setExpirationTime("1h").setAudience("https://appleid.apple.com").setSubject(clientId).sign(keyObject);
80
+ const clientId = type === "web" ? this.appleServiceId : this.appleClientId;
81
+ const keyObject = await (0, import_jose.importPKCS8)(this.appleAuthKey, "ES256");
82
+ return new import_jose.SignJWT().setProtectedHeader({ alg: "ES256", kid: this.appleKeyId }).setIssuedAt().setIssuer(this.appleTeamId).setExpirationTime("1h").setAudience("https://appleid.apple.com").setSubject(clientId).sign(keyObject);
70
83
  }
71
84
  };
72
85
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,63 @@
1
+ // src/auth/apple_auth.ts
2
+ import { decodeJwt, importPKCS8, SignJWT } from "jose";
3
+ var AppleAuth = class {
4
+ thirdpartyAuth;
5
+ appleAuthKey;
6
+ appleClientId;
7
+ appleTeamId;
8
+ appleKeyId;
9
+ appleServiceId;
10
+ constructor({
11
+ thirdpartyAuth,
12
+ appleAuthKey,
13
+ appleClientId,
14
+ appleTeamId,
15
+ appleKeyId,
16
+ appleServiceId
17
+ }) {
18
+ this.thirdpartyAuth = thirdpartyAuth;
19
+ this.appleAuthKey = appleAuthKey;
20
+ this.appleClientId = appleClientId;
21
+ this.appleTeamId = appleTeamId;
22
+ this.appleKeyId = appleKeyId;
23
+ this.appleServiceId = appleServiceId;
24
+ }
25
+ async login(code, type = "web") {
26
+ const url = "https://appleid.apple.com/auth/token";
27
+ const client_secret = await this.generateAppleClientSecret(type);
28
+ const res = await fetch(url, {
29
+ method: "POST",
30
+ headers: {
31
+ "Content-Type": "application/x-www-form-urlencoded"
32
+ },
33
+ body: new URLSearchParams({
34
+ client_id: type === "web" ? this.appleServiceId : this.appleClientId,
35
+ client_secret,
36
+ code,
37
+ grant_type: "authorization_code"
38
+ })
39
+ });
40
+ if (!res.ok) {
41
+ console.error(await res.text());
42
+ throw new Error("Apple \uC778\uC99D\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4.");
43
+ }
44
+ const data = await res.json();
45
+ const { id_token } = data;
46
+ const appleAuth = decodeJwt(id_token);
47
+ const { sub, email, name } = appleAuth;
48
+ const payload = {
49
+ id: sub,
50
+ email,
51
+ name
52
+ };
53
+ return this.thirdpartyAuth.issueTokensIfUserFound("apple", payload);
54
+ }
55
+ async generateAppleClientSecret(type = "web") {
56
+ const clientId = type === "web" ? this.appleServiceId : this.appleClientId;
57
+ const keyObject = await importPKCS8(this.appleAuthKey, "ES256");
58
+ return new SignJWT().setProtectedHeader({ alg: "ES256", kid: this.appleKeyId }).setIssuedAt().setIssuer(this.appleTeamId).setExpirationTime("1h").setAudience("https://appleid.apple.com").setSubject(clientId).sign(keyObject);
59
+ }
60
+ };
61
+ export {
62
+ AppleAuth
63
+ };
@@ -1,4 +1,4 @@
1
- interface AuthRepository {
1
+ interface AuthRepository<TFile = unknown> {
2
2
  findCredentialById(id: string): Promise<{
3
3
  password: string;
4
4
  userId: string;
@@ -13,9 +13,9 @@ interface AuthRepository {
13
13
  createUser(userData: {
14
14
  id: string;
15
15
  role: string;
16
- profileImageId: string | null;
17
16
  name: string;
18
17
  email: string;
18
+ profileImage?: TFile;
19
19
  }): Promise<{
20
20
  id: string;
21
21
  role: string;
@@ -24,18 +24,15 @@ interface AuthRepository {
24
24
  findThirdPartyAuth(provider: string, providerId: string): Promise<{
25
25
  userId: string;
26
26
  } | undefined>;
27
- createThirdPartyAuth(authData: {
27
+ createThirdPartyAuth(params: {
28
28
  id: string;
29
29
  provider: string;
30
30
  userId: string;
31
31
  }): Promise<void>;
32
- createFile(fileData: {
32
+ createCredential(params: {
33
33
  id: string;
34
- name: string;
35
- type: string;
36
- key: string;
37
- size: number;
38
- metadata: Record<string, any>;
34
+ password: string;
35
+ userId: string;
39
36
  }): Promise<void>;
40
37
  }
41
38
 
@@ -1,4 +1,4 @@
1
- interface AuthRepository {
1
+ interface AuthRepository<TFile = unknown> {
2
2
  findCredentialById(id: string): Promise<{
3
3
  password: string;
4
4
  userId: string;
@@ -13,9 +13,9 @@ interface AuthRepository {
13
13
  createUser(userData: {
14
14
  id: string;
15
15
  role: string;
16
- profileImageId: string | null;
17
16
  name: string;
18
17
  email: string;
18
+ profileImage?: TFile;
19
19
  }): Promise<{
20
20
  id: string;
21
21
  role: string;
@@ -24,18 +24,15 @@ interface AuthRepository {
24
24
  findThirdPartyAuth(provider: string, providerId: string): Promise<{
25
25
  userId: string;
26
26
  } | undefined>;
27
- createThirdPartyAuth(authData: {
27
+ createThirdPartyAuth(params: {
28
28
  id: string;
29
29
  provider: string;
30
30
  userId: string;
31
31
  }): Promise<void>;
32
- createFile(fileData: {
32
+ createCredential(params: {
33
33
  id: string;
34
- name: string;
35
- type: string;
36
- key: string;
37
- size: number;
38
- metadata: Record<string, any>;
34
+ password: string;
35
+ userId: string;
39
36
  }): Promise<void>;
40
37
  }
41
38
 
@@ -13,6 +13,6 @@ var __copyProps = (to, from, except, desc) => {
13
13
  };
14
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
15
 
16
- // src/file-kit/repository.ts
17
- var repository_exports = {};
18
- module.exports = __toCommonJS(repository_exports);
16
+ // src/auth/auth_repository.ts
17
+ var auth_repository_exports = {};
18
+ module.exports = __toCommonJS(auth_repository_exports);
@@ -1,25 +1,26 @@
1
1
  import * as jose from 'jose';
2
2
  import * as react_router from 'react-router';
3
- import { JWTManager } from './jwt.mjs';
4
- import { ObjectStorage } from '../file-kit/object_storage.mjs';
5
- import { AuthRepository } from './repository.mjs';
3
+ import { JWTManager } from './jwt_manager.mjs';
4
+ import { ObjectStorage } from '../file/object_storage.mjs';
5
+ import { AuthRepository } from './auth_repository.mjs';
6
6
  import '@aws-sdk/client-s3';
7
7
 
8
8
  declare const ACCESS_TOKEN_KEY = "access_token";
9
9
  declare const REFRESH_TOKEN_KEY = "refresh_token";
10
10
  declare const ACCESS_TOKEN_COOKIE: react_router.Cookie;
11
11
  declare const REFRESH_TOKEN_COOKIE: react_router.Cookie;
12
- declare class AuthService {
13
- repository: AuthRepository;
14
- JWT_MANAGER: JWTManager;
15
- OBJECT_STORAGE: ObjectStorage;
16
- constructor({ repository, JWT_MANAGER, OBJECT_STORAGE, }: {
17
- repository: AuthRepository;
18
- JWT_MANAGER: JWTManager;
19
- OBJECT_STORAGE: ObjectStorage;
12
+ declare class AuthService<TFile = unknown> {
13
+ authRepository: AuthRepository<TFile>;
14
+ jwtManager: JWTManager;
15
+ objectStorage: ObjectStorage;
16
+ constructor({ authRepository, jwtManager, objectStorage, }: {
17
+ authRepository: AuthRepository<TFile>;
18
+ jwtManager: JWTManager;
19
+ objectStorage: ObjectStorage;
20
20
  });
21
21
  verify(request: Request): Promise<jose.JWTPayload | undefined>;
22
22
  verifyOrRefresh(request: Request): Promise<jose.JWTPayload | undefined>;
23
+ getAccessTokenFromRequest(request: Request): Promise<any>;
23
24
  getAccessTokenFromCookies(request: Request): Promise<any>;
24
25
  getRefreshTokenFromCookies(request: Request): Promise<any>;
25
26
  refresh(request: Request): Promise<jose.JWTPayload | undefined>;
@@ -57,17 +58,6 @@ declare class AuthService {
57
58
  name: string;
58
59
  refreshToken: string | null;
59
60
  } | undefined>;
60
- getOrCreateUser(provider: string, info: {
61
- id: string;
62
- email: string;
63
- name?: string;
64
- picture?: string;
65
- }): Promise<{
66
- id: string;
67
- role: string;
68
- name: string;
69
- }>;
70
- protected savePicture(picture?: string): Promise<string | undefined>;
71
61
  }
72
62
 
73
63
  export { ACCESS_TOKEN_COOKIE, ACCESS_TOKEN_KEY, AuthService, REFRESH_TOKEN_COOKIE, REFRESH_TOKEN_KEY };
@@ -1,25 +1,26 @@
1
1
  import * as jose from 'jose';
2
2
  import * as react_router from 'react-router';
3
- import { JWTManager } from './jwt.js';
4
- import { ObjectStorage } from '../file-kit/object_storage.js';
5
- import { AuthRepository } from './repository.js';
3
+ import { JWTManager } from './jwt_manager.js';
4
+ import { ObjectStorage } from '../file/object_storage.js';
5
+ import { AuthRepository } from './auth_repository.js';
6
6
  import '@aws-sdk/client-s3';
7
7
 
8
8
  declare const ACCESS_TOKEN_KEY = "access_token";
9
9
  declare const REFRESH_TOKEN_KEY = "refresh_token";
10
10
  declare const ACCESS_TOKEN_COOKIE: react_router.Cookie;
11
11
  declare const REFRESH_TOKEN_COOKIE: react_router.Cookie;
12
- declare class AuthService {
13
- repository: AuthRepository;
14
- JWT_MANAGER: JWTManager;
15
- OBJECT_STORAGE: ObjectStorage;
16
- constructor({ repository, JWT_MANAGER, OBJECT_STORAGE, }: {
17
- repository: AuthRepository;
18
- JWT_MANAGER: JWTManager;
19
- OBJECT_STORAGE: ObjectStorage;
12
+ declare class AuthService<TFile = unknown> {
13
+ authRepository: AuthRepository<TFile>;
14
+ jwtManager: JWTManager;
15
+ objectStorage: ObjectStorage;
16
+ constructor({ authRepository, jwtManager, objectStorage, }: {
17
+ authRepository: AuthRepository<TFile>;
18
+ jwtManager: JWTManager;
19
+ objectStorage: ObjectStorage;
20
20
  });
21
21
  verify(request: Request): Promise<jose.JWTPayload | undefined>;
22
22
  verifyOrRefresh(request: Request): Promise<jose.JWTPayload | undefined>;
23
+ getAccessTokenFromRequest(request: Request): Promise<any>;
23
24
  getAccessTokenFromCookies(request: Request): Promise<any>;
24
25
  getRefreshTokenFromCookies(request: Request): Promise<any>;
25
26
  refresh(request: Request): Promise<jose.JWTPayload | undefined>;
@@ -57,17 +58,6 @@ declare class AuthService {
57
58
  name: string;
58
59
  refreshToken: string | null;
59
60
  } | undefined>;
60
- getOrCreateUser(provider: string, info: {
61
- id: string;
62
- email: string;
63
- name?: string;
64
- picture?: string;
65
- }): Promise<{
66
- id: string;
67
- role: string;
68
- name: string;
69
- }>;
70
- protected savePicture(picture?: string): Promise<string | undefined>;
71
61
  }
72
62
 
73
63
  export { ACCESS_TOKEN_COOKIE, ACCESS_TOKEN_KEY, AuthService, REFRESH_TOKEN_COOKIE, REFRESH_TOKEN_KEY };
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // src/auth-kit/auth_service.ts
30
+ // src/auth/auth_service.ts
31
31
  var auth_service_exports = {};
32
32
  __export(auth_service_exports, {
33
33
  ACCESS_TOKEN_COOKIE: () => ACCESS_TOKEN_COOKIE,
@@ -38,7 +38,6 @@ __export(auth_service_exports, {
38
38
  });
39
39
  module.exports = __toCommonJS(auth_service_exports);
40
40
  var import_bcryptjs = __toESM(require("bcryptjs"));
41
- var import_uuid = require("uuid");
42
41
  var import_react_router = require("react-router");
43
42
  var ACCESS_TOKEN_KEY = "access_token";
44
43
  var REFRESH_TOKEN_KEY = "refresh_token";
@@ -55,22 +54,22 @@ var REFRESH_TOKEN_COOKIE = (0, import_react_router.createCookie)(REFRESH_TOKEN_K
55
54
  sameSite: "strict"
56
55
  });
57
56
  var AuthService = class {
58
- repository;
59
- JWT_MANAGER;
60
- OBJECT_STORAGE;
57
+ authRepository;
58
+ jwtManager;
59
+ objectStorage;
61
60
  constructor({
62
- repository,
63
- JWT_MANAGER,
64
- OBJECT_STORAGE
61
+ authRepository,
62
+ jwtManager,
63
+ objectStorage
65
64
  }) {
66
- this.repository = repository;
67
- this.JWT_MANAGER = JWT_MANAGER;
68
- this.OBJECT_STORAGE = OBJECT_STORAGE;
65
+ this.authRepository = authRepository;
66
+ this.jwtManager = jwtManager;
67
+ this.objectStorage = objectStorage;
69
68
  }
70
69
  async verify(request) {
71
- const accessToken = request?.headers.get("Authorization")?.replace("Bearer ", "") || await this.getAccessTokenFromCookies(request);
70
+ const accessToken = await this.getAccessTokenFromRequest(request);
72
71
  if (accessToken) {
73
- return this.JWT_MANAGER.verifyAccessToken(accessToken);
72
+ return this.jwtManager.verifyAccessToken(accessToken);
74
73
  }
75
74
  }
76
75
  async verifyOrRefresh(request) {
@@ -80,6 +79,12 @@ var AuthService = class {
80
79
  }
81
80
  return this.refresh(request);
82
81
  }
82
+ async getAccessTokenFromRequest(request) {
83
+ if (request.headers.get("Authorization")) {
84
+ return request.headers.get("Authorization")?.replace("Bearer ", "");
85
+ }
86
+ return this.getAccessTokenFromCookies(request);
87
+ }
83
88
  async getAccessTokenFromCookies(request) {
84
89
  const accessToken = await ACCESS_TOKEN_COOKIE.parse(
85
90
  request.headers.get("cookie")
@@ -100,7 +105,7 @@ var AuthService = class {
100
105
  refreshToken
101
106
  );
102
107
  await this.getAccessTokenSetCookie(refreshedAccessToken);
103
- const payload = this.JWT_MANAGER.decode(refreshedAccessToken);
108
+ const payload = this.jwtManager.decode(refreshedAccessToken);
104
109
  if (payload) {
105
110
  return payload;
106
111
  }
@@ -113,14 +118,14 @@ var AuthService = class {
113
118
  }
114
119
  }
115
120
  async signIn({ id, password }) {
116
- const credential = await this.repository.findCredentialById(id);
121
+ const credential = await this.authRepository.findCredentialById(id);
117
122
  if (!credential) {
118
123
  throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
119
124
  }
120
125
  if (!await import_bcryptjs.default.compare(password, credential.password)) {
121
126
  throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
122
127
  }
123
- const user = await this.repository.findUserById(credential.userId);
128
+ const user = await this.authRepository.findUserById(credential.userId);
124
129
  if (!user) {
125
130
  throw Error("\uD68C\uC6D0 \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
126
131
  }
@@ -131,19 +136,19 @@ var AuthService = class {
131
136
  };
132
137
  }
133
138
  async issueAccessToken(user) {
134
- return this.JWT_MANAGER.signAccessToken({
139
+ return this.jwtManager.signAccessToken({
135
140
  userId: user.id,
136
141
  role: user.role,
137
142
  name: user.name
138
143
  });
139
144
  }
140
145
  async issueTokenPair(user) {
141
- const refreshToken = await this.JWT_MANAGER.signRefreshToken({
146
+ const refreshToken = await this.jwtManager.signRefreshToken({
142
147
  userId: user.id,
143
148
  role: user.role,
144
149
  name: user.name
145
150
  });
146
- await this.repository.updateUserRefreshToken(
151
+ await this.authRepository.updateUserRefreshToken(
147
152
  user.id,
148
153
  await import_bcryptjs.default.hash(refreshToken, 10)
149
154
  );
@@ -151,7 +156,7 @@ var AuthService = class {
151
156
  return { refreshToken, accessToken };
152
157
  }
153
158
  async refreshAccessToken(refreshToken) {
154
- const payload = await this.JWT_MANAGER.verifyRefreshToken(refreshToken);
159
+ const payload = await this.jwtManager.verifyRefreshToken(refreshToken);
155
160
  if (!payload) {
156
161
  throw new Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
157
162
  }
@@ -159,7 +164,7 @@ var AuthService = class {
159
164
  if (typeof userId !== "string") {
160
165
  throw new Error("\uD1A0\uD070\uC774 \uC704\uC870\uB418\uC5C8\uC2B5\uB2C8\uB2E4.");
161
166
  }
162
- const user = await this.repository.findUserById(userId);
167
+ const user = await this.authRepository.findUserById(userId);
163
168
  if (!user) {
164
169
  throw Error("\uC774\uC6A9\uC790\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
165
170
  }
@@ -174,77 +179,25 @@ var AuthService = class {
174
179
  }
175
180
  async getAccessTokenSetCookie(accessToken) {
176
181
  return ACCESS_TOKEN_COOKIE.serialize(accessToken, {
177
- expires: accessToken ? this.JWT_MANAGER.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
182
+ expires: accessToken ? this.jwtManager.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
178
183
  });
179
184
  }
180
185
  async getRefreshTokenSetCookie(refreshToken) {
181
186
  return REFRESH_TOKEN_COOKIE.serialize(refreshToken, {
182
- expires: refreshToken ? this.JWT_MANAGER.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
187
+ expires: refreshToken ? this.jwtManager.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
183
188
  });
184
189
  }
185
190
  async findUser(provider, info) {
186
- const thirdPartyAuth = await this.repository.findThirdPartyAuth(
187
- provider,
188
- info.id
189
- );
190
- if (thirdPartyAuth) {
191
- const user = await this.repository.findUserById(thirdPartyAuth.userId);
192
- if (user) {
193
- return user;
194
- }
195
- }
196
- }
197
- async getOrCreateUser(provider, info) {
198
- const thirdPartyAuth = await this.repository.findThirdPartyAuth(
191
+ const thirdPartyAuth = await this.authRepository.findThirdPartyAuth(
199
192
  provider,
200
193
  info.id
201
194
  );
202
195
  if (thirdPartyAuth) {
203
- const user = await this.repository.findUserById(thirdPartyAuth.userId);
196
+ const user = await this.authRepository.findUserById(thirdPartyAuth.userId);
204
197
  if (user) {
205
198
  return user;
206
199
  }
207
200
  }
208
- const userId = (0, import_uuid.v4)();
209
- const email = info.email;
210
- const name = info.name || "\uC775\uBA85";
211
- const picture = info.picture;
212
- const profileImageId = await this.savePicture(picture) || null;
213
- const result = await this.repository.createUser({
214
- id: userId,
215
- role: "user",
216
- profileImageId,
217
- name,
218
- email
219
- });
220
- await this.repository.createThirdPartyAuth({
221
- id: info.id,
222
- provider,
223
- userId
224
- });
225
- return result;
226
- }
227
- async savePicture(picture) {
228
- if (!picture) {
229
- return;
230
- }
231
- const res = await fetch(picture);
232
- if (!res.ok) {
233
- return;
234
- }
235
- const buffer = await res.arrayBuffer();
236
- const id = (0, import_uuid.v4)();
237
- const key = `/users/${id}/picture`;
238
- await this.OBJECT_STORAGE.put(key, Buffer.from(buffer));
239
- await this.repository.createFile({
240
- id,
241
- name: "picture",
242
- type: "image/*",
243
- key,
244
- size: buffer.byteLength,
245
- metadata: {}
246
- });
247
- return id;
248
201
  }
249
202
  };
250
203
  // Annotate the CommonJS export names for ESM import in node: