@pisell/pisellos 0.0.336 → 0.0.337

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",
@@ -49,6 +49,10 @@ export declare class RegisterAndLoginImpl extends BaseModule implements Module {
49
49
  * 发送邮箱验证码
50
50
  */
51
51
  sendEmailVerificationCode(params: SendVerificationCodeParams): Promise<ApiResponse>;
52
+ /**
53
+ * 发送邮箱登录验证码
54
+ */
55
+ sendEmailLoginCode(params: SendVerificationCodeParams): Promise<ApiResponse>;
52
56
  /**
53
57
  * 发送手机号注册验证码
54
58
  */
@@ -47,7 +47,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
47
47
  const error = "没有找到邮箱注册链接的 code,请先调用 sendEmailRegisterLink";
48
48
  this.store.error = error;
49
49
  return {
50
- success: false,
50
+ status: false,
51
51
  message: error
52
52
  };
53
53
  }
@@ -57,7 +57,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
57
57
  "resendEmailRegisterLink",
58
58
  { code: this.store.emailRegisterLinkCode }
59
59
  );
60
- if (response.success) {
60
+ if (response.status) {
61
61
  await this.core.effects.emit(
62
62
  import_types.RegisterAndLoginHooks.onEmailVerificationSent,
63
63
  {
@@ -107,7 +107,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
107
107
  "emailCodeRegister",
108
108
  params
109
109
  );
110
- if (response.success && response.data) {
110
+ if (response.status && response.data) {
111
111
  const { user, token, refreshToken, expiresAt } = response.data;
112
112
  if (token) {
113
113
  this.store.currentUser = user;
@@ -151,7 +151,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
151
151
  "phoneCodeRegister",
152
152
  params
153
153
  );
154
- if (response.success && response.data) {
154
+ if (response.status && response.data) {
155
155
  const { user, token, refreshToken, expiresAt } = response.data;
156
156
  if (token) {
157
157
  this.store.currentUser = user;
@@ -233,7 +233,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
233
233
  "validateToken",
234
234
  token
235
235
  );
236
- if (response.success && response.data) {
236
+ if (response.status && response.data) {
237
237
  this.store.currentUser = response.data;
238
238
  return true;
239
239
  } else {
@@ -267,7 +267,58 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
267
267
  "sendEmailVerificationCode",
268
268
  params
269
269
  );
270
- if (response.success) {
270
+ if (response.status) {
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 sendEmailLoginCode(params) {
314
+ try {
315
+ this.store.isLoading = true;
316
+ this.store.error = null;
317
+ const response = await this.apiCaller.call(
318
+ "sendEmailLoginCode",
319
+ params
320
+ );
321
+ if (response.status) {
271
322
  const now = Date.now();
272
323
  this.store.verificationCodeSent[params.target] = {
273
324
  sent: true,
@@ -318,7 +369,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
318
369
  "sendSmsRegisterCode",
319
370
  params
320
371
  );
321
- if (response.success) {
372
+ if (response.status) {
322
373
  const now = Date.now();
323
374
  this.store.verificationCodeSent[params.phone] = {
324
375
  sent: true,
@@ -370,7 +421,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
370
421
  "sendEmailRegisterLink",
371
422
  email
372
423
  );
373
- if (response.success) {
424
+ if (response.status) {
374
425
  if ((_a = response.data) == null ? void 0 : _a.code) {
375
426
  this.store.emailRegisterLinkCode = response.data.code;
376
427
  }
@@ -424,7 +475,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
424
475
  "verifyEmailRegistrationLink",
425
476
  params
426
477
  );
427
- if (response.success) {
478
+ if (response.status) {
428
479
  await this.core.effects.emit(
429
480
  import_types.RegisterAndLoginHooks.onEmailVerificationVerified,
430
481
  {
@@ -472,7 +523,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
472
523
  "emailPasswordLogin",
473
524
  params
474
525
  );
475
- if (response.success && response.data) {
526
+ if (response.status && response.data) {
476
527
  this.store.isLoggedIn = true;
477
528
  this.store.userInfo = response.data.user;
478
529
  this.store.token = response.data.token;
@@ -514,7 +565,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
514
565
  "verifyCode",
515
566
  params
516
567
  );
517
- if (response.success) {
568
+ if (response.status) {
518
569
  const hookName = params.type === import_types.VerificationCodeType.EMAIL ? import_types.RegisterAndLoginHooks.onEmailVerificationVerified : import_types.RegisterAndLoginHooks.onSmsVerificationVerified;
519
570
  await this.core.effects.emit(hookName, {
520
571
  target: params.target,
@@ -551,7 +602,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
551
602
  "register",
552
603
  params
553
604
  );
554
- if (response.success && response.data) {
605
+ if (response.status && response.data) {
555
606
  const { user, token, refreshToken, expiresAt } = response.data;
556
607
  if (token) {
557
608
  this.store.currentUser = user;
@@ -600,7 +651,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
600
651
  "login",
601
652
  params
602
653
  );
603
- if (response.success && response.data) {
654
+ if (response.status && response.data) {
604
655
  const { user, token, refreshToken } = response.data;
605
656
  this.store.currentUser = user;
606
657
  this.store.isLoggedIn = true;
@@ -644,7 +695,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
644
695
  params
645
696
  );
646
697
  const response = await this.apiCaller.call("oauthLogin", params);
647
- if (response.success && response.data) {
698
+ if (response.status && response.data) {
648
699
  const { user, token, refreshToken } = response.data;
649
700
  this.store.currentUser = user;
650
701
  this.store.isLoggedIn = true;
@@ -697,7 +748,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
697
748
  "sendResetPasswordLink",
698
749
  params
699
750
  );
700
- if (response.success) {
751
+ if (response.status) {
701
752
  this.store.verificationCodeSent[params.email] = {
702
753
  sent: true,
703
754
  sentAt: Date.now(),
@@ -728,7 +779,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
728
779
  "checkResetPasswordCode",
729
780
  params
730
781
  );
731
- if (!response.success) {
782
+ if (!response.status) {
732
783
  this.store.error = response.message || "验证码无效";
733
784
  }
734
785
  return response;
@@ -748,7 +799,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
748
799
  "checkEmailLinkCode",
749
800
  params
750
801
  );
751
- if (!response.success) {
802
+ if (!response.status) {
752
803
  this.store.error = response.message || "邮件链接验证码无效";
753
804
  }
754
805
  return response;
@@ -771,7 +822,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
771
822
  "resetPasswordByCode",
772
823
  params
773
824
  );
774
- if (response.success) {
825
+ if (response.status) {
775
826
  this.core.effects.emit(import_types.RegisterAndLoginHooks.onPasswordResetSuccess, {
776
827
  code: params.code
777
828
  });
@@ -837,7 +888,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
837
888
  }
838
889
  );
839
890
  }
840
- if (response.success) {
891
+ if (response.status) {
841
892
  const key = params.type === "email" ? params.target.email : params.target.phone;
842
893
  if (this.store.verificationCodeSent[key]) {
843
894
  delete this.store.verificationCodeSent[key];
@@ -893,7 +944,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
893
944
  "sendSmsLoginCode",
894
945
  params
895
946
  );
896
- if (response.success) {
947
+ if (response.status) {
897
948
  const now = Date.now();
898
949
  this.store.verificationCodeSent[params.phone] = {
899
950
  sent: true,
@@ -946,7 +997,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
946
997
  "phoneCodeLogin",
947
998
  params
948
999
  );
949
- if (response.success && response.data) {
1000
+ if (response.status && response.data) {
950
1001
  this.store.isLoggedIn = true;
951
1002
  this.store.userInfo = response.data.user;
952
1003
  this.store.token = response.data.token;
@@ -986,7 +1037,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
986
1037
  type: "guest"
987
1038
  });
988
1039
  const response = await this.apiCaller.call("guestLogin", this.channel);
989
- if (response.success && response.data) {
1040
+ if (response.status && response.data) {
990
1041
  this.store.isLoggedIn = true;
991
1042
  this.store.userInfo = response.data.user;
992
1043
  this.store.token = response.data.token;
@@ -1023,7 +1074,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1023
1074
  this.store.isLoading = true;
1024
1075
  this.store.error = null;
1025
1076
  const response = await this.apiCaller.call("checkEmailExists", params);
1026
- if (!response.success) {
1077
+ if (!response.status) {
1027
1078
  this.store.error = response.message || "检查邮箱失败";
1028
1079
  }
1029
1080
  return response;
@@ -1040,7 +1091,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1040
1091
  this.store.isLoading = true;
1041
1092
  this.store.error = null;
1042
1093
  const response = await this.apiCaller.call("checkEmailCode", params);
1043
- if (!response.success) {
1094
+ if (!response.status) {
1044
1095
  this.store.error = response.message || "检查邮箱验证码失败";
1045
1096
  }
1046
1097
  return response;
@@ -1057,7 +1108,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1057
1108
  this.store.isLoading = true;
1058
1109
  this.store.error = null;
1059
1110
  const response = await this.apiCaller.call("checkMobileCode", params);
1060
- if (!response.success) {
1111
+ if (!response.status) {
1061
1112
  this.store.error = response.message || "检查手机验证码失败";
1062
1113
  }
1063
1114
  return response;
@@ -1081,7 +1132,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1081
1132
  "phonePasswordLogin",
1082
1133
  params
1083
1134
  );
1084
- if (response.success && response.data) {
1135
+ if (response.status && response.data) {
1085
1136
  this.store.isLoggedIn = true;
1086
1137
  this.store.userInfo = response.data.user;
1087
1138
  this.store.token = response.data.token;
@@ -1121,7 +1172,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1121
1172
  "sendPasswordResetEmail",
1122
1173
  params
1123
1174
  );
1124
- if (response.success) {
1175
+ if (response.status) {
1125
1176
  const now = Date.now();
1126
1177
  this.store.verificationCodeSent[params.email] = {
1127
1178
  sent: true,
@@ -1164,7 +1215,7 @@ var RegisterAndLoginImpl = class extends import_BaseModule.BaseModule {
1164
1215
  "sendPasswordResetSms",
1165
1216
  params
1166
1217
  );
1167
- if (response.success) {
1218
+ if (response.status) {
1168
1219
  return response;
1169
1220
  } else {
1170
1221
  this.store.error = response.message || "发送手机号验证码重置密码失败";
@@ -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.337",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",