sa2kit 2.0.1 → 2.0.3

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 (278) hide show
  1. package/README.md +1 -1
  2. package/dist/CollisionBalls-BpHufX3H.d.mts +41 -0
  3. package/dist/CollisionBalls-BpHufX3H.d.ts +41 -0
  4. package/dist/ConfigService-BxK06xP6.d.mts +262 -0
  5. package/dist/ConfigService-BxK06xP6.d.ts +262 -0
  6. package/dist/UniversalFileService-BpvbZitV.d.mts +139 -0
  7. package/dist/UniversalFileService-GsP6D3Rc.d.ts +139 -0
  8. package/dist/audioDetection/index.d.mts +449 -0
  9. package/dist/audioDetection/index.d.ts +449 -0
  10. package/dist/audioDetection/index.js +1244 -0
  11. package/dist/audioDetection/index.js.map +1 -0
  12. package/dist/audioDetection/index.mjs +1227 -0
  13. package/dist/audioDetection/index.mjs.map +1 -0
  14. package/dist/auth/legacy/core/index.d.mts +42 -0
  15. package/dist/auth/legacy/core/index.d.ts +42 -0
  16. package/dist/auth/legacy/core/index.js +242 -0
  17. package/dist/auth/legacy/core/index.js.map +1 -0
  18. package/dist/auth/legacy/core/index.mjs +226 -0
  19. package/dist/auth/legacy/core/index.mjs.map +1 -0
  20. package/dist/auth/legacy/db/index.d.mts +5 -0
  21. package/dist/auth/legacy/db/index.d.ts +5 -0
  22. package/dist/auth/legacy/db/index.js +261 -0
  23. package/dist/auth/legacy/db/index.js.map +1 -0
  24. package/dist/auth/legacy/db/index.mjs +250 -0
  25. package/dist/auth/legacy/db/index.mjs.map +1 -0
  26. package/dist/auth/legacy/index.d.mts +5 -0
  27. package/dist/auth/legacy/index.d.ts +5 -0
  28. package/dist/auth/legacy/index.js +1107 -0
  29. package/dist/auth/legacy/index.js.map +1 -0
  30. package/dist/auth/legacy/index.mjs +1086 -0
  31. package/dist/auth/legacy/index.mjs.map +1 -0
  32. package/dist/auth/legacy/logic/index.d.mts +9 -0
  33. package/dist/auth/legacy/logic/index.d.ts +9 -0
  34. package/dist/auth/legacy/logic/index.js +194 -0
  35. package/dist/auth/legacy/logic/index.js.map +1 -0
  36. package/dist/auth/legacy/logic/index.mjs +187 -0
  37. package/dist/auth/legacy/logic/index.mjs.map +1 -0
  38. package/dist/auth/legacy/miniapp/index.d.mts +5 -0
  39. package/dist/auth/legacy/miniapp/index.d.ts +5 -0
  40. package/dist/auth/legacy/miniapp/index.js +506 -0
  41. package/dist/auth/legacy/miniapp/index.js.map +1 -0
  42. package/dist/auth/legacy/miniapp/index.mjs +487 -0
  43. package/dist/auth/legacy/miniapp/index.mjs.map +1 -0
  44. package/dist/auth/legacy/routes/index.d.mts +53 -0
  45. package/dist/auth/legacy/routes/index.d.ts +53 -0
  46. package/dist/auth/legacy/routes/index.js +278 -0
  47. package/dist/auth/legacy/routes/index.js.map +1 -0
  48. package/dist/auth/legacy/routes/index.mjs +271 -0
  49. package/dist/auth/legacy/routes/index.mjs.map +1 -0
  50. package/dist/auth/legacy/schema/index.d.mts +401 -0
  51. package/dist/auth/legacy/schema/index.d.ts +401 -0
  52. package/dist/auth/legacy/schema/index.js +50 -0
  53. package/dist/auth/legacy/schema/index.js.map +1 -0
  54. package/dist/auth/legacy/schema/index.mjs +44 -0
  55. package/dist/auth/legacy/schema/index.mjs.map +1 -0
  56. package/dist/auth/legacy/server/index.d.mts +13 -0
  57. package/dist/auth/legacy/server/index.d.ts +13 -0
  58. package/dist/auth/legacy/server/index.js +21 -0
  59. package/dist/auth/legacy/server/index.js.map +1 -0
  60. package/dist/auth/legacy/server/index.mjs +19 -0
  61. package/dist/auth/legacy/server/index.mjs.map +1 -0
  62. package/dist/auth/legacy/services/index.d.mts +40 -0
  63. package/dist/auth/legacy/services/index.d.ts +40 -0
  64. package/dist/auth/legacy/services/index.js +258 -0
  65. package/dist/auth/legacy/services/index.js.map +1 -0
  66. package/dist/auth/legacy/services/index.mjs +252 -0
  67. package/dist/auth/legacy/services/index.mjs.map +1 -0
  68. package/dist/auth/legacy/ui/miniapp/index.d.mts +10 -0
  69. package/dist/auth/legacy/ui/miniapp/index.d.ts +10 -0
  70. package/dist/auth/legacy/ui/miniapp/index.js +298 -0
  71. package/dist/auth/legacy/ui/miniapp/index.js.map +1 -0
  72. package/dist/auth/legacy/ui/miniapp/index.mjs +290 -0
  73. package/dist/auth/legacy/ui/miniapp/index.mjs.map +1 -0
  74. package/dist/auth/legacy/ui/web/index.d.mts +22 -0
  75. package/dist/auth/legacy/ui/web/index.d.ts +22 -0
  76. package/dist/auth/legacy/ui/web/index.js +899 -0
  77. package/dist/auth/legacy/ui/web/index.js.map +1 -0
  78. package/dist/auth/legacy/ui/web/index.mjs +889 -0
  79. package/dist/auth/legacy/ui/web/index.mjs.map +1 -0
  80. package/dist/auth/legacy/web/index.d.mts +5 -0
  81. package/dist/auth/legacy/web/index.d.ts +5 -0
  82. package/dist/auth/legacy/web/index.js +1107 -0
  83. package/dist/auth/legacy/web/index.js.map +1 -0
  84. package/dist/auth/legacy/web/index.mjs +1086 -0
  85. package/dist/auth/legacy/web/index.mjs.map +1 -0
  86. package/dist/auth/rn/index.d.mts +64 -0
  87. package/dist/auth/rn/index.d.ts +64 -0
  88. package/dist/auth/rn/index.js +765 -0
  89. package/dist/auth/rn/index.js.map +1 -0
  90. package/dist/auth/rn/index.mjs +754 -0
  91. package/dist/auth/rn/index.mjs.map +1 -0
  92. package/dist/base-api-client-ACKKt13v.d.mts +277 -0
  93. package/dist/base-api-client-ACKKt13v.d.ts +277 -0
  94. package/dist/boothVaultService-Cn4WPhjg.d.mts +83 -0
  95. package/dist/boothVaultService-Cn4WPhjg.d.ts +83 -0
  96. package/dist/business/index.d.mts +6 -0
  97. package/dist/business/index.d.ts +6 -0
  98. package/dist/business/index.js +1682 -0
  99. package/dist/business/index.js.map +1 -0
  100. package/dist/business/index.mjs +1675 -0
  101. package/dist/business/index.mjs.map +1 -0
  102. package/dist/calendar/index.d.mts +1325 -0
  103. package/dist/calendar/index.d.ts +1325 -0
  104. package/dist/calendar/index.js +5964 -0
  105. package/dist/calendar/index.js.map +1 -0
  106. package/dist/calendar/index.mjs +5878 -0
  107. package/dist/calendar/index.mjs.map +1 -0
  108. package/dist/calendar/routes/index.d.mts +118 -0
  109. package/dist/calendar/routes/index.d.ts +118 -0
  110. package/dist/calendar/routes/index.js +755 -0
  111. package/dist/calendar/routes/index.js.map +1 -0
  112. package/dist/calendar/routes/index.mjs +747 -0
  113. package/dist/calendar/routes/index.mjs.map +1 -0
  114. package/dist/components/index.d.mts +405 -0
  115. package/dist/components/index.d.ts +405 -0
  116. package/dist/components/index.js +2516 -0
  117. package/dist/components/index.js.map +1 -0
  118. package/dist/components/index.mjs +2396 -0
  119. package/dist/components/index.mjs.map +1 -0
  120. package/dist/drizzle-schema-BNhqj2AZ.d.mts +1114 -0
  121. package/dist/drizzle-schema-BNhqj2AZ.d.ts +1114 -0
  122. package/dist/festivalCard/index.d.mts +76 -0
  123. package/dist/festivalCard/index.d.ts +76 -0
  124. package/dist/festivalCard/index.js +1492 -0
  125. package/dist/festivalCard/index.js.map +1 -0
  126. package/dist/festivalCard/index.mjs +1475 -0
  127. package/dist/festivalCard/index.mjs.map +1 -0
  128. package/dist/festivalCard/routes/index.d.mts +42 -0
  129. package/dist/festivalCard/routes/index.d.ts +42 -0
  130. package/dist/festivalCard/routes/index.js +361 -0
  131. package/dist/festivalCard/routes/index.js.map +1 -0
  132. package/dist/festivalCard/routes/index.mjs +356 -0
  133. package/dist/festivalCard/routes/index.mjs.map +1 -0
  134. package/dist/festivalCard/server/index.d.mts +120 -0
  135. package/dist/festivalCard/server/index.d.ts +120 -0
  136. package/dist/festivalCard/server/index.js +272 -0
  137. package/dist/festivalCard/server/index.js.map +1 -0
  138. package/dist/festivalCard/server/index.mjs +265 -0
  139. package/dist/festivalCard/server/index.mjs.map +1 -0
  140. package/dist/festivalCardService-BFCRhJrq.d.ts +13 -0
  141. package/dist/festivalCardService-GriR2VMc.d.mts +13 -0
  142. package/dist/index-1Ag7IBXN.d.ts +144 -0
  143. package/dist/index-DNKZ7-R_.d.mts +184 -0
  144. package/dist/index-DNKZ7-R_.d.ts +184 -0
  145. package/dist/index-DSel44Ke.d.mts +93 -0
  146. package/dist/index-DSel44Ke.d.ts +93 -0
  147. package/dist/index-DdeZSeTJ.d.mts +144 -0
  148. package/dist/index-DrPcMJPc.d.mts +250 -0
  149. package/dist/index-DrPcMJPc.d.ts +250 -0
  150. package/dist/index.d.mts +5334 -0
  151. package/dist/index.d.ts +5334 -0
  152. package/dist/index.js +18809 -0
  153. package/dist/index.js.map +1 -0
  154. package/dist/index.mjs +18533 -0
  155. package/dist/index.mjs.map +1 -0
  156. package/dist/mikuContest/ui/web/index.d.mts +2 -0
  157. package/dist/mikuContest/ui/web/index.d.ts +2 -0
  158. package/dist/mikuContest/ui/web/index.js +353 -0
  159. package/dist/mikuContest/ui/web/index.js.map +1 -0
  160. package/dist/mikuContest/ui/web/index.mjs +343 -0
  161. package/dist/mikuContest/ui/web/index.mjs.map +1 -0
  162. package/dist/mikuFireworks3D/index.d.mts +268 -0
  163. package/dist/mikuFireworks3D/index.d.ts +268 -0
  164. package/dist/mikuFireworks3D/index.js +1267 -0
  165. package/dist/mikuFireworks3D/index.js.map +1 -0
  166. package/dist/mikuFireworks3D/index.mjs +1228 -0
  167. package/dist/mikuFireworks3D/index.mjs.map +1 -0
  168. package/dist/mikuFusionGame/index.d.mts +117 -0
  169. package/dist/mikuFusionGame/index.d.ts +117 -0
  170. package/dist/mikuFusionGame/index.js +1208 -0
  171. package/dist/mikuFusionGame/index.js.map +1 -0
  172. package/dist/mikuFusionGame/index.mjs +1195 -0
  173. package/dist/mikuFusionGame/index.mjs.map +1 -0
  174. package/dist/mmd/admin/index.d.mts +487 -0
  175. package/dist/mmd/admin/index.d.ts +487 -0
  176. package/dist/mmd/admin/index.js +1058 -0
  177. package/dist/mmd/admin/index.js.map +1 -0
  178. package/dist/mmd/admin/index.mjs +1027 -0
  179. package/dist/mmd/admin/index.mjs.map +1 -0
  180. package/dist/mmd/index.d.mts +2467 -0
  181. package/dist/mmd/index.d.ts +2467 -0
  182. package/dist/mmd/index.js +10119 -0
  183. package/dist/mmd/index.js.map +1 -0
  184. package/dist/mmd/index.mjs +10028 -0
  185. package/dist/mmd/index.mjs.map +1 -0
  186. package/dist/mmd/server/index.d.mts +139 -0
  187. package/dist/mmd/server/index.d.ts +139 -0
  188. package/dist/mmd/server/index.js +424 -0
  189. package/dist/mmd/server/index.js.map +1 -0
  190. package/dist/mmd/server/index.mjs +404 -0
  191. package/dist/mmd/server/index.mjs.map +1 -0
  192. package/dist/music/index.d.mts +74 -0
  193. package/dist/music/index.d.ts +74 -0
  194. package/dist/music/index.js +830 -0
  195. package/dist/music/index.js.map +1 -0
  196. package/dist/music/index.mjs +809 -0
  197. package/dist/music/index.mjs.map +1 -0
  198. package/dist/music/server/index.d.mts +1 -0
  199. package/dist/music/server/index.d.ts +1 -0
  200. package/dist/music/server/index.js +194 -0
  201. package/dist/music/server/index.js.map +1 -0
  202. package/dist/music/server/index.mjs +182 -0
  203. package/dist/music/server/index.mjs.map +1 -0
  204. package/dist/navigation/index.d.mts +93 -0
  205. package/dist/navigation/index.d.ts +93 -0
  206. package/dist/navigation/index.js +453 -0
  207. package/dist/navigation/index.js.map +1 -0
  208. package/dist/navigation/index.mjs +443 -0
  209. package/dist/navigation/index.mjs.map +1 -0
  210. package/dist/portfolio/index.d.mts +66 -0
  211. package/dist/portfolio/index.d.ts +66 -0
  212. package/dist/portfolio/index.js +736 -0
  213. package/dist/portfolio/index.js.map +1 -0
  214. package/dist/portfolio/index.mjs +724 -0
  215. package/dist/portfolio/index.mjs.map +1 -0
  216. package/dist/qqbot/server/index.d.mts +216 -0
  217. package/dist/qqbot/server/index.d.ts +216 -0
  218. package/dist/qqbot/server/index.js +394 -0
  219. package/dist/qqbot/server/index.js.map +1 -0
  220. package/dist/qqbot/server/index.mjs +385 -0
  221. package/dist/qqbot/server/index.mjs.map +1 -0
  222. package/dist/qqbot/ui/web/index.d.mts +10 -0
  223. package/dist/qqbot/ui/web/index.d.ts +10 -0
  224. package/dist/qqbot/ui/web/index.js +105 -0
  225. package/dist/qqbot/ui/web/index.js.map +1 -0
  226. package/dist/qqbot/ui/web/index.mjs +99 -0
  227. package/dist/qqbot/ui/web/index.mjs.map +1 -0
  228. package/dist/screenReceiver/index.d.mts +86 -0
  229. package/dist/screenReceiver/index.d.ts +86 -0
  230. package/dist/screenReceiver/index.js +281 -0
  231. package/dist/screenReceiver/index.js.map +1 -0
  232. package/dist/screenReceiver/index.mjs +273 -0
  233. package/dist/screenReceiver/index.mjs.map +1 -0
  234. package/dist/testYourself/admin/index.d.mts +58 -0
  235. package/dist/testYourself/admin/index.d.ts +58 -0
  236. package/dist/testYourself/admin/index.js +1009 -0
  237. package/dist/testYourself/admin/index.js.map +1 -0
  238. package/dist/testYourself/admin/index.mjs +1002 -0
  239. package/dist/testYourself/admin/index.mjs.map +1 -0
  240. package/dist/testYourself/index.d.mts +53 -0
  241. package/dist/testYourself/index.d.ts +53 -0
  242. package/dist/testYourself/index.js +2551 -0
  243. package/dist/testYourself/index.js.map +1 -0
  244. package/dist/testYourself/index.mjs +2531 -0
  245. package/dist/testYourself/index.mjs.map +1 -0
  246. package/dist/testYourself/server/index.d.mts +1029 -0
  247. package/dist/testYourself/server/index.d.ts +1029 -0
  248. package/dist/testYourself/server/index.js +825 -0
  249. package/dist/testYourself/server/index.js.map +1 -0
  250. package/dist/testYourself/server/index.mjs +816 -0
  251. package/dist/testYourself/server/index.mjs.map +1 -0
  252. package/dist/types-BTiaMsBz.d.mts +292 -0
  253. package/dist/types-DyG3ZV9V.d.mts +270 -0
  254. package/dist/types-DyG3ZV9V.d.ts +270 -0
  255. package/dist/types-ERmJyjx8.d.ts +292 -0
  256. package/dist/types-HorDyIRv.d.mts +303 -0
  257. package/dist/types-HorDyIRv.d.ts +303 -0
  258. package/dist/types-tQfupO6d.d.mts +70 -0
  259. package/dist/types-tQfupO6d.d.ts +70 -0
  260. package/dist/vocaloidBooth/index.d.mts +64 -0
  261. package/dist/vocaloidBooth/index.d.ts +64 -0
  262. package/dist/vocaloidBooth/index.js +376 -0
  263. package/dist/vocaloidBooth/index.js.map +1 -0
  264. package/dist/vocaloidBooth/index.mjs +362 -0
  265. package/dist/vocaloidBooth/index.mjs.map +1 -0
  266. package/dist/vocaloidBooth/server/index.d.mts +111 -0
  267. package/dist/vocaloidBooth/server/index.d.ts +111 -0
  268. package/dist/vocaloidBooth/server/index.js +247 -0
  269. package/dist/vocaloidBooth/server/index.js.map +1 -0
  270. package/dist/vocaloidBooth/server/index.mjs +237 -0
  271. package/dist/vocaloidBooth/server/index.mjs.map +1 -0
  272. package/dist/vocaloidBooth/web/index.d.mts +3 -0
  273. package/dist/vocaloidBooth/web/index.d.ts +3 -0
  274. package/dist/vocaloidBooth/web/index.js +376 -0
  275. package/dist/vocaloidBooth/web/index.js.map +1 -0
  276. package/dist/vocaloidBooth/web/index.mjs +362 -0
  277. package/dist/vocaloidBooth/web/index.mjs.map +1 -0
  278. package/package.json +11 -1
@@ -0,0 +1,754 @@
1
+ import React2, { useState, useEffect, useCallback } from 'react';
2
+
3
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
4
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
5
+ }) : x)(function(x) {
6
+ if (typeof require !== "undefined") return require.apply(this, arguments);
7
+ throw Error('Dynamic require of "' + x + '" is not supported');
8
+ });
9
+
10
+ // src/common/auth/client/types.ts
11
+ var STORAGE_KEYS = {
12
+ AUTH_TOKEN: "auth_token",
13
+ USER_DATA: "user_data"
14
+ };
15
+ var API_ROUTES = {
16
+ AUTH: {
17
+ LOGIN: "/auth/login",
18
+ REGISTER: "/auth/register",
19
+ LOGOUT: "/auth/logout",
20
+ ME: "/auth/me"
21
+ }
22
+ };
23
+
24
+ // src/common/auth/client/base-api-client.ts
25
+ var BaseApiClient = class {
26
+ constructor(storage, request, baseUrl) {
27
+ this.storage = storage;
28
+ this.request = request;
29
+ this.baseUrl = baseUrl;
30
+ this.token = null;
31
+ this.user = null;
32
+ }
33
+ /**
34
+ * 初始化 - 从存储中加载 token 和用户信息
35
+ */
36
+ async init() {
37
+ try {
38
+ this.token = await this.storage.getItem(STORAGE_KEYS.AUTH_TOKEN);
39
+ const userData = await this.storage.getItem(STORAGE_KEYS.USER_DATA);
40
+ if (userData) {
41
+ this.user = JSON.parse(userData);
42
+ }
43
+ } catch (error) {
44
+ console.error("Failed to load auth data:", error);
45
+ }
46
+ }
47
+ /**
48
+ * 设置认证 token
49
+ */
50
+ async setToken(token) {
51
+ this.token = token;
52
+ if (token) {
53
+ await this.storage.setItem(STORAGE_KEYS.AUTH_TOKEN, token);
54
+ } else {
55
+ await this.storage.removeItem(STORAGE_KEYS.AUTH_TOKEN);
56
+ }
57
+ }
58
+ /**
59
+ * 设置用户信息
60
+ */
61
+ async setUser(user) {
62
+ this.user = user;
63
+ if (user) {
64
+ await this.storage.setItem(STORAGE_KEYS.USER_DATA, JSON.stringify(user));
65
+ } else {
66
+ await this.storage.removeItem(STORAGE_KEYS.USER_DATA);
67
+ }
68
+ }
69
+ /**
70
+ * 获取当前 token
71
+ */
72
+ getToken() {
73
+ return this.token;
74
+ }
75
+ /**
76
+ * 获取当前用户
77
+ */
78
+ getUser() {
79
+ return this.user;
80
+ }
81
+ /**
82
+ * 检查是否已登录
83
+ */
84
+ async isAuthenticated() {
85
+ return !!this.token;
86
+ }
87
+ /**
88
+ * 清除用户数据
89
+ */
90
+ async clearUserData() {
91
+ await this.storage.removeItem(STORAGE_KEYS.AUTH_TOKEN);
92
+ await this.storage.removeItem(STORAGE_KEYS.USER_DATA);
93
+ this.token = null;
94
+ this.user = null;
95
+ }
96
+ /**
97
+ * 发送请求的通用方法
98
+ */
99
+ async sendRequest(config) {
100
+ try {
101
+ const headers = {
102
+ "Content-Type": "application/json",
103
+ ...config.headers || {}
104
+ };
105
+ if (this.token) {
106
+ headers["Authorization"] = "Bearer " + this.token;
107
+ }
108
+ const response = await this.request.request({
109
+ ...config,
110
+ url: this.baseUrl + config.url,
111
+ headers
112
+ });
113
+ return response;
114
+ } catch (error) {
115
+ console.error("API request error:", error);
116
+ return {
117
+ success: false,
118
+ error: error instanceof Error ? error.message : "\u7F51\u7EDC\u9519\u8BEF\uFF0C\u8BF7\u91CD\u8BD5"
119
+ };
120
+ }
121
+ }
122
+ // ==================== 认证相关 API ====================
123
+ /**
124
+ * 用户注册
125
+ */
126
+ async register(email, password, username) {
127
+ const response = await this.sendRequest({
128
+ url: API_ROUTES.AUTH.REGISTER,
129
+ method: "POST",
130
+ body: { email, password, username }
131
+ });
132
+ if (response.success && response.data) {
133
+ await this.setToken(response.data.token);
134
+ await this.setUser(response.data.user);
135
+ }
136
+ return response;
137
+ }
138
+ /**
139
+ * 用户登录
140
+ */
141
+ async login(email, password) {
142
+ const response = await this.sendRequest({
143
+ url: API_ROUTES.AUTH.LOGIN,
144
+ method: "POST",
145
+ body: { email, password }
146
+ });
147
+ if (response.success && response.data) {
148
+ await this.setToken(response.data.token);
149
+ await this.setUser(response.data.user);
150
+ if (typeof window !== "undefined") {
151
+ window.dispatchEvent(
152
+ new CustomEvent("user_login_success", {
153
+ detail: {
154
+ userId: response.data.user.id,
155
+ email: response.data.user.email,
156
+ role: response.data.user.role
157
+ }
158
+ })
159
+ );
160
+ }
161
+ }
162
+ return response;
163
+ }
164
+ /**
165
+ * 用户退出登录
166
+ */
167
+ async logout() {
168
+ await this.sendRequest({
169
+ url: API_ROUTES.AUTH.LOGOUT,
170
+ method: "POST"
171
+ });
172
+ await this.clearUserData();
173
+ }
174
+ /**
175
+ * 获取当前用户信息
176
+ */
177
+ async getCurrentUser() {
178
+ const response = await this.sendRequest({
179
+ url: API_ROUTES.AUTH.ME,
180
+ method: "GET"
181
+ });
182
+ if (response.success && response.data) {
183
+ const userData = response.data.user || response.data;
184
+ await this.setUser(userData);
185
+ return {
186
+ ...response,
187
+ data: userData
188
+ };
189
+ }
190
+ return response;
191
+ }
192
+ // ==================== 通用方法 ====================
193
+ /**
194
+ * 发送 GET 请求
195
+ */
196
+ async get(url, params) {
197
+ return this.sendRequest({ url, method: "GET", params });
198
+ }
199
+ /**
200
+ * 发送 POST 请求
201
+ */
202
+ async post(url, body) {
203
+ return this.sendRequest({ url, method: "POST", body });
204
+ }
205
+ /**
206
+ * 发送 PUT 请求
207
+ */
208
+ async put(url, body) {
209
+ return this.sendRequest({ url, method: "PUT", body });
210
+ }
211
+ /**
212
+ * 发送 DELETE 请求
213
+ */
214
+ async delete(url) {
215
+ return this.sendRequest({ url, method: "DELETE" });
216
+ }
217
+ };
218
+
219
+ // src/storage/adapters/react-native-adapter.ts
220
+ var AsyncStorage = null;
221
+ try {
222
+ AsyncStorage = __require("@react-native-async-storage/async-storage").default;
223
+ } catch (e) {
224
+ }
225
+ var ReactNativeStorageAdapter = class {
226
+ constructor() {
227
+ this.listeners = /* @__PURE__ */ new Map();
228
+ }
229
+ async getItem(key) {
230
+ if (!AsyncStorage) return null;
231
+ try {
232
+ return await AsyncStorage.getItem(key);
233
+ } catch (error) {
234
+ console.error('[ReactNativeStorage] Error getting item "' + key + '":', error);
235
+ return null;
236
+ }
237
+ }
238
+ async setItem(key, value) {
239
+ if (!AsyncStorage) {
240
+ throw new Error("AsyncStorage is not available");
241
+ }
242
+ try {
243
+ await AsyncStorage.setItem(key, value);
244
+ this.notifyListeners(key, value);
245
+ } catch (error) {
246
+ console.error('[ReactNativeStorage] Error setting item "' + key + '":', error);
247
+ throw error;
248
+ }
249
+ }
250
+ async removeItem(key) {
251
+ if (!AsyncStorage) {
252
+ throw new Error("AsyncStorage is not available");
253
+ }
254
+ try {
255
+ await AsyncStorage.removeItem(key);
256
+ this.notifyListeners(key, null);
257
+ } catch (error) {
258
+ console.error('[ReactNativeStorage] Error removing item "' + key + '":', error);
259
+ throw error;
260
+ }
261
+ }
262
+ async clear() {
263
+ if (!AsyncStorage) {
264
+ throw new Error("AsyncStorage is not available");
265
+ }
266
+ try {
267
+ await AsyncStorage.clear();
268
+ } catch (error) {
269
+ console.error("[ReactNativeStorage] Error clearing storage:", error);
270
+ throw error;
271
+ }
272
+ }
273
+ addChangeListener(callback) {
274
+ if (!this.listeners.has("*")) {
275
+ this.listeners.set("*", /* @__PURE__ */ new Set());
276
+ }
277
+ this.listeners.get("*").add(callback);
278
+ return () => {
279
+ this.listeners.get("*")?.delete(callback);
280
+ };
281
+ }
282
+ notifyListeners(key, value) {
283
+ const globalListeners = this.listeners.get("*");
284
+ if (globalListeners) {
285
+ globalListeners.forEach((callback) => callback(key, value));
286
+ }
287
+ }
288
+ };
289
+
290
+ // src/request/adapters/react-native-adapter.ts
291
+ var ReactNativeRequestAdapter = class {
292
+ async request(config) {
293
+ const { url, method = "GET", headers = {}, body, params } = config;
294
+ let fullUrl = url;
295
+ if (params) {
296
+ const searchParams = new URLSearchParams();
297
+ Object.entries(params).forEach(([key, value]) => {
298
+ if (value !== void 0 && value !== null) {
299
+ searchParams.append(key, String(value));
300
+ }
301
+ });
302
+ const qs = searchParams.toString();
303
+ if (qs) {
304
+ fullUrl += url.includes("?") ? `&${qs}` : `?${qs}`;
305
+ }
306
+ }
307
+ const response = await fetch(fullUrl, {
308
+ method,
309
+ headers: {
310
+ "Content-Type": "application/json",
311
+ ...headers
312
+ },
313
+ body: body ? JSON.stringify(body) : void 0
314
+ });
315
+ const data = await response.json();
316
+ if (!response.ok) {
317
+ return {
318
+ success: false,
319
+ error: data.error ?? `\u8BF7\u6C42\u5931\u8D25 (${response.status})`
320
+ };
321
+ }
322
+ return data;
323
+ }
324
+ };
325
+
326
+ // src/common/auth/rn/client.ts
327
+ var cached = null;
328
+ var cachedBase = "";
329
+ function createRnAuthClient(authApiBase) {
330
+ const base = authApiBase.replace(/\/+$/, "");
331
+ if (cached && cachedBase === base) {
332
+ return cached;
333
+ }
334
+ const client = new BaseApiClient(
335
+ new ReactNativeStorageAdapter(),
336
+ new ReactNativeRequestAdapter(),
337
+ base
338
+ );
339
+ cached = client;
340
+ cachedBase = base;
341
+ return client;
342
+ }
343
+ async function initRnAuthClient(authApiBase) {
344
+ const client = createRnAuthClient(authApiBase);
345
+ await client.init();
346
+ return client;
347
+ }
348
+ function resetRnAuthClientCache() {
349
+ cached = null;
350
+ cachedBase = "";
351
+ }
352
+
353
+ // src/business/auth-legacy/utils/authUtils.ts
354
+ function validatePhoneNumber(phone) {
355
+ return /^1[3-9]\d{9}$/.test(phone);
356
+ }
357
+
358
+ // src/business/auth-legacy/rn/legacy-login.ts
359
+ async function loginWithLegacyPhone(authApiBase, phone, password) {
360
+ const trimmedPhone = phone.trim();
361
+ if (!trimmedPhone || !password) {
362
+ return { success: false, message: "\u8BF7\u586B\u5199\u624B\u673A\u53F7\u548C\u5BC6\u7801" };
363
+ }
364
+ if (!validatePhoneNumber(trimmedPhone)) {
365
+ return { success: false, message: "\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7" };
366
+ }
367
+ const base = authApiBase.replace(/\/+$/, "");
368
+ const adapter = new ReactNativeRequestAdapter();
369
+ const data = await adapter.request({
370
+ url: `${base}/auth/login`,
371
+ method: "POST",
372
+ body: { phone: trimmedPhone, password }
373
+ });
374
+ if (!data.success) {
375
+ return {
376
+ success: false,
377
+ message: data.message ?? "\u767B\u5F55\u5931\u8D25"
378
+ };
379
+ }
380
+ const token = data.sessionToken ?? data.data?.sessionToken;
381
+ if (!token || token.length < 8) {
382
+ return { success: false, message: "\u767B\u5F55\u6210\u529F\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u4F1A\u8BDD\u4EE4\u724C" };
383
+ }
384
+ return { success: true, token };
385
+ }
386
+ function isPhoneAccount(account) {
387
+ return validatePhoneNumber(account.trim());
388
+ }
389
+ function useAuth(apiClient) {
390
+ const [user, setUser] = useState(null);
391
+ const [isLoggedIn, setIsLoggedIn] = useState(false);
392
+ const [loading, setLoading] = useState(false);
393
+ const [checkingAuth, setCheckingAuth] = useState(true);
394
+ const [error, setError] = useState(null);
395
+ const checkAuthStatus = useCallback(async () => {
396
+ try {
397
+ setCheckingAuth(true);
398
+ setError(null);
399
+ const isAuth = await apiClient.isAuthenticated();
400
+ if (isAuth) {
401
+ const response = await apiClient.getCurrentUser();
402
+ if (response.success && response.data) {
403
+ setUser(response.data);
404
+ setIsLoggedIn(true);
405
+ } else {
406
+ await apiClient.clearUserData();
407
+ setUser(null);
408
+ setIsLoggedIn(false);
409
+ }
410
+ } else {
411
+ setUser(null);
412
+ setIsLoggedIn(false);
413
+ }
414
+ } catch (err) {
415
+ console.error("\u68C0\u67E5\u767B\u5F55\u72B6\u6001\u5931\u8D25:", err);
416
+ setError(err instanceof Error ? err.message : "\u68C0\u67E5\u767B\u5F55\u72B6\u6001\u5931\u8D25");
417
+ setUser(null);
418
+ setIsLoggedIn(false);
419
+ } finally {
420
+ setCheckingAuth(false);
421
+ }
422
+ }, [apiClient]);
423
+ const login = useCallback(
424
+ async (email, password) => {
425
+ setLoading(true);
426
+ setError(null);
427
+ try {
428
+ const response = await apiClient.login(email, password);
429
+ if (response.success && response.data) {
430
+ setUser(response.data.user);
431
+ setIsLoggedIn(true);
432
+ return { success: true };
433
+ } else {
434
+ const errorMsg = response.error || "\u767B\u5F55\u5931\u8D25";
435
+ setError(errorMsg);
436
+ return { success: false, error: errorMsg };
437
+ }
438
+ } catch (err) {
439
+ const errorMsg = err instanceof Error ? err.message : "\u767B\u5F55\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5";
440
+ setError(errorMsg);
441
+ return { success: false, error: errorMsg };
442
+ } finally {
443
+ setLoading(false);
444
+ }
445
+ },
446
+ [apiClient]
447
+ );
448
+ const register = useCallback(
449
+ async (email, password, username) => {
450
+ setLoading(true);
451
+ setError(null);
452
+ try {
453
+ const response = await apiClient.register(email, password, username);
454
+ if (response.success && response.data) {
455
+ setUser(response.data.user);
456
+ setIsLoggedIn(true);
457
+ return { success: true };
458
+ } else {
459
+ const errorMsg = response.error || "\u6CE8\u518C\u5931\u8D25";
460
+ setError(errorMsg);
461
+ return { success: false, error: errorMsg };
462
+ }
463
+ } catch (err) {
464
+ const errorMsg = err instanceof Error ? err.message : "\u6CE8\u518C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5";
465
+ setError(errorMsg);
466
+ return { success: false, error: errorMsg };
467
+ } finally {
468
+ setLoading(false);
469
+ }
470
+ },
471
+ [apiClient]
472
+ );
473
+ const logout = useCallback(async () => {
474
+ setLoading(true);
475
+ setError(null);
476
+ try {
477
+ await apiClient.logout();
478
+ setUser(null);
479
+ setIsLoggedIn(false);
480
+ } catch (err) {
481
+ console.error("\u767B\u51FA\u5931\u8D25:", err);
482
+ setError(err instanceof Error ? err.message : "\u767B\u51FA\u5931\u8D25");
483
+ setUser(null);
484
+ setIsLoggedIn(false);
485
+ } finally {
486
+ setLoading(false);
487
+ }
488
+ }, [apiClient]);
489
+ const clearError = useCallback(() => {
490
+ setError(null);
491
+ }, []);
492
+ useEffect(() => {
493
+ checkAuthStatus();
494
+ }, [checkAuthStatus]);
495
+ return {
496
+ // 状态
497
+ user,
498
+ isLoggedIn,
499
+ loading,
500
+ checkingAuth,
501
+ error,
502
+ // 操作方法
503
+ login,
504
+ register,
505
+ logout,
506
+ refresh: checkAuthStatus,
507
+ clearError
508
+ };
509
+ }
510
+
511
+ // src/common/auth/components/LoginForm.tsx
512
+ function LoginForm({ apiClient, onSuccess, onError, children }) {
513
+ const { login, loading, error: authError, clearError } = useAuth(apiClient);
514
+ const [email, setEmail] = useState("");
515
+ const [password, setPassword] = useState("");
516
+ const handleSubmit = async (e) => {
517
+ if (e) {
518
+ e.preventDefault();
519
+ }
520
+ clearError();
521
+ const result = await login(email, password);
522
+ if (result.success) {
523
+ const currentUser = apiClient.getUser();
524
+ if (currentUser) {
525
+ onSuccess?.(currentUser);
526
+ }
527
+ } else {
528
+ onError?.(result.error || "\u767B\u5F55\u5931\u8D25");
529
+ }
530
+ };
531
+ const state = {
532
+ email,
533
+ password,
534
+ loading,
535
+ error: authError,
536
+ handleEmailChange: setEmail,
537
+ handlePasswordChange: setPassword,
538
+ handleSubmit
539
+ };
540
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, children(state));
541
+ }
542
+
543
+ // src/business/auth-legacy/rn/components/AccountLoginForm.tsx
544
+ var ReactNative = __require("react-native");
545
+ var { ActivityIndicator, Pressable, Text, TextInput, View, StyleSheet } = ReactNative;
546
+ var defaultStyles = StyleSheet.create({
547
+ label: { fontSize: 12, color: "#8b98a5", marginBottom: 6, marginTop: 12 },
548
+ input: {
549
+ borderWidth: 1,
550
+ borderColor: "rgba(255,255,255,0.12)",
551
+ borderRadius: 10,
552
+ paddingHorizontal: 12,
553
+ paddingVertical: 10,
554
+ color: "#e8edf2",
555
+ backgroundColor: "rgba(0,0,0,0.2)",
556
+ fontSize: 15
557
+ },
558
+ err: { color: "#f87171", marginTop: 10, fontSize: 14 },
559
+ btn: {
560
+ marginTop: 14,
561
+ paddingVertical: 12,
562
+ borderRadius: 10,
563
+ alignItems: "center",
564
+ borderWidth: 1,
565
+ borderColor: "rgba(255,255,255,0.12)",
566
+ backgroundColor: "rgba(255,255,255,0.08)"
567
+ },
568
+ primary: { backgroundColor: "#3d9eff", borderColor: "transparent" },
569
+ disabled: { opacity: 0.6 },
570
+ btnTextPrimary: { color: "#fff", fontSize: 15, fontWeight: "600" },
571
+ centerInline: { paddingVertical: 24, alignItems: "center" }
572
+ });
573
+ var DEFAULT_LABELS = {
574
+ authApiBase: "\u8BA4\u8BC1 API \u6839\u5730\u5740\uFF08\u542B /api\uFF09",
575
+ phone: "\u624B\u673A\u53F7",
576
+ email: "\u90AE\u7BB1",
577
+ password: "\u5BC6\u7801",
578
+ submit: "\u767B\u5F55"
579
+ };
580
+ function RnAccountLoginForm({
581
+ authApiBase,
582
+ defaultAuthApiBase = "",
583
+ onAuthApiBaseChange,
584
+ submitting = false,
585
+ error = "",
586
+ onError,
587
+ onSuccess,
588
+ theme,
589
+ labels: labelsProp,
590
+ placeholders
591
+ }) {
592
+ const labels = { ...DEFAULT_LABELS, ...labelsProp };
593
+ const [apiClient, setApiClient] = useState(null);
594
+ const [account, setAccount] = useState("");
595
+ const [password, setPassword] = useState("");
596
+ const [useLegacyPhone, setUseLegacyPhone] = useState(true);
597
+ useEffect(() => {
598
+ let cancelled = false;
599
+ const base = authApiBase.trim() || defaultAuthApiBase;
600
+ if (!base) {
601
+ setApiClient(null);
602
+ return;
603
+ }
604
+ resetRnAuthClientCache();
605
+ initRnAuthClient(base).then((c) => {
606
+ if (!cancelled) {
607
+ setApiClient(c);
608
+ }
609
+ });
610
+ return () => {
611
+ cancelled = true;
612
+ };
613
+ }, [authApiBase, defaultAuthApiBase]);
614
+ useEffect(() => {
615
+ const trimmed = account.trim();
616
+ if (!trimmed) {
617
+ setUseLegacyPhone(true);
618
+ return;
619
+ }
620
+ setUseLegacyPhone(isPhoneAccount(trimmed));
621
+ }, [account]);
622
+ const handleLegacySubmit = useCallback(async () => {
623
+ const base = authApiBase.trim() || defaultAuthApiBase;
624
+ onError?.("");
625
+ const result = await loginWithLegacyPhone(base, account, password);
626
+ if (!result.success || !result.token) {
627
+ onError?.(result.message ?? "\u767B\u5F55\u5931\u8D25");
628
+ return;
629
+ }
630
+ await onSuccess(result.token);
631
+ }, [account, authApiBase, defaultAuthApiBase, onError, onSuccess, password]);
632
+ const authApiField = onAuthApiBaseChange ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Text, { style: [defaultStyles.label, theme?.label] }, labels.authApiBase), /* @__PURE__ */ React2.createElement(
633
+ TextInput,
634
+ {
635
+ style: [defaultStyles.input, theme?.input, theme?.inputContainer],
636
+ value: authApiBase,
637
+ onChangeText: onAuthApiBaseChange,
638
+ autoCapitalize: "none",
639
+ autoCorrect: false,
640
+ placeholder: placeholders?.authApiBase ?? defaultAuthApiBase,
641
+ placeholderTextColor: "#6b7a8a"
642
+ }
643
+ )) : null;
644
+ if (!apiClient) {
645
+ return /* @__PURE__ */ React2.createElement(View, { style: [defaultStyles.centerInline, theme?.loadingContainer] }, /* @__PURE__ */ React2.createElement(ActivityIndicator, null));
646
+ }
647
+ if (useLegacyPhone) {
648
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, authApiField, /* @__PURE__ */ React2.createElement(Text, { style: [defaultStyles.label, theme?.label] }, labels.phone), /* @__PURE__ */ React2.createElement(
649
+ TextInput,
650
+ {
651
+ style: [defaultStyles.input, theme?.input, theme?.inputContainer],
652
+ value: account,
653
+ onChangeText: setAccount,
654
+ keyboardType: "phone-pad",
655
+ autoCapitalize: "none",
656
+ autoCorrect: false,
657
+ placeholder: placeholders?.phone ?? "13800138000",
658
+ placeholderTextColor: "#6b7a8a"
659
+ }
660
+ ), /* @__PURE__ */ React2.createElement(Text, { style: [defaultStyles.label, theme?.label] }, labels.password), /* @__PURE__ */ React2.createElement(
661
+ TextInput,
662
+ {
663
+ style: [defaultStyles.input, theme?.input, theme?.inputContainer],
664
+ value: password,
665
+ onChangeText: setPassword,
666
+ secureTextEntry: true,
667
+ autoCapitalize: "none",
668
+ autoCorrect: false,
669
+ placeholder: placeholders?.password ?? "\u5BC6\u7801",
670
+ placeholderTextColor: "#6b7a8a"
671
+ }
672
+ ), error ? /* @__PURE__ */ React2.createElement(Text, { style: [defaultStyles.err, theme?.error] }, error) : null, /* @__PURE__ */ React2.createElement(
673
+ Pressable,
674
+ {
675
+ style: [
676
+ defaultStyles.btn,
677
+ defaultStyles.primary,
678
+ theme?.button,
679
+ theme?.buttonPrimary,
680
+ submitting && (theme?.buttonDisabled ?? defaultStyles.disabled)
681
+ ],
682
+ onPress: handleLegacySubmit,
683
+ disabled: submitting
684
+ },
685
+ submitting ? /* @__PURE__ */ React2.createElement(ActivityIndicator, { color: "#fff" }) : /* @__PURE__ */ React2.createElement(Text, { style: [defaultStyles.btnTextPrimary, theme?.buttonTextPrimary] }, labels.submit)
686
+ ));
687
+ }
688
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, authApiField, /* @__PURE__ */ React2.createElement(
689
+ LoginForm,
690
+ {
691
+ apiClient,
692
+ onSuccess: () => {
693
+ const tok = apiClient.getToken();
694
+ if (tok) {
695
+ void onSuccess(tok);
696
+ } else {
697
+ onError?.("\u767B\u5F55\u6210\u529F\u4F46\u672A\u83B7\u53D6\u5230\u4EE4\u724C");
698
+ }
699
+ },
700
+ onError: (msg) => onError?.(msg)
701
+ },
702
+ ({
703
+ email,
704
+ password: pwd,
705
+ loading,
706
+ error: formErr,
707
+ handleEmailChange,
708
+ handlePasswordChange,
709
+ handleSubmit
710
+ }) => /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Text, { style: [defaultStyles.label, theme?.label] }, labels.email), /* @__PURE__ */ React2.createElement(
711
+ TextInput,
712
+ {
713
+ style: [defaultStyles.input, theme?.input, theme?.inputContainer],
714
+ value: email,
715
+ onChangeText: handleEmailChange,
716
+ keyboardType: "email-address",
717
+ autoCapitalize: "none",
718
+ autoCorrect: false,
719
+ placeholder: placeholders?.email ?? "user@example.com",
720
+ placeholderTextColor: "#6b7a8a"
721
+ }
722
+ ), /* @__PURE__ */ React2.createElement(Text, { style: [defaultStyles.label, theme?.label] }, labels.password), /* @__PURE__ */ React2.createElement(
723
+ TextInput,
724
+ {
725
+ style: [defaultStyles.input, theme?.input, theme?.inputContainer],
726
+ value: pwd,
727
+ onChangeText: handlePasswordChange,
728
+ secureTextEntry: true,
729
+ autoCapitalize: "none",
730
+ autoCorrect: false,
731
+ placeholder: placeholders?.password ?? "\u5BC6\u7801",
732
+ placeholderTextColor: "#6b7a8a"
733
+ }
734
+ ), formErr || error ? /* @__PURE__ */ React2.createElement(Text, { style: [defaultStyles.err, theme?.error] }, formErr ?? error) : null, /* @__PURE__ */ React2.createElement(
735
+ Pressable,
736
+ {
737
+ style: [
738
+ defaultStyles.btn,
739
+ defaultStyles.primary,
740
+ theme?.button,
741
+ theme?.buttonPrimary,
742
+ (loading || submitting) && (theme?.buttonDisabled ?? defaultStyles.disabled)
743
+ ],
744
+ onPress: () => handleSubmit(),
745
+ disabled: loading || submitting
746
+ },
747
+ loading || submitting ? /* @__PURE__ */ React2.createElement(ActivityIndicator, { color: "#fff" }) : /* @__PURE__ */ React2.createElement(Text, { style: [defaultStyles.btnTextPrimary, theme?.buttonTextPrimary] }, labels.submit)
748
+ ))
749
+ ));
750
+ }
751
+
752
+ export { RnAccountLoginForm, createRnAuthClient, initRnAuthClient, isPhoneAccount, loginWithLegacyPhone, resetRnAuthClientCache };
753
+ //# sourceMappingURL=index.mjs.map
754
+ //# sourceMappingURL=index.mjs.map