@pisell/pisellos 0.0.334 → 0.0.336

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.
@@ -0,0 +1,1437 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/solution/RegisterAndLogin/index.ts
21
+ var RegisterAndLogin_exports = {};
22
+ __export(RegisterAndLogin_exports, {
23
+ RegisterAndLoginImpl: () => RegisterAndLoginImpl
24
+ });
25
+ module.exports = __toCommonJS(RegisterAndLogin_exports);
26
+ var import_BaseModule = require("../../modules/BaseModule");
27
+ var import_types = require("./types");
28
+ var import_config = require("./config");
29
+ __reExport(RegisterAndLogin_exports, require("./types"), module.exports);
30
+ __reExport(RegisterAndLogin_exports, require("./config"), module.exports);
31
+ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
32
+ constructor(name, version) {
33
+ super(name, version);
34
+ // 提供给 baseModule 用的默认名称和默认版本
35
+ this.defaultName = "registerAndLogin";
36
+ this.defaultVersion = "1.0.0";
37
+ this.isSolution = true;
38
+ this.otherParams = {};
39
+ this.channel = "default";
40
+ }
41
+ /**
42
+ * 重新发送邮箱注册链接
43
+ */
44
+ async resendEmailRegisterLink() {
45
+ try {
46
+ if (!this.store.emailRegisterLinkCode) {
47
+ const error = "没有找到邮箱注册链接的 code,请先调用 sendEmailRegisterLink";
48
+ this.store.error = error;
49
+ return {
50
+ success: false,
51
+ message: error
52
+ };
53
+ }
54
+ this.store.isLoading = true;
55
+ this.store.error = null;
56
+ const response = await this.apiCaller.call(
57
+ "resendEmailRegisterLink",
58
+ { code: this.store.emailRegisterLinkCode }
59
+ );
60
+ if (response.success) {
61
+ await this.core.effects.emit(
62
+ import_types.RegisterAndLoginHooks.onEmailVerificationSent,
63
+ {
64
+ target: "resend",
65
+ purpose: import_types.VerificationPurpose.REGISTER
66
+ }
67
+ );
68
+ } else {
69
+ this.store.error = response.message || "重新发送注册邀请链接失败";
70
+ await this.core.effects.emit(
71
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
72
+ {
73
+ target: "resend",
74
+ error: this.store.error
75
+ }
76
+ );
77
+ }
78
+ return response;
79
+ } catch (error) {
80
+ this.store.error = "重新发送注册邀请链接失败";
81
+ await this.core.effects.emit(
82
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
83
+ {
84
+ target: "resend",
85
+ error: this.store.error
86
+ }
87
+ );
88
+ return error;
89
+ } finally {
90
+ this.store.isLoading = false;
91
+ }
92
+ }
93
+ /**
94
+ * 邮箱验证码注册
95
+ * @param params 注册参数
96
+ * @returns 注册结果
97
+ */
98
+ async emailCodeRegister(params) {
99
+ try {
100
+ this.store.isLoading = true;
101
+ this.store.error = null;
102
+ await this.core.effects.emit(
103
+ import_types.RegisterAndLoginHooks.onRegisterStarted,
104
+ params
105
+ );
106
+ const response = await this.apiCaller.call(
107
+ "emailCodeRegister",
108
+ params
109
+ );
110
+ if (response.success && response.data) {
111
+ const { user, token, refreshToken, expiresAt } = response.data;
112
+ if (token) {
113
+ this.store.currentUser = user;
114
+ this.store.isLoggedIn = true;
115
+ }
116
+ await this.core.effects.emit(
117
+ import_types.RegisterAndLoginHooks.onRegisterSuccess,
118
+ response.data
119
+ );
120
+ } else {
121
+ this.store.error = response.message || "邮箱验证码注册失败";
122
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
123
+ error: this.store.error,
124
+ params
125
+ });
126
+ }
127
+ return response;
128
+ } catch (error) {
129
+ this.store.error = "邮箱验证码注册失败";
130
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
131
+ error: this.store.error,
132
+ params
133
+ });
134
+ throw error;
135
+ } finally {
136
+ this.store.isLoading = false;
137
+ }
138
+ }
139
+ /**
140
+ * 手机验证码注册
141
+ */
142
+ async phoneCodeRegister(params) {
143
+ try {
144
+ this.store.isLoading = true;
145
+ this.store.error = null;
146
+ await this.core.effects.emit(
147
+ import_types.RegisterAndLoginHooks.onRegisterStarted,
148
+ params
149
+ );
150
+ const response = await this.apiCaller.call(
151
+ "phoneCodeRegister",
152
+ params
153
+ );
154
+ if (response.success && response.data) {
155
+ const { user, token, refreshToken, expiresAt } = response.data;
156
+ if (token) {
157
+ this.store.currentUser = user;
158
+ this.store.isLoggedIn = true;
159
+ }
160
+ await this.core.effects.emit(
161
+ import_types.RegisterAndLoginHooks.onRegisterSuccess,
162
+ response.data
163
+ );
164
+ } else {
165
+ this.store.error = response.message || "注册失败";
166
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
167
+ error: this.store.error,
168
+ params
169
+ });
170
+ }
171
+ return response;
172
+ } catch (error) {
173
+ this.store.error = error.message || "注册失败";
174
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
175
+ error: this.store.error,
176
+ params
177
+ });
178
+ throw error;
179
+ } finally {
180
+ this.store.isLoading = false;
181
+ }
182
+ }
183
+ async initialize(core, options) {
184
+ this.core = core;
185
+ this.store = {
186
+ currentUser: null,
187
+ isLoggedIn: false,
188
+ isLoading: false,
189
+ verificationCodeSent: {},
190
+ oauthConfig: options.oauthConfig || {},
191
+ error: null,
192
+ ...options.store
193
+ };
194
+ this.otherParams = options.otherParams || {};
195
+ this.channel = this.otherParams.channel || "default";
196
+ this.request = core.getPlugin("request");
197
+ this.window = core.getPlugin("window");
198
+ if (!this.request) {
199
+ throw new Error("RegisterAndLogin 模块需要 request 插件支持");
200
+ }
201
+ if (!this.window) {
202
+ throw new Error("RegisterAndLogin 模块需要 window 插件支持");
203
+ }
204
+ this.apiCaller = (0, import_config.createApiCaller)(this.request, this.channel);
205
+ await this.restoreLoginState();
206
+ console.log("[RegisterAndLogin] 初始化完成");
207
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onInited, {});
208
+ }
209
+ /**
210
+ * 从本地存储恢复登录状态
211
+ */
212
+ async restoreLoginState() {
213
+ try {
214
+ const token = this.window.localStorage.getItem("auth_token");
215
+ const userInfo = this.window.localStorage.getItem("user_info");
216
+ if (token && userInfo) {
217
+ const user = JSON.parse(userInfo);
218
+ this.store.currentUser = user;
219
+ this.store.isLoggedIn = true;
220
+ await this.validateToken(token);
221
+ }
222
+ } catch (error) {
223
+ console.warn("[RegisterAndLogin] 恢复登录状态失败:", error);
224
+ this.clearLoginState();
225
+ }
226
+ }
227
+ /**
228
+ * 验证 token 有效性
229
+ */
230
+ async validateToken(token) {
231
+ try {
232
+ const response = await this.apiCaller.call(
233
+ "validateToken",
234
+ token
235
+ );
236
+ if (response.success && response.data) {
237
+ this.store.currentUser = response.data;
238
+ return true;
239
+ } else {
240
+ this.clearLoginState();
241
+ return false;
242
+ }
243
+ } catch (error) {
244
+ console.warn("[RegisterAndLogin] Token 验证失败:", error);
245
+ this.clearLoginState();
246
+ return false;
247
+ }
248
+ }
249
+ /**
250
+ * 清除登录状态
251
+ */
252
+ clearLoginState() {
253
+ this.store.currentUser = null;
254
+ this.store.isLoggedIn = false;
255
+ this.window.localStorage.removeItem("auth_token");
256
+ this.window.localStorage.removeItem("user_info");
257
+ this.window.localStorage.removeItem("refresh_token");
258
+ }
259
+ /**
260
+ * 发送邮箱验证码
261
+ */
262
+ async sendEmailVerificationCode(params) {
263
+ try {
264
+ this.store.isLoading = true;
265
+ this.store.error = null;
266
+ const response = await this.apiCaller.call(
267
+ "sendEmailVerificationCode",
268
+ params
269
+ );
270
+ if (response.success) {
271
+ const now = Date.now();
272
+ this.store.verificationCodeSent[params.target] = {
273
+ sent: true,
274
+ sentAt: now,
275
+ expiresAt: now + 5 * 60 * 1e3
276
+ // 5分钟过期
277
+ };
278
+ await this.core.effects.emit(
279
+ import_types.RegisterAndLoginHooks.onEmailVerificationSent,
280
+ {
281
+ target: params.target,
282
+ purpose: params.purpose
283
+ }
284
+ );
285
+ } else {
286
+ this.store.error = response.message || "发送验证码失败";
287
+ await this.core.effects.emit(
288
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
289
+ {
290
+ target: params.target,
291
+ error: this.store.error
292
+ }
293
+ );
294
+ }
295
+ return response;
296
+ } catch (error) {
297
+ this.store.error = "发送验证码失败";
298
+ await this.core.effects.emit(
299
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
300
+ {
301
+ target: params.target,
302
+ error: this.store.error
303
+ }
304
+ );
305
+ return error;
306
+ } finally {
307
+ this.store.isLoading = false;
308
+ }
309
+ }
310
+ /**
311
+ * 发送手机号注册验证码
312
+ */
313
+ async sendSmsRegisterCode(params) {
314
+ try {
315
+ this.store.isLoading = true;
316
+ this.store.error = null;
317
+ const response = await this.apiCaller.call(
318
+ "sendSmsRegisterCode",
319
+ params
320
+ );
321
+ if (response.success) {
322
+ const now = Date.now();
323
+ this.store.verificationCodeSent[params.phone] = {
324
+ sent: true,
325
+ sentAt: now,
326
+ expiresAt: now + 5 * 60 * 1e3
327
+ // 5分钟过期
328
+ };
329
+ await this.core.effects.emit(
330
+ import_types.RegisterAndLoginHooks.onSmsVerificationSent,
331
+ {
332
+ target: params.phone,
333
+ purpose: import_types.VerificationPurpose.REGISTER
334
+ }
335
+ );
336
+ } else {
337
+ this.store.error = response.message || "发送注册验证码失败";
338
+ await this.core.effects.emit(
339
+ import_types.RegisterAndLoginHooks.onSmsVerificationFailed,
340
+ {
341
+ target: params.phone,
342
+ error: this.store.error
343
+ }
344
+ );
345
+ }
346
+ return response;
347
+ } catch (error) {
348
+ this.store.error = "发送注册验证码失败";
349
+ await this.core.effects.emit(
350
+ import_types.RegisterAndLoginHooks.onSmsVerificationFailed,
351
+ {
352
+ target: params.phone,
353
+ error: this.store.error
354
+ }
355
+ );
356
+ return error;
357
+ } finally {
358
+ this.store.isLoading = false;
359
+ }
360
+ }
361
+ /**
362
+ * 发送邮箱注册邀请链接
363
+ */
364
+ async sendEmailRegisterLink(email) {
365
+ var _a;
366
+ try {
367
+ this.store.isLoading = true;
368
+ this.store.error = null;
369
+ const response = await this.apiCaller.call(
370
+ "sendEmailRegisterLink",
371
+ email
372
+ );
373
+ if (response.success) {
374
+ if ((_a = response.data) == null ? void 0 : _a.code) {
375
+ this.store.emailRegisterLinkCode = response.data.code;
376
+ }
377
+ const now = Date.now();
378
+ this.store.verificationCodeSent[email] = {
379
+ sent: true,
380
+ sentAt: now,
381
+ expiresAt: now + 24 * 60 * 60 * 1e3
382
+ // 24小时过期
383
+ };
384
+ await this.core.effects.emit(
385
+ import_types.RegisterAndLoginHooks.onEmailVerificationSent,
386
+ {
387
+ target: email,
388
+ purpose: import_types.VerificationPurpose.REGISTER
389
+ }
390
+ );
391
+ } else {
392
+ this.store.error = response.message || "发送注册邀请链接失败";
393
+ await this.core.effects.emit(
394
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
395
+ {
396
+ target: email,
397
+ error: this.store.error
398
+ }
399
+ );
400
+ }
401
+ return response;
402
+ } catch (error) {
403
+ this.store.error = "发送注册邀请链接失败";
404
+ await this.core.effects.emit(
405
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
406
+ {
407
+ target: email,
408
+ error: this.store.error
409
+ }
410
+ );
411
+ return error;
412
+ } finally {
413
+ this.store.isLoading = false;
414
+ }
415
+ }
416
+ /**
417
+ * 验证邮箱注册链接
418
+ */
419
+ async verifyEmailRegistrationLink(params) {
420
+ try {
421
+ this.store.isLoading = true;
422
+ this.store.error = null;
423
+ const response = await this.apiCaller.call(
424
+ "verifyEmailRegistrationLink",
425
+ params
426
+ );
427
+ if (response.success) {
428
+ await this.core.effects.emit(
429
+ import_types.RegisterAndLoginHooks.onEmailVerificationVerified,
430
+ {
431
+ target: "email-registration-link",
432
+ purpose: import_types.VerificationPurpose.REGISTER
433
+ }
434
+ );
435
+ } else {
436
+ this.store.error = response.message || "邮箱注册链接验证失败";
437
+ await this.core.effects.emit(
438
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
439
+ {
440
+ target: "email-registration-link",
441
+ error: this.store.error
442
+ }
443
+ );
444
+ }
445
+ return response;
446
+ } catch (error) {
447
+ this.store.error = "邮箱注册链接验证失败";
448
+ await this.core.effects.emit(
449
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
450
+ {
451
+ target: "email-registration-link",
452
+ error: this.store.error
453
+ }
454
+ );
455
+ return error;
456
+ } finally {
457
+ this.store.isLoading = false;
458
+ }
459
+ }
460
+ /**
461
+ * 邮箱密码登录
462
+ */
463
+ async emailPasswordLogin(params) {
464
+ try {
465
+ this.store.isLoading = true;
466
+ this.store.error = null;
467
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginStarted, {
468
+ type: "email-password",
469
+ email: params.email
470
+ });
471
+ const response = await this.apiCaller.call(
472
+ "emailPasswordLogin",
473
+ params
474
+ );
475
+ if (response.success && response.data) {
476
+ this.store.isLoggedIn = true;
477
+ this.store.userInfo = response.data.user;
478
+ this.store.token = response.data.token;
479
+ if (response.data.refreshToken) {
480
+ this.store.refreshToken = response.data.refreshToken;
481
+ }
482
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginSuccess, {
483
+ user: response.data.user,
484
+ token: response.data.token,
485
+ loginType: "email-password"
486
+ });
487
+ } else {
488
+ this.store.error = response.message || "邮箱密码登录失败";
489
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
490
+ error: this.store.error,
491
+ loginType: "email-password"
492
+ });
493
+ }
494
+ return response;
495
+ } catch (error) {
496
+ this.store.error = "邮箱密码登录失败";
497
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
498
+ error: this.store.error,
499
+ loginType: "email-password"
500
+ });
501
+ return error;
502
+ } finally {
503
+ this.store.isLoading = false;
504
+ }
505
+ }
506
+ /**
507
+ * 验证验证码
508
+ */
509
+ async verifyCode(params) {
510
+ try {
511
+ this.store.isLoading = true;
512
+ this.store.error = null;
513
+ const response = await this.apiCaller.call(
514
+ "verifyCode",
515
+ params
516
+ );
517
+ if (response.success) {
518
+ const hookName = params.type === import_types.VerificationCodeType.EMAIL ? import_types.RegisterAndLoginHooks.onEmailVerificationVerified : import_types.RegisterAndLoginHooks.onSmsVerificationVerified;
519
+ await this.core.effects.emit(hookName, {
520
+ target: params.target,
521
+ purpose: params.purpose
522
+ });
523
+ } else {
524
+ this.store.error = response.message || "验证码验证失败";
525
+ const hookName = params.type === import_types.VerificationCodeType.EMAIL ? import_types.RegisterAndLoginHooks.onEmailVerificationFailed : import_types.RegisterAndLoginHooks.onSmsVerificationFailed;
526
+ await this.core.effects.emit(hookName, {
527
+ target: params.target,
528
+ error: this.store.error
529
+ });
530
+ }
531
+ return response;
532
+ } catch (error) {
533
+ this.store.error = "验证码验证失败";
534
+ return error;
535
+ } finally {
536
+ this.store.isLoading = false;
537
+ }
538
+ }
539
+ /**
540
+ * 用户注册
541
+ */
542
+ async register(params) {
543
+ try {
544
+ this.store.isLoading = true;
545
+ this.store.error = null;
546
+ await this.core.effects.emit(
547
+ import_types.RegisterAndLoginHooks.onRegisterStarted,
548
+ params
549
+ );
550
+ const response = await this.apiCaller.call(
551
+ "register",
552
+ params
553
+ );
554
+ if (response.success && response.data) {
555
+ const { user, token, refreshToken, expiresAt } = response.data;
556
+ if (token) {
557
+ this.store.currentUser = user;
558
+ this.store.isLoggedIn = true;
559
+ this.window.localStorage.setItem("auth_token", token);
560
+ this.window.localStorage.setItem("user_info", JSON.stringify(user));
561
+ if (refreshToken) {
562
+ this.window.localStorage.setItem("refresh_token", refreshToken);
563
+ }
564
+ }
565
+ await this.core.effects.emit(
566
+ import_types.RegisterAndLoginHooks.onRegisterSuccess,
567
+ response.data
568
+ );
569
+ } else {
570
+ this.store.error = response.message || "注册失败";
571
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
572
+ error: this.store.error,
573
+ params
574
+ });
575
+ }
576
+ return response;
577
+ } catch (error) {
578
+ this.store.error = "注册失败";
579
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onRegisterFailed, {
580
+ error: this.store.error,
581
+ params
582
+ });
583
+ throw error;
584
+ } finally {
585
+ this.store.isLoading = false;
586
+ }
587
+ }
588
+ /**
589
+ * 用户登录
590
+ */
591
+ async login(params) {
592
+ try {
593
+ this.store.isLoading = true;
594
+ this.store.error = null;
595
+ await this.core.effects.emit(
596
+ import_types.RegisterAndLoginHooks.onLoginStarted,
597
+ params
598
+ );
599
+ const response = await this.apiCaller.call(
600
+ "login",
601
+ params
602
+ );
603
+ if (response.success && response.data) {
604
+ const { user, token, refreshToken } = response.data;
605
+ this.store.currentUser = user;
606
+ this.store.isLoggedIn = true;
607
+ this.window.localStorage.setItem("auth_token", token);
608
+ this.window.localStorage.setItem("user_info", JSON.stringify(user));
609
+ if (refreshToken) {
610
+ this.window.localStorage.setItem("refresh_token", refreshToken);
611
+ }
612
+ await this.core.effects.emit(
613
+ import_types.RegisterAndLoginHooks.onLoginSuccess,
614
+ response.data
615
+ );
616
+ } else {
617
+ this.store.error = response.message || "登录失败";
618
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
619
+ error: this.store.error,
620
+ params
621
+ });
622
+ }
623
+ return response;
624
+ } catch (error) {
625
+ this.store.error = "登录失败";
626
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
627
+ error: this.store.error,
628
+ params
629
+ });
630
+ throw error;
631
+ } finally {
632
+ this.store.isLoading = false;
633
+ }
634
+ }
635
+ /**
636
+ * OAuth 登录
637
+ */
638
+ async oauthLogin(params) {
639
+ try {
640
+ this.store.isLoading = true;
641
+ this.store.error = null;
642
+ await this.core.effects.emit(
643
+ import_types.RegisterAndLoginHooks.onOAuthLoginStarted,
644
+ params
645
+ );
646
+ const response = await this.apiCaller.call("oauthLogin", params);
647
+ if (response.success && response.data) {
648
+ const { user, token, refreshToken } = response.data;
649
+ this.store.currentUser = user;
650
+ this.store.isLoggedIn = true;
651
+ this.window.localStorage.setItem("auth_token", token);
652
+ this.window.localStorage.setItem("user_info", JSON.stringify(user));
653
+ if (refreshToken) {
654
+ this.window.localStorage.setItem("refresh_token", refreshToken);
655
+ }
656
+ await this.core.effects.emit(
657
+ import_types.RegisterAndLoginHooks.onOAuthLoginSuccess,
658
+ response.data
659
+ );
660
+ } else {
661
+ this.store.error = response.message || "OAuth 登录失败";
662
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onOAuthLoginFailed, {
663
+ error: this.store.error,
664
+ params
665
+ });
666
+ }
667
+ return response;
668
+ } catch (error) {
669
+ this.store.error = "OAuth 登录失败";
670
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onOAuthLoginFailed, {
671
+ error: this.store.error,
672
+ params
673
+ });
674
+ throw error;
675
+ } finally {
676
+ this.store.isLoading = false;
677
+ }
678
+ }
679
+ /**
680
+ * 用户登出
681
+ */
682
+ async logout() {
683
+ try {
684
+ await this.apiCaller.call("logout");
685
+ } catch (error) {
686
+ console.warn("[RegisterAndLogin] 登出接口调用失败:", error);
687
+ } finally {
688
+ this.clearLoginState();
689
+ }
690
+ }
691
+ /** 发送重置密码邮箱链接 */
692
+ async sendResetPasswordLink(params) {
693
+ try {
694
+ this.store.isLoading = true;
695
+ this.store.error = null;
696
+ const response = await this.apiCaller.call(
697
+ "sendResetPasswordLink",
698
+ params
699
+ );
700
+ if (response.success) {
701
+ this.store.verificationCodeSent[params.email] = {
702
+ sent: true,
703
+ sentAt: Date.now(),
704
+ expiresAt: Date.now() + 5 * 60 * 1e3
705
+ // 5分钟后过期
706
+ };
707
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onEmailVerificationSent, {
708
+ email: params.email,
709
+ purpose: "reset-password-link"
710
+ });
711
+ } else {
712
+ this.store.error = response.message || "发送重置密码链接失败";
713
+ }
714
+ return response;
715
+ } catch (error) {
716
+ this.store.error = "发送重置密码链接失败";
717
+ return error;
718
+ } finally {
719
+ this.store.isLoading = false;
720
+ }
721
+ }
722
+ /** 检测重置密码链接code有效性 */
723
+ async checkResetPasswordCode(params) {
724
+ try {
725
+ this.store.isLoading = true;
726
+ this.store.error = null;
727
+ const response = await this.apiCaller.call(
728
+ "checkResetPasswordCode",
729
+ params
730
+ );
731
+ if (!response.success) {
732
+ this.store.error = response.message || "验证码无效";
733
+ }
734
+ return response;
735
+ } catch (error) {
736
+ this.store.error = "验证码验证失败";
737
+ return error;
738
+ } finally {
739
+ this.store.isLoading = false;
740
+ }
741
+ }
742
+ /** 校验邮件链接 code 有效性 */
743
+ async checkEmailLinkCode(params) {
744
+ try {
745
+ this.store.isLoading = true;
746
+ this.store.error = null;
747
+ const response = await this.apiCaller.call(
748
+ "checkEmailLinkCode",
749
+ params
750
+ );
751
+ if (!response.success) {
752
+ this.store.error = response.message || "邮件链接验证码无效";
753
+ }
754
+ return response;
755
+ } catch (error) {
756
+ this.store.error = "邮件链接验证码验证失败";
757
+ return error;
758
+ } finally {
759
+ this.store.isLoading = false;
760
+ }
761
+ }
762
+ /** 通过code重置密码 */
763
+ async resetPasswordByCode(params) {
764
+ try {
765
+ this.store.isLoading = true;
766
+ this.store.error = null;
767
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetStarted, {
768
+ code: params.code
769
+ });
770
+ const response = await this.apiCaller.call(
771
+ "resetPasswordByCode",
772
+ params
773
+ );
774
+ if (response.success) {
775
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
776
+ code: params.code
777
+ });
778
+ } else {
779
+ this.store.error = response.message || "密码重置失败";
780
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
781
+ code: params.code,
782
+ error: this.store.error
783
+ });
784
+ }
785
+ return response;
786
+ } catch (error) {
787
+ this.store.error = "密码重置失败";
788
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
789
+ code: params.code,
790
+ error: this.store.error
791
+ });
792
+ return error;
793
+ } finally {
794
+ this.store.isLoading = false;
795
+ }
796
+ }
797
+ /**
798
+ * 重置密码
799
+ */
800
+ async resetPassword(params) {
801
+ try {
802
+ this.store.isLoading = true;
803
+ this.store.error = null;
804
+ if (params.type === "email") {
805
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetStarted, {
806
+ email: params.target.email
807
+ });
808
+ } else {
809
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetStarted, {
810
+ phone: params.target.phone
811
+ });
812
+ }
813
+ let response;
814
+ if (params.type === "email") {
815
+ if (!params.target.email) {
816
+ throw new Error("邮箱地址不能为空");
817
+ }
818
+ response = await this.apiCaller.call(
819
+ "resetPasswordByEmail",
820
+ {
821
+ email: params.target.email,
822
+ password: params.password,
823
+ code: params.code
824
+ }
825
+ );
826
+ } else {
827
+ if (!params.target.phone || !params.target.country_calling_code) {
828
+ throw new Error("手机号和国家区号不能为空");
829
+ }
830
+ response = await this.apiCaller.call(
831
+ "resetPasswordByPhone",
832
+ {
833
+ phone: params.target.phone,
834
+ password: params.password,
835
+ code: params.code,
836
+ country_calling_code: params.target.country_calling_code
837
+ }
838
+ );
839
+ }
840
+ if (response.success) {
841
+ const key = params.type === "email" ? params.target.email : params.target.phone;
842
+ if (this.store.verificationCodeSent[key]) {
843
+ delete this.store.verificationCodeSent[key];
844
+ }
845
+ if (params.type === "email") {
846
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
847
+ email: params.target.email
848
+ });
849
+ } else {
850
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
851
+ phone: params.target.phone
852
+ });
853
+ }
854
+ } else {
855
+ this.store.error = response.message || "密码重置失败";
856
+ if (params.type === "email") {
857
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
858
+ email: params.target.email,
859
+ error: this.store.error
860
+ });
861
+ } else {
862
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
863
+ phone: params.target.phone,
864
+ error: this.store.error
865
+ });
866
+ }
867
+ }
868
+ return response;
869
+ } catch (error) {
870
+ this.store.error = "密码重置失败";
871
+ if (params.type === "email") {
872
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
873
+ email: params.target.email,
874
+ error: this.store.error
875
+ });
876
+ } else {
877
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetFailed, {
878
+ phone: params.target.phone,
879
+ error: this.store.error
880
+ });
881
+ }
882
+ return error;
883
+ } finally {
884
+ this.store.isLoading = false;
885
+ }
886
+ }
887
+ /** 发送手机登录验证码 */
888
+ async sendSmsLoginCode(params) {
889
+ try {
890
+ this.store.isLoading = true;
891
+ this.store.error = null;
892
+ const response = await this.apiCaller.call(
893
+ "sendSmsLoginCode",
894
+ params
895
+ );
896
+ if (response.success) {
897
+ const now = Date.now();
898
+ this.store.verificationCodeSent[params.phone] = {
899
+ sent: true,
900
+ sentAt: now,
901
+ expiresAt: now + 5 * 60 * 1e3
902
+ // 5分钟过期
903
+ };
904
+ await this.core.effects.emit(
905
+ import_types.RegisterAndLoginHooks.onSmsVerificationSent,
906
+ {
907
+ target: params.phone,
908
+ purpose: import_types.VerificationPurpose.LOGIN
909
+ }
910
+ );
911
+ } else {
912
+ this.store.error = response.message || "发送登录验证码失败";
913
+ await this.core.effects.emit(
914
+ import_types.RegisterAndLoginHooks.onSmsVerificationFailed,
915
+ {
916
+ target: params.phone,
917
+ error: this.store.error
918
+ }
919
+ );
920
+ }
921
+ return response;
922
+ } catch (error) {
923
+ this.store.error = "发送登录验证码失败";
924
+ await this.core.effects.emit(
925
+ import_types.RegisterAndLoginHooks.onSmsVerificationFailed,
926
+ {
927
+ target: params.phone,
928
+ error: this.store.error
929
+ }
930
+ );
931
+ return error;
932
+ } finally {
933
+ this.store.isLoading = false;
934
+ }
935
+ }
936
+ /** 手机号+短信验证码登录 */
937
+ async phoneCodeLogin(params) {
938
+ try {
939
+ this.store.isLoading = true;
940
+ this.store.error = null;
941
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginStarted, {
942
+ type: "phone-code",
943
+ phone: params.phone
944
+ });
945
+ const response = await this.apiCaller.call(
946
+ "phoneCodeLogin",
947
+ params
948
+ );
949
+ if (response.success && response.data) {
950
+ this.store.isLoggedIn = true;
951
+ this.store.userInfo = response.data.user;
952
+ this.store.token = response.data.token;
953
+ if (response.data.refreshToken) {
954
+ this.store.refreshToken = response.data.refreshToken;
955
+ }
956
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginSuccess, {
957
+ user: response.data.user,
958
+ token: response.data.token,
959
+ loginType: "phone-code"
960
+ });
961
+ } else {
962
+ this.store.error = response.message || "手机号验证码登录失败";
963
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
964
+ error: this.store.error,
965
+ loginType: "phone-code"
966
+ });
967
+ }
968
+ return response;
969
+ } catch (error) {
970
+ this.store.error = "手机号验证码登录失败";
971
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
972
+ error: this.store.error,
973
+ loginType: "phone-code"
974
+ });
975
+ return error;
976
+ } finally {
977
+ this.store.isLoading = false;
978
+ }
979
+ }
980
+ /** Guest 登录 */
981
+ async guestLogin() {
982
+ try {
983
+ this.store.isLoading = true;
984
+ this.store.error = null;
985
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginStarted, {
986
+ type: "guest"
987
+ });
988
+ const response = await this.apiCaller.call("guestLogin", this.channel);
989
+ if (response.success && response.data) {
990
+ this.store.isLoggedIn = true;
991
+ this.store.userInfo = response.data.user;
992
+ this.store.token = response.data.token;
993
+ if (response.data.refreshToken) {
994
+ this.store.refreshToken = response.data.refreshToken;
995
+ }
996
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginSuccess, {
997
+ user: response.data.user,
998
+ token: response.data.token,
999
+ loginType: "guest"
1000
+ });
1001
+ } else {
1002
+ this.store.error = response.message || "Guest 登录失败";
1003
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
1004
+ error: this.store.error,
1005
+ loginType: "guest"
1006
+ });
1007
+ }
1008
+ return response;
1009
+ } catch (error) {
1010
+ this.store.error = "Guest 登录失败";
1011
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
1012
+ error: this.store.error,
1013
+ loginType: "guest"
1014
+ });
1015
+ return error;
1016
+ } finally {
1017
+ this.store.isLoading = false;
1018
+ }
1019
+ }
1020
+ /** 检查邮箱是否已注册 */
1021
+ async checkEmailExists(params) {
1022
+ try {
1023
+ this.store.isLoading = true;
1024
+ this.store.error = null;
1025
+ const response = await this.apiCaller.call("checkEmailExists", params);
1026
+ if (!response.success) {
1027
+ this.store.error = response.message || "检查邮箱失败";
1028
+ }
1029
+ return response;
1030
+ } catch (error) {
1031
+ this.store.error = "检查邮箱失败";
1032
+ return error;
1033
+ } finally {
1034
+ this.store.isLoading = false;
1035
+ }
1036
+ }
1037
+ /** 检查邮箱验证码是否有效 */
1038
+ async checkEmailCode(params) {
1039
+ try {
1040
+ this.store.isLoading = true;
1041
+ this.store.error = null;
1042
+ const response = await this.apiCaller.call("checkEmailCode", params);
1043
+ if (!response.success) {
1044
+ this.store.error = response.message || "检查邮箱验证码失败";
1045
+ }
1046
+ return response;
1047
+ } catch (error) {
1048
+ this.store.error = "检查邮箱验证码失败";
1049
+ return error;
1050
+ } finally {
1051
+ this.store.isLoading = false;
1052
+ }
1053
+ }
1054
+ /** 检查手机验证码是否有效 */
1055
+ async checkMobileCode(params) {
1056
+ try {
1057
+ this.store.isLoading = true;
1058
+ this.store.error = null;
1059
+ const response = await this.apiCaller.call("checkMobileCode", params);
1060
+ if (!response.success) {
1061
+ this.store.error = response.message || "检查手机验证码失败";
1062
+ }
1063
+ return response;
1064
+ } catch (error) {
1065
+ this.store.error = "检查手机验证码失败";
1066
+ return error;
1067
+ } finally {
1068
+ this.store.isLoading = false;
1069
+ }
1070
+ }
1071
+ /** 手机号密码登录 */
1072
+ async phonePasswordLogin(params) {
1073
+ try {
1074
+ this.store.isLoading = true;
1075
+ this.store.error = null;
1076
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginStarted, {
1077
+ type: "phone-password",
1078
+ phone: params.phone
1079
+ });
1080
+ const response = await this.apiCaller.call(
1081
+ "phonePasswordLogin",
1082
+ params
1083
+ );
1084
+ if (response.success && response.data) {
1085
+ this.store.isLoggedIn = true;
1086
+ this.store.userInfo = response.data.user;
1087
+ this.store.token = response.data.token;
1088
+ if (response.data.refreshToken) {
1089
+ this.store.refreshToken = response.data.refreshToken;
1090
+ }
1091
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginSuccess, {
1092
+ user: response.data.user,
1093
+ token: response.data.token,
1094
+ loginType: "phone-password"
1095
+ });
1096
+ } else {
1097
+ this.store.error = response.message || "手机号密码登录失败";
1098
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
1099
+ error: this.store.error,
1100
+ loginType: "phone-password"
1101
+ });
1102
+ }
1103
+ return response;
1104
+ } catch (error) {
1105
+ this.store.error = "手机号密码登录失败";
1106
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onLoginFailed, {
1107
+ error: this.store.error,
1108
+ loginType: "phone-password"
1109
+ });
1110
+ return error;
1111
+ } finally {
1112
+ this.store.isLoading = false;
1113
+ }
1114
+ }
1115
+ /** 发送密码重置邮箱验证码 */
1116
+ async sendPasswordResetEmail(params) {
1117
+ try {
1118
+ this.store.isLoading = true;
1119
+ this.store.error = null;
1120
+ const response = await this.apiCaller.call(
1121
+ "sendPasswordResetEmail",
1122
+ params
1123
+ );
1124
+ if (response.success) {
1125
+ const now = Date.now();
1126
+ this.store.verificationCodeSent[params.email] = {
1127
+ sent: true,
1128
+ sentAt: now,
1129
+ expiresAt: now + 10 * 60 * 1e3
1130
+ // 10分钟过期
1131
+ };
1132
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onEmailVerificationSent, {
1133
+ target: params.email,
1134
+ purpose: import_types.VerificationPurpose.PASSWORD_RESET
1135
+ });
1136
+ } else {
1137
+ this.store.error = response.message || "发送密码重置验证码失败";
1138
+ this.core.effects.emit(
1139
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
1140
+ {
1141
+ target: params.email,
1142
+ error: this.store.error
1143
+ }
1144
+ );
1145
+ }
1146
+ return response;
1147
+ } catch (error) {
1148
+ this.store.error = "发送密码重置验证码失败";
1149
+ this.core.effects.emit(import_types.RegisterAndLoginHooks.onEmailVerificationFailed, {
1150
+ target: params.email,
1151
+ error: this.store.error
1152
+ });
1153
+ return error;
1154
+ } finally {
1155
+ this.store.isLoading = false;
1156
+ }
1157
+ }
1158
+ /** 发送手机号验证码重置密码 */
1159
+ async sendPasswordResetSms(params) {
1160
+ try {
1161
+ this.store.isLoading = true;
1162
+ this.store.error = null;
1163
+ const response = await this.apiCaller.call(
1164
+ "sendPasswordResetSms",
1165
+ params
1166
+ );
1167
+ if (response.success) {
1168
+ return response;
1169
+ } else {
1170
+ this.store.error = response.message || "发送手机号验证码重置密码失败";
1171
+ }
1172
+ return response;
1173
+ } catch (error) {
1174
+ this.store.error = "发送手机号验证码重置密码失败";
1175
+ return error;
1176
+ } finally {
1177
+ this.store.isLoading = false;
1178
+ }
1179
+ }
1180
+ /**
1181
+ * 获取当前用户信息
1182
+ */
1183
+ getCurrentUser() {
1184
+ return this.store.currentUser;
1185
+ }
1186
+ /**
1187
+ * 检查是否已登录
1188
+ */
1189
+ isLoggedIn() {
1190
+ return this.store.isLoggedIn;
1191
+ }
1192
+ /**
1193
+ * 获取加载状态
1194
+ */
1195
+ isLoading() {
1196
+ return this.store.isLoading;
1197
+ }
1198
+ /**
1199
+ * 获取错误信息
1200
+ */
1201
+ getError() {
1202
+ return this.store.error;
1203
+ }
1204
+ /**
1205
+ * 清除错误信息
1206
+ */
1207
+ clearError() {
1208
+ this.store.error = null;
1209
+ }
1210
+ /**
1211
+ * 检查验证码是否已发送且未过期
1212
+ */
1213
+ isVerificationCodeSent(target) {
1214
+ const codeInfo = this.store.verificationCodeSent[target];
1215
+ if (!codeInfo || !codeInfo.sent) {
1216
+ return false;
1217
+ }
1218
+ return Date.now() < codeInfo.expiresAt;
1219
+ }
1220
+ /**
1221
+ * 获取验证码剩余时间(秒)
1222
+ */
1223
+ getVerificationCodeRemainingTime(target) {
1224
+ const codeInfo = this.store.verificationCodeSent[target];
1225
+ if (!codeInfo || !codeInfo.sent) {
1226
+ return 0;
1227
+ }
1228
+ const remaining = Math.max(0, codeInfo.expiresAt - Date.now());
1229
+ return Math.ceil(remaining / 1e3);
1230
+ }
1231
+ /**
1232
+ * 初始化 Facebook SDK
1233
+ */
1234
+ async initFacebookSDK(token) {
1235
+ return new Promise((resolve, reject) => {
1236
+ if (typeof window === "undefined") {
1237
+ reject(new Error("Facebook SDK 只能在浏览器环境中使用"));
1238
+ return;
1239
+ }
1240
+ if (window.FB) {
1241
+ resolve();
1242
+ return;
1243
+ }
1244
+ const script = document.createElement("script");
1245
+ script.src = "https://connect.facebook.net/en_US/sdk.js";
1246
+ script.async = true;
1247
+ script.defer = true;
1248
+ script.crossOrigin = "anonymous";
1249
+ script.onload = () => {
1250
+ window.FB.init({
1251
+ appId: token,
1252
+ cookie: true,
1253
+ xfbml: true,
1254
+ version: "v18.0"
1255
+ });
1256
+ resolve();
1257
+ };
1258
+ script.onerror = () => {
1259
+ reject(new Error("Facebook SDK 加载失败"));
1260
+ };
1261
+ document.head.appendChild(script);
1262
+ });
1263
+ }
1264
+ /**
1265
+ * 初始化 Apple SDK
1266
+ */
1267
+ async initAppleSDK() {
1268
+ return new Promise((resolve, reject) => {
1269
+ if (typeof window === "undefined") {
1270
+ reject(new Error("Apple SDK 只能在浏览器环境中使用"));
1271
+ return;
1272
+ }
1273
+ if (window.AppleID) {
1274
+ resolve();
1275
+ return;
1276
+ }
1277
+ const script = document.createElement("script");
1278
+ script.src = "https://file.mypisell-dev.com/static/apple.js";
1279
+ script.async = true;
1280
+ script.defer = true;
1281
+ script.crossOrigin = "anonymous";
1282
+ script.onload = () => {
1283
+ setTimeout(() => {
1284
+ if (window.AppleID) {
1285
+ resolve();
1286
+ } else {
1287
+ reject(new Error("Apple SDK 加载失败:AppleID 对象不可用"));
1288
+ }
1289
+ }, 100);
1290
+ };
1291
+ script.onerror = () => {
1292
+ reject(new Error("Apple SDK 加载失败"));
1293
+ };
1294
+ document.head.appendChild(script);
1295
+ });
1296
+ }
1297
+ /**
1298
+ * Facebook 登录
1299
+ */
1300
+ async loginWithFacebook(token) {
1301
+ await this.initFacebookSDK(token);
1302
+ return new Promise((resolve, reject) => {
1303
+ window.FB.login(
1304
+ async (response) => {
1305
+ if (response.authResponse) {
1306
+ try {
1307
+ const result = await this.apiCaller.call("facebookLogin", {
1308
+ token: response.authResponse.accessToken
1309
+ });
1310
+ resolve(result);
1311
+ } catch (error) {
1312
+ reject(error);
1313
+ }
1314
+ } else {
1315
+ reject(new Error("facebook_login_cancel"));
1316
+ }
1317
+ },
1318
+ { scope: "email,public_profile" }
1319
+ );
1320
+ });
1321
+ }
1322
+ /**
1323
+ * Apple 登录(需要在支持的环境中使用)
1324
+ */
1325
+ async loginWithApple(token) {
1326
+ await this.initAppleSDK();
1327
+ return new Promise((resolve, reject) => {
1328
+ var _a, _b, _c, _d;
1329
+ try {
1330
+ const appleSignInDiv = document.createElement("div");
1331
+ appleSignInDiv.id = "appleid-signin-temp";
1332
+ appleSignInDiv.setAttribute("data-color", "black");
1333
+ appleSignInDiv.setAttribute("data-border", "false");
1334
+ appleSignInDiv.setAttribute("data-type", "sign-in");
1335
+ appleSignInDiv.setAttribute("data-mode", "logo-only");
1336
+ appleSignInDiv.setAttribute("data-logo-size", "small");
1337
+ appleSignInDiv.style.opacity = "0";
1338
+ appleSignInDiv.style.position = "absolute";
1339
+ appleSignInDiv.style.left = "-9999px";
1340
+ appleSignInDiv.style.top = "-9999px";
1341
+ appleSignInDiv.style.width = "1px";
1342
+ appleSignInDiv.style.height = "1px";
1343
+ document.body.appendChild(appleSignInDiv);
1344
+ if ((_b = (_a = window.AppleID) == null ? void 0 : _a.auth) == null ? void 0 : _b.init) {
1345
+ window.AppleID.auth.init({
1346
+ clientId: token,
1347
+ // 使用传入的 token 作为 clientId
1348
+ scope: "name email",
1349
+ redirectURI: window.location.origin,
1350
+ state: "signin",
1351
+ usePopup: true
1352
+ });
1353
+ }
1354
+ if ((_d = (_c = window.AppleID) == null ? void 0 : _c.auth) == null ? void 0 : _d.signIn) {
1355
+ window.AppleID.auth.signIn().then(async (authResult) => {
1356
+ var _a2, _b2;
1357
+ try {
1358
+ if (document.body.contains(appleSignInDiv)) {
1359
+ document.body.removeChild(appleSignInDiv);
1360
+ }
1361
+ const authorizationCode = (_a2 = authResult.authorization) == null ? void 0 : _a2.code;
1362
+ const identityToken = (_b2 = authResult.authorization) == null ? void 0 : _b2.id_token;
1363
+ const result = await this.apiCaller.call("appleLogin", {
1364
+ token: authorizationCode || identityToken
1365
+ });
1366
+ resolve(result);
1367
+ } catch (error) {
1368
+ reject(error);
1369
+ }
1370
+ }).catch((error) => {
1371
+ if (document.body.contains(appleSignInDiv)) {
1372
+ document.body.removeChild(appleSignInDiv);
1373
+ }
1374
+ reject(new Error("Apple 登录失败: " + ((error == null ? void 0 : error.error) || (error == null ? void 0 : error.message) || "未知错误")));
1375
+ });
1376
+ } else {
1377
+ reject(new Error("Apple SDK 未正确加载"));
1378
+ }
1379
+ } catch (error) {
1380
+ reject(error);
1381
+ }
1382
+ });
1383
+ }
1384
+ /**
1385
+ * 更新 OAuth 配置
1386
+ */
1387
+ updateOAuthConfig(config) {
1388
+ this.store.oauthConfig = {
1389
+ ...this.store.oauthConfig,
1390
+ ...config
1391
+ };
1392
+ }
1393
+ /**
1394
+ * 获取当前渠道
1395
+ */
1396
+ getCurrentChannel() {
1397
+ return this.channel;
1398
+ }
1399
+ /**
1400
+ * 获取 API 调用器(用于高级用法)
1401
+ */
1402
+ getApiCaller() {
1403
+ return this.apiCaller;
1404
+ }
1405
+ /**
1406
+ * 获取国家区号列表
1407
+ */
1408
+ async getCountries() {
1409
+ try {
1410
+ this.store.isLoading = true;
1411
+ this.store.error = null;
1412
+ const response = await this.apiCaller.call("getCountries");
1413
+ if (response.status && response.data) {
1414
+ return response.data;
1415
+ } else {
1416
+ this.store.error = response.message || "获取国家区号失败";
1417
+ throw new Error(this.store.error);
1418
+ }
1419
+ } catch (error) {
1420
+ this.store.error = "获取国家区号失败";
1421
+ console.error("[RegisterAndLogin] 获取国家区号失败:", error);
1422
+ throw error;
1423
+ } finally {
1424
+ this.store.isLoading = false;
1425
+ }
1426
+ }
1427
+ async destroy() {
1428
+ await this.core.effects.emit(import_types.RegisterAndLoginHooks.onDestroy, {});
1429
+ console.log("[RegisterAndLogin] 已销毁");
1430
+ }
1431
+ };
1432
+ // Annotate the CommonJS export names for ESM import in node:
1433
+ 0 && (module.exports = {
1434
+ RegisterAndLoginImpl,
1435
+ ...require("./types"),
1436
+ ...require("./config")
1437
+ });