@pisell/pisellos 0.0.336 → 0.0.338

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.
@@ -194,7 +194,7 @@ export interface RegisterAndLoginState {
194
194
  * API 响应接口
195
195
  */
196
196
  export interface ApiResponse<T = any> {
197
- success: boolean;
197
+ status: boolean;
198
198
  data?: T;
199
199
  message?: string;
200
200
  error?: string;
@@ -17,6 +17,7 @@ export interface ApiConfig {
17
17
  */
18
18
  export interface ChannelConfig {
19
19
  sendEmailVerificationCode: ApiConfig;
20
+ sendEmailLoginCode: ApiConfig;
20
21
  sendSmsRegisterCode: ApiConfig;
21
22
  sendEmailRegisterLink: ApiConfig;
22
23
  verifyEmailRegistrationLink: ApiConfig;
@@ -33,6 +33,15 @@ var onlineStoreConfig = {
33
33
  email: params.target
34
34
  })
35
35
  },
36
+ sendEmailLoginCode: {
37
+ url: "/auth/send-email-code",
38
+ method: "POST",
39
+ transformParams: (params) => ({
40
+ email: params.target,
41
+ purpose: params.purpose,
42
+ type: params.type
43
+ })
44
+ },
36
45
  sendSmsRegisterCode: {
37
46
  url: "/auth/mobile/sms-register",
38
47
  method: "POST",
@@ -87,7 +96,7 @@ var onlineStoreConfig = {
87
96
  })
88
97
  },
89
98
  resendEmailRegisterLink: {
90
- url: "/auth/email/link/resend_reset_pwd_link",
99
+ url: "/auth/email/link/resend_register_link",
91
100
  method: "POST",
92
101
  transformParams: (params) => ({
93
102
  code: params.code
@@ -282,6 +291,15 @@ var defaultConfig = {
282
291
  type: params.type
283
292
  })
284
293
  },
294
+ sendEmailLoginCode: {
295
+ url: "/auth/send-email-code",
296
+ method: "POST",
297
+ transformParams: (params) => ({
298
+ email: params.target,
299
+ purpose: params.purpose,
300
+ type: params.type
301
+ })
302
+ },
285
303
  sendSmsRegisterCode: {
286
304
  url: "/auth/send-sms-register",
287
305
  method: "POST",
@@ -17,6 +17,7 @@ export declare class RegisterAndLoginImpl extends BaseModule implements Module {
17
17
  private apiCaller;
18
18
  private otherParams;
19
19
  private channel;
20
+ private countriesCache;
20
21
  constructor(name?: string, version?: string);
21
22
  /**
22
23
  * 重新发送邮箱注册链接
@@ -49,6 +50,10 @@ export declare class RegisterAndLoginImpl extends BaseModule implements Module {
49
50
  * 发送邮箱验证码
50
51
  */
51
52
  sendEmailVerificationCode(params: SendVerificationCodeParams): Promise<ApiResponse>;
53
+ /**
54
+ * 发送邮箱登录验证码
55
+ */
56
+ sendEmailLoginCode(params: SendVerificationCodeParams): Promise<ApiResponse>;
52
57
  /**
53
58
  * 发送手机号注册验证码
54
59
  */
@@ -175,5 +180,9 @@ export declare class RegisterAndLoginImpl extends BaseModule implements Module {
175
180
  * 获取国家区号列表
176
181
  */
177
182
  getCountries(): Promise<CountryInfo[]>;
183
+ /**
184
+ * 异步更新国家缓存数据
185
+ */
186
+ private updateCountriesCache;
178
187
  destroy(): Promise<void>;
179
188
  }
@@ -37,6 +37,8 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
37
37
  this.isSolution = true;
38
38
  this.otherParams = {};
39
39
  this.channel = "default";
40
+ // 内存缓存
41
+ this.countriesCache = null;
40
42
  }
41
43
  /**
42
44
  * 重新发送邮箱注册链接
@@ -47,7 +49,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
47
49
  const error = "没有找到邮箱注册链接的 code,请先调用 sendEmailRegisterLink";
48
50
  this.store.error = error;
49
51
  return {
50
- success: false,
52
+ status: false,
51
53
  message: error
52
54
  };
53
55
  }
@@ -57,7 +59,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
57
59
  "resendEmailRegisterLink",
58
60
  { code: this.store.emailRegisterLinkCode }
59
61
  );
60
- if (response.success) {
62
+ if (response.status) {
61
63
  await this.core.effects.emit(
62
64
  import_types.RegisterAndLoginHooks.onEmailVerificationSent,
63
65
  {
@@ -107,7 +109,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
107
109
  "emailCodeRegister",
108
110
  params
109
111
  );
110
- if (response.success && response.data) {
112
+ if (response.status && response.data) {
111
113
  const { user, token, refreshToken, expiresAt } = response.data;
112
114
  if (token) {
113
115
  this.store.currentUser = user;
@@ -151,7 +153,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
151
153
  "phoneCodeRegister",
152
154
  params
153
155
  );
154
- if (response.success && response.data) {
156
+ if (response.status && response.data) {
155
157
  const { user, token, refreshToken, expiresAt } = response.data;
156
158
  if (token) {
157
159
  this.store.currentUser = user;
@@ -233,7 +235,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
233
235
  "validateToken",
234
236
  token
235
237
  );
236
- if (response.success && response.data) {
238
+ if (response.status && response.data) {
237
239
  this.store.currentUser = response.data;
238
240
  return true;
239
241
  } else {
@@ -267,7 +269,58 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
267
269
  "sendEmailVerificationCode",
268
270
  params
269
271
  );
270
- if (response.success) {
272
+ if (response.status) {
273
+ const now = Date.now();
274
+ this.store.verificationCodeSent[params.target] = {
275
+ sent: true,
276
+ sentAt: now,
277
+ expiresAt: now + 5 * 60 * 1e3
278
+ // 5分钟过期
279
+ };
280
+ await this.core.effects.emit(
281
+ import_types.RegisterAndLoginHooks.onEmailVerificationSent,
282
+ {
283
+ target: params.target,
284
+ purpose: params.purpose
285
+ }
286
+ );
287
+ } else {
288
+ this.store.error = response.message || "发送验证码失败";
289
+ await this.core.effects.emit(
290
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
291
+ {
292
+ target: params.target,
293
+ error: this.store.error
294
+ }
295
+ );
296
+ }
297
+ return response;
298
+ } catch (error) {
299
+ this.store.error = "发送验证码失败";
300
+ await this.core.effects.emit(
301
+ import_types.RegisterAndLoginHooks.onEmailVerificationFailed,
302
+ {
303
+ target: params.target,
304
+ error: this.store.error
305
+ }
306
+ );
307
+ return error;
308
+ } finally {
309
+ this.store.isLoading = false;
310
+ }
311
+ }
312
+ /**
313
+ * 发送邮箱登录验证码
314
+ */
315
+ async sendEmailLoginCode(params) {
316
+ try {
317
+ this.store.isLoading = true;
318
+ this.store.error = null;
319
+ const response = await this.apiCaller.call(
320
+ "sendEmailLoginCode",
321
+ params
322
+ );
323
+ if (response.status) {
271
324
  const now = Date.now();
272
325
  this.store.verificationCodeSent[params.target] = {
273
326
  sent: true,
@@ -318,7 +371,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
318
371
  "sendSmsRegisterCode",
319
372
  params
320
373
  );
321
- if (response.success) {
374
+ if (response.status) {
322
375
  const now = Date.now();
323
376
  this.store.verificationCodeSent[params.phone] = {
324
377
  sent: true,
@@ -370,7 +423,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
370
423
  "sendEmailRegisterLink",
371
424
  email
372
425
  );
373
- if (response.success) {
426
+ if (response.status) {
374
427
  if ((_a = response.data) == null ? void 0 : _a.code) {
375
428
  this.store.emailRegisterLinkCode = response.data.code;
376
429
  }
@@ -424,7 +477,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
424
477
  "verifyEmailRegistrationLink",
425
478
  params
426
479
  );
427
- if (response.success) {
480
+ if (response.status) {
428
481
  await this.core.effects.emit(
429
482
  import_types.RegisterAndLoginHooks.onEmailVerificationVerified,
430
483
  {
@@ -472,7 +525,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
472
525
  "emailPasswordLogin",
473
526
  params
474
527
  );
475
- if (response.success && response.data) {
528
+ if (response.status && response.data) {
476
529
  this.store.isLoggedIn = true;
477
530
  this.store.userInfo = response.data.user;
478
531
  this.store.token = response.data.token;
@@ -514,7 +567,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
514
567
  "verifyCode",
515
568
  params
516
569
  );
517
- if (response.success) {
570
+ if (response.status) {
518
571
  const hookName = params.type === import_types.VerificationCodeType.EMAIL ? import_types.RegisterAndLoginHooks.onEmailVerificationVerified : import_types.RegisterAndLoginHooks.onSmsVerificationVerified;
519
572
  await this.core.effects.emit(hookName, {
520
573
  target: params.target,
@@ -551,16 +604,11 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
551
604
  "register",
552
605
  params
553
606
  );
554
- if (response.success && response.data) {
607
+ if (response.status && response.data) {
555
608
  const { user, token, refreshToken, expiresAt } = response.data;
556
609
  if (token) {
557
610
  this.store.currentUser = user;
558
611
  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
612
  }
565
613
  await this.core.effects.emit(
566
614
  import_types.RegisterAndLoginHooks.onRegisterSuccess,
@@ -600,15 +648,10 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
600
648
  "login",
601
649
  params
602
650
  );
603
- if (response.success && response.data) {
651
+ if (response.status && response.data) {
604
652
  const { user, token, refreshToken } = response.data;
605
653
  this.store.currentUser = user;
606
654
  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
655
  await this.core.effects.emit(
613
656
  import_types.RegisterAndLoginHooks.onLoginSuccess,
614
657
  response.data
@@ -644,15 +687,10 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
644
687
  params
645
688
  );
646
689
  const response = await this.apiCaller.call("oauthLogin", params);
647
- if (response.success && response.data) {
690
+ if (response.status && response.data) {
648
691
  const { user, token, refreshToken } = response.data;
649
692
  this.store.currentUser = user;
650
693
  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
694
  await this.core.effects.emit(
657
695
  import_types.RegisterAndLoginHooks.onOAuthLoginSuccess,
658
696
  response.data
@@ -697,7 +735,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
697
735
  "sendResetPasswordLink",
698
736
  params
699
737
  );
700
- if (response.success) {
738
+ if (response.status) {
701
739
  this.store.verificationCodeSent[params.email] = {
702
740
  sent: true,
703
741
  sentAt: Date.now(),
@@ -728,7 +766,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
728
766
  "checkResetPasswordCode",
729
767
  params
730
768
  );
731
- if (!response.success) {
769
+ if (!response.status) {
732
770
  this.store.error = response.message || "验证码无效";
733
771
  }
734
772
  return response;
@@ -748,7 +786,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
748
786
  "checkEmailLinkCode",
749
787
  params
750
788
  );
751
- if (!response.success) {
789
+ if (!response.status) {
752
790
  this.store.error = response.message || "邮件链接验证码无效";
753
791
  }
754
792
  return response;
@@ -771,7 +809,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
771
809
  "resetPasswordByCode",
772
810
  params
773
811
  );
774
- if (response.success) {
812
+ if (response.status) {
775
813
  this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
776
814
  code: params.code
777
815
  });
@@ -837,7 +875,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
837
875
  }
838
876
  );
839
877
  }
840
- if (response.success) {
878
+ if (response.status) {
841
879
  const key = params.type === "email" ? params.target.email : params.target.phone;
842
880
  if (this.store.verificationCodeSent[key]) {
843
881
  delete this.store.verificationCodeSent[key];
@@ -893,7 +931,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
893
931
  "sendSmsLoginCode",
894
932
  params
895
933
  );
896
- if (response.success) {
934
+ if (response.status) {
897
935
  const now = Date.now();
898
936
  this.store.verificationCodeSent[params.phone] = {
899
937
  sent: true,
@@ -946,7 +984,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
946
984
  "phoneCodeLogin",
947
985
  params
948
986
  );
949
- if (response.success && response.data) {
987
+ if (response.status && response.data) {
950
988
  this.store.isLoggedIn = true;
951
989
  this.store.userInfo = response.data.user;
952
990
  this.store.token = response.data.token;
@@ -986,7 +1024,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
986
1024
  type: "guest"
987
1025
  });
988
1026
  const response = await this.apiCaller.call("guestLogin", this.channel);
989
- if (response.success && response.data) {
1027
+ if (response.status && response.data) {
990
1028
  this.store.isLoggedIn = true;
991
1029
  this.store.userInfo = response.data.user;
992
1030
  this.store.token = response.data.token;
@@ -1023,7 +1061,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1023
1061
  this.store.isLoading = true;
1024
1062
  this.store.error = null;
1025
1063
  const response = await this.apiCaller.call("checkEmailExists", params);
1026
- if (!response.success) {
1064
+ if (!response.status) {
1027
1065
  this.store.error = response.message || "检查邮箱失败";
1028
1066
  }
1029
1067
  return response;
@@ -1040,7 +1078,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1040
1078
  this.store.isLoading = true;
1041
1079
  this.store.error = null;
1042
1080
  const response = await this.apiCaller.call("checkEmailCode", params);
1043
- if (!response.success) {
1081
+ if (!response.status) {
1044
1082
  this.store.error = response.message || "检查邮箱验证码失败";
1045
1083
  }
1046
1084
  return response;
@@ -1057,7 +1095,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1057
1095
  this.store.isLoading = true;
1058
1096
  this.store.error = null;
1059
1097
  const response = await this.apiCaller.call("checkMobileCode", params);
1060
- if (!response.success) {
1098
+ if (!response.status) {
1061
1099
  this.store.error = response.message || "检查手机验证码失败";
1062
1100
  }
1063
1101
  return response;
@@ -1081,7 +1119,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1081
1119
  "phonePasswordLogin",
1082
1120
  params
1083
1121
  );
1084
- if (response.success && response.data) {
1122
+ if (response.status && response.data) {
1085
1123
  this.store.isLoggedIn = true;
1086
1124
  this.store.userInfo = response.data.user;
1087
1125
  this.store.token = response.data.token;
@@ -1121,7 +1159,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1121
1159
  "sendPasswordResetEmail",
1122
1160
  params
1123
1161
  );
1124
- if (response.success) {
1162
+ if (response.status) {
1125
1163
  const now = Date.now();
1126
1164
  this.store.verificationCodeSent[params.email] = {
1127
1165
  sent: true,
@@ -1164,7 +1202,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1164
1202
  "sendPasswordResetSms",
1165
1203
  params
1166
1204
  );
1167
- if (response.success) {
1205
+ if (response.status) {
1168
1206
  return response;
1169
1207
  } else {
1170
1208
  this.store.error = response.message || "发送手机号验证码重置密码失败";
@@ -1406,12 +1444,39 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1406
1444
  * 获取国家区号列表
1407
1445
  */
1408
1446
  async getCountries() {
1447
+ const CACHE_KEY = "pisell_countries_cache";
1409
1448
  try {
1410
1449
  this.store.isLoading = true;
1411
1450
  this.store.error = null;
1451
+ if (this.countriesCache) {
1452
+ this.store.isLoading = false;
1453
+ return this.countriesCache;
1454
+ }
1455
+ let cachedData = null;
1456
+ try {
1457
+ const cached = this.window.localStorage.getItem(CACHE_KEY);
1458
+ if (cached) {
1459
+ cachedData = JSON.parse(cached);
1460
+ }
1461
+ } catch (error) {
1462
+ console.warn("[RegisterAndLogin] localStorage 缓存解析失败:", error);
1463
+ }
1464
+ if (cachedData && Array.isArray(cachedData) && cachedData.length > 0) {
1465
+ this.countriesCache = cachedData;
1466
+ this.updateCountriesCache(CACHE_KEY, cachedData);
1467
+ this.store.isLoading = false;
1468
+ return cachedData;
1469
+ }
1412
1470
  const response = await this.apiCaller.call("getCountries");
1413
1471
  if (response.status && response.data) {
1414
- return response.data;
1472
+ const countries = response.data;
1473
+ this.countriesCache = countries;
1474
+ try {
1475
+ localStorage.setItem(CACHE_KEY, JSON.stringify(countries));
1476
+ } catch (error) {
1477
+ console.warn("[RegisterAndLogin] localStorage 存储失败:", error);
1478
+ }
1479
+ return countries;
1415
1480
  } else {
1416
1481
  this.store.error = response.message || "获取国家区号失败";
1417
1482
  throw new Error(this.store.error);
@@ -1424,6 +1489,29 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1424
1489
  this.store.isLoading = false;
1425
1490
  }
1426
1491
  }
1492
+ /**
1493
+ * 异步更新国家缓存数据
1494
+ */
1495
+ async updateCountriesCache(cacheKey, cachedData) {
1496
+ try {
1497
+ const response = await this.apiCaller.call("getCountries");
1498
+ if (response.status && response.data) {
1499
+ const newData = response.data;
1500
+ const hasChanged = newData.length !== cachedData.length || JSON.stringify(newData) !== JSON.stringify(cachedData);
1501
+ if (hasChanged) {
1502
+ this.countriesCache = newData;
1503
+ try {
1504
+ localStorage.setItem(cacheKey, JSON.stringify(newData));
1505
+ } catch (error) {
1506
+ console.warn("[RegisterAndLogin] localStorage 更新失败:", error);
1507
+ }
1508
+ console.log("[RegisterAndLogin] 国家数据已更新");
1509
+ }
1510
+ }
1511
+ } catch (error) {
1512
+ console.warn("[RegisterAndLogin] 后台更新国家数据失败:", error);
1513
+ }
1514
+ }
1427
1515
  async destroy() {
1428
1516
  await this.core.effects.emit(import_types.RegisterAndLoginHooks.onDestroy, {});
1429
1517
  console.log("[RegisterAndLogin] 已销毁");
@@ -194,7 +194,7 @@ export interface RegisterAndLoginState {
194
194
  * API 响应接口
195
195
  */
196
196
  export interface ApiResponse<T = any> {
197
- success: boolean;
197
+ status: boolean;
198
198
  data?: T;
199
199
  message?: string;
200
200
  error?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.336",
4
+ "version": "0.0.338",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",