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
@@ -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,8 +1,15 @@
1
- interface AuthRepository {
1
+ interface AuthRepository<TFile = unknown> {
2
2
  findCredentialById(id: string): Promise<{
3
+ id: string;
3
4
  password: string;
4
5
  userId: string;
5
6
  } | undefined>;
7
+ createCredential(params: {
8
+ id: string;
9
+ password: string;
10
+ userId: string;
11
+ }): Promise<void>;
12
+ updatePassword(id: string, hashedPassword: string): Promise<void>;
6
13
  findUserById(userId: string): Promise<{
7
14
  id: string;
8
15
  role: string;
@@ -13,9 +20,9 @@ interface AuthRepository {
13
20
  createUser(userData: {
14
21
  id: string;
15
22
  role: string;
16
- profileImageId: string | null;
17
23
  name: string;
18
24
  email: string;
25
+ profileImage?: TFile;
19
26
  }): Promise<{
20
27
  id: string;
21
28
  role: string;
@@ -24,19 +31,11 @@ interface AuthRepository {
24
31
  findThirdPartyAuth(provider: string, providerId: string): Promise<{
25
32
  userId: string;
26
33
  } | undefined>;
27
- createThirdPartyAuth(authData: {
34
+ createThirdPartyAuth(params: {
28
35
  id: string;
29
36
  provider: string;
30
37
  userId: string;
31
38
  }): Promise<void>;
32
- createFile(fileData: {
33
- id: string;
34
- name: string;
35
- type: string;
36
- key: string;
37
- size: number;
38
- metadata: Record<string, any>;
39
- }): Promise<void>;
40
39
  }
41
40
 
42
41
  export type { AuthRepository };
@@ -1,8 +1,15 @@
1
- interface AuthRepository {
1
+ interface AuthRepository<TFile = unknown> {
2
2
  findCredentialById(id: string): Promise<{
3
+ id: string;
3
4
  password: string;
4
5
  userId: string;
5
6
  } | undefined>;
7
+ createCredential(params: {
8
+ id: string;
9
+ password: string;
10
+ userId: string;
11
+ }): Promise<void>;
12
+ updatePassword(id: string, hashedPassword: string): Promise<void>;
6
13
  findUserById(userId: string): Promise<{
7
14
  id: string;
8
15
  role: string;
@@ -13,9 +20,9 @@ interface AuthRepository {
13
20
  createUser(userData: {
14
21
  id: string;
15
22
  role: string;
16
- profileImageId: string | null;
17
23
  name: string;
18
24
  email: string;
25
+ profileImage?: TFile;
19
26
  }): Promise<{
20
27
  id: string;
21
28
  role: string;
@@ -24,19 +31,11 @@ interface AuthRepository {
24
31
  findThirdPartyAuth(provider: string, providerId: string): Promise<{
25
32
  userId: string;
26
33
  } | undefined>;
27
- createThirdPartyAuth(authData: {
34
+ createThirdPartyAuth(params: {
28
35
  id: string;
29
36
  provider: string;
30
37
  userId: string;
31
38
  }): Promise<void>;
32
- createFile(fileData: {
33
- id: string;
34
- name: string;
35
- type: string;
36
- key: string;
37
- size: number;
38
- metadata: Record<string, any>;
39
- }): Promise<void>;
40
39
  }
41
40
 
42
41
  export type { AuthRepository };
@@ -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,22 +1,22 @@
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>;
@@ -24,7 +24,7 @@ declare class AuthService {
24
24
  getAccessTokenFromCookies(request: Request): Promise<any>;
25
25
  getRefreshTokenFromCookies(request: Request): Promise<any>;
26
26
  refresh(request: Request): Promise<jose.JWTPayload | undefined>;
27
- signIn({ id, password }: {
27
+ login({ id, password }: {
28
28
  id: string;
29
29
  password: string;
30
30
  }): Promise<{
@@ -58,17 +58,6 @@ declare class AuthService {
58
58
  name: string;
59
59
  refreshToken: string | null;
60
60
  } | undefined>;
61
- getOrCreateUser(provider: string, info: {
62
- id: string;
63
- email: string;
64
- name?: string;
65
- picture?: string;
66
- }): Promise<{
67
- id: string;
68
- role: string;
69
- name: string;
70
- }>;
71
- protected savePicture(picture?: string): Promise<string | undefined>;
72
61
  }
73
62
 
74
63
  export { ACCESS_TOKEN_COOKIE, ACCESS_TOKEN_KEY, AuthService, REFRESH_TOKEN_COOKIE, REFRESH_TOKEN_KEY };
@@ -1,22 +1,22 @@
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>;
@@ -24,7 +24,7 @@ declare class AuthService {
24
24
  getAccessTokenFromCookies(request: Request): Promise<any>;
25
25
  getRefreshTokenFromCookies(request: Request): Promise<any>;
26
26
  refresh(request: Request): Promise<jose.JWTPayload | undefined>;
27
- signIn({ id, password }: {
27
+ login({ id, password }: {
28
28
  id: string;
29
29
  password: string;
30
30
  }): Promise<{
@@ -58,17 +58,6 @@ declare class AuthService {
58
58
  name: string;
59
59
  refreshToken: string | null;
60
60
  } | undefined>;
61
- getOrCreateUser(provider: string, info: {
62
- id: string;
63
- email: string;
64
- name?: string;
65
- picture?: string;
66
- }): Promise<{
67
- id: string;
68
- role: string;
69
- name: string;
70
- }>;
71
- protected savePicture(picture?: string): Promise<string | undefined>;
72
61
  }
73
62
 
74
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
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) {
@@ -106,7 +105,7 @@ var AuthService = class {
106
105
  refreshToken
107
106
  );
108
107
  await this.getAccessTokenSetCookie(refreshedAccessToken);
109
- const payload = this.JWT_MANAGER.decode(refreshedAccessToken);
108
+ const payload = this.jwtManager.decode(refreshedAccessToken);
110
109
  if (payload) {
111
110
  return payload;
112
111
  }
@@ -118,15 +117,15 @@ var AuthService = class {
118
117
  }
119
118
  }
120
119
  }
121
- async signIn({ id, password }) {
122
- const credential = await this.repository.findCredentialById(id);
120
+ async login({ id, password }) {
121
+ const credential = await this.authRepository.findCredentialById(id);
123
122
  if (!credential) {
124
123
  throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
125
124
  }
126
125
  if (!await import_bcryptjs.default.compare(password, credential.password)) {
127
126
  throw Error("\uC544\uC774\uB514 \uB610\uB294 \uBE44\uBC00\uBC88\uD638\uAC00 \uD2C0\uB838\uC2B5\uB2C8\uB2E4.");
128
127
  }
129
- const user = await this.repository.findUserById(credential.userId);
128
+ const user = await this.authRepository.findUserById(credential.userId);
130
129
  if (!user) {
131
130
  throw Error("\uD68C\uC6D0 \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
132
131
  }
@@ -137,19 +136,19 @@ var AuthService = class {
137
136
  };
138
137
  }
139
138
  async issueAccessToken(user) {
140
- return this.JWT_MANAGER.signAccessToken({
139
+ return this.jwtManager.signAccessToken({
141
140
  userId: user.id,
142
141
  role: user.role,
143
142
  name: user.name
144
143
  });
145
144
  }
146
145
  async issueTokenPair(user) {
147
- const refreshToken = await this.JWT_MANAGER.signRefreshToken({
146
+ const refreshToken = await this.jwtManager.signRefreshToken({
148
147
  userId: user.id,
149
148
  role: user.role,
150
149
  name: user.name
151
150
  });
152
- await this.repository.updateUserRefreshToken(
151
+ await this.authRepository.updateUserRefreshToken(
153
152
  user.id,
154
153
  await import_bcryptjs.default.hash(refreshToken, 10)
155
154
  );
@@ -157,7 +156,7 @@ var AuthService = class {
157
156
  return { refreshToken, accessToken };
158
157
  }
159
158
  async refreshAccessToken(refreshToken) {
160
- const payload = await this.JWT_MANAGER.verifyRefreshToken(refreshToken);
159
+ const payload = await this.jwtManager.verifyRefreshToken(refreshToken);
161
160
  if (!payload) {
162
161
  throw new Error("\uD1A0\uD070\uC774 \uC720\uD6A8\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.");
163
162
  }
@@ -165,7 +164,7 @@ var AuthService = class {
165
164
  if (typeof userId !== "string") {
166
165
  throw new Error("\uD1A0\uD070\uC774 \uC704\uC870\uB418\uC5C8\uC2B5\uB2C8\uB2E4.");
167
166
  }
168
- const user = await this.repository.findUserById(userId);
167
+ const user = await this.authRepository.findUserById(userId);
169
168
  if (!user) {
170
169
  throw Error("\uC774\uC6A9\uC790\uB97C \uCC3E\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4.");
171
170
  }
@@ -180,78 +179,26 @@ var AuthService = class {
180
179
  }
181
180
  async getAccessTokenSetCookie(accessToken) {
182
181
  return ACCESS_TOKEN_COOKIE.serialize(accessToken, {
183
- expires: accessToken ? this.JWT_MANAGER.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
182
+ expires: accessToken ? this.jwtManager.getExpirationTime(accessToken) : /* @__PURE__ */ new Date(0)
184
183
  });
185
184
  }
186
185
  async getRefreshTokenSetCookie(refreshToken) {
187
186
  return REFRESH_TOKEN_COOKIE.serialize(refreshToken, {
188
- expires: refreshToken ? this.JWT_MANAGER.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
187
+ expires: refreshToken ? this.jwtManager.getExpirationTime(refreshToken) : /* @__PURE__ */ new Date(0)
189
188
  });
190
189
  }
191
190
  async findUser(provider, info) {
192
- const thirdPartyAuth = await this.repository.findThirdPartyAuth(
191
+ const thirdPartyAuth = await this.authRepository.findThirdPartyAuth(
193
192
  provider,
194
193
  info.id
195
194
  );
196
195
  if (thirdPartyAuth) {
197
- const user = await this.repository.findUserById(thirdPartyAuth.userId);
196
+ const user = await this.authRepository.findUserById(thirdPartyAuth.userId);
198
197
  if (user) {
199
198
  return user;
200
199
  }
201
200
  }
202
201
  }
203
- async getOrCreateUser(provider, info) {
204
- const thirdPartyAuth = await this.repository.findThirdPartyAuth(
205
- provider,
206
- info.id
207
- );
208
- if (thirdPartyAuth) {
209
- const user = await this.repository.findUserById(thirdPartyAuth.userId);
210
- if (user) {
211
- return user;
212
- }
213
- }
214
- const userId = (0, import_uuid.v4)();
215
- const email = info.email;
216
- const name = info.name || "\uC775\uBA85";
217
- const picture = info.picture;
218
- const profileImageId = await this.savePicture(picture) || null;
219
- const result = await this.repository.createUser({
220
- id: userId,
221
- role: "user",
222
- profileImageId,
223
- name,
224
- email
225
- });
226
- await this.repository.createThirdPartyAuth({
227
- id: info.id,
228
- provider,
229
- userId
230
- });
231
- return result;
232
- }
233
- async savePicture(picture) {
234
- if (!picture) {
235
- return;
236
- }
237
- const res = await fetch(picture);
238
- if (!res.ok) {
239
- return;
240
- }
241
- const buffer = await res.arrayBuffer();
242
- const id = (0, import_uuid.v4)();
243
- const key = `/users/${id}/picture`;
244
- await this.OBJECT_STORAGE.put(key, Buffer.from(buffer));
245
- await this.repository.createFile({
246
- id,
247
- name: "picture",
248
- type: "image/*",
249
- key,
250
- size: buffer.byteLength,
251
- metadata: {}
252
- });
253
- return id;
254
- }
255
202
  };
256
203
  // Annotate the CommonJS export names for ESM import in node:
257
204
  0 && (module.exports = {