@misiki/gocommerce-connector 0.4.6 → 0.4.7

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.
@@ -374,6 +374,8 @@ type Customer = {
374
374
  id: number;
375
375
  email: string;
376
376
  email_verified: boolean;
377
+ /** The phone was proved with a code and signs in to this account (D118). */
378
+ phone_verified?: boolean;
377
379
  name: string;
378
380
  phone: string;
379
381
  created_at: string;
@@ -1126,6 +1128,7 @@ declare function toUser(c: Customer): {
1126
1128
  email: string;
1127
1129
  emailVerified: boolean;
1128
1130
  phone: string | null;
1131
+ phoneVerified: boolean;
1129
1132
  firstName: string;
1130
1133
  lastName: string;
1131
1134
  name: string;
@@ -4686,6 +4689,7 @@ declare class UserService extends BaseService {
4686
4689
  avatar: null;
4687
4690
  role: string;
4688
4691
  emailVerified: boolean;
4692
+ phoneVerified: boolean;
4689
4693
  storeId: null;
4690
4694
  }>;
4691
4695
  signup({ email, password, firstName, lastName, phone, }: {
@@ -4708,6 +4712,7 @@ declare class UserService extends BaseService {
4708
4712
  avatar: null;
4709
4713
  role: string;
4710
4714
  emailVerified: boolean;
4715
+ phoneVerified: boolean;
4711
4716
  storeId: null;
4712
4717
  }>;
4713
4718
  /** Signs out here and on the engine. The storefront assigns the answer to its user: `null`. */
@@ -4718,6 +4723,7 @@ declare class UserService extends BaseService {
4718
4723
  email: string;
4719
4724
  emailVerified: boolean;
4720
4725
  phone: string | null;
4726
+ phoneVerified: boolean;
4721
4727
  firstName: string;
4722
4728
  lastName: string;
4723
4729
  name: string;
@@ -4739,6 +4745,7 @@ declare class UserService extends BaseService {
4739
4745
  email: string;
4740
4746
  emailVerified: boolean;
4741
4747
  phone: string | null;
4748
+ phoneVerified: boolean;
4742
4749
  firstName: string;
4743
4750
  lastName: string;
4744
4751
  name: string;
@@ -4763,6 +4770,7 @@ declare class UserService extends BaseService {
4763
4770
  email: string;
4764
4771
  emailVerified: boolean;
4765
4772
  phone: string | null;
4773
+ phoneVerified: boolean;
4766
4774
  firstName: string;
4767
4775
  lastName: string;
4768
4776
  name: string;
@@ -4793,6 +4801,7 @@ declare class UserService extends BaseService {
4793
4801
  avatar: null;
4794
4802
  role: string;
4795
4803
  emailVerified: boolean;
4804
+ phoneVerified: boolean;
4796
4805
  storeId: null;
4797
4806
  }>;
4798
4807
  /**
@@ -4918,6 +4927,7 @@ declare class UserService extends BaseService {
4918
4927
  avatar: null;
4919
4928
  role: string;
4920
4929
  emailVerified: boolean;
4930
+ phoneVerified: boolean;
4921
4931
  storeId: null;
4922
4932
  }>;
4923
4933
  /** An identity call, with a 404 from a build without the module said in words. */
@@ -4934,7 +4944,7 @@ declare class AuthService extends UserService {
4934
4944
  * How this store signs customers in: `email_password` or `phone_otp`.
4935
4945
  * A store whose accounts module says nothing signs in by email.
4936
4946
  */
4937
- loginMethod(): Promise<'email_password' | 'phone_otp'>;
4947
+ loginMethod(): Promise<'email_password' | 'phone_otp' | 'email_or_phone'>;
4938
4948
  forgotPassword({ email }: {
4939
4949
  email: string;
4940
4950
  referrer?: string;
@@ -4958,6 +4968,7 @@ declare class AuthService extends UserService {
4958
4968
  avatar: null;
4959
4969
  role: string;
4960
4970
  emailVerified: boolean;
4971
+ phoneVerified: boolean;
4961
4972
  storeId: null;
4962
4973
  }>;
4963
4974
  /** Answers `{ errorCode, message }` on failure rather than throwing: that is how the page reads it. */
@@ -4968,6 +4979,7 @@ declare class AuthService extends UserService {
4968
4979
  email: string;
4969
4980
  emailVerified: boolean;
4970
4981
  phone: string | null;
4982
+ phoneVerified: boolean;
4971
4983
  firstName: string;
4972
4984
  lastName: string;
4973
4985
  name: string;
@@ -5003,6 +5015,7 @@ declare class AuthService extends UserService {
5003
5015
  avatar: null;
5004
5016
  role: string;
5005
5017
  emailVerified: boolean;
5018
+ phoneVerified: boolean;
5006
5019
  storeId: null;
5007
5020
  }>;
5008
5021
  joinAsAdmin(): Promise<never>;
@@ -5015,6 +5028,7 @@ declare class ProfileService extends UserService {
5015
5028
  email: string;
5016
5029
  emailVerified: boolean;
5017
5030
  phone: string | null;
5031
+ phoneVerified: boolean;
5018
5032
  firstName: string;
5019
5033
  lastName: string;
5020
5034
  name: string;
@@ -5035,6 +5049,33 @@ declare class ProfileService extends UserService {
5035
5049
  email: string;
5036
5050
  emailVerified: boolean;
5037
5051
  phone: string | null;
5052
+ phoneVerified: boolean;
5053
+ firstName: string;
5054
+ lastName: string;
5055
+ name: string;
5056
+ fullName: string;
5057
+ avatar: null;
5058
+ role: string;
5059
+ createdAt: string;
5060
+ updatedAt: string;
5061
+ }>;
5062
+ /** Texts a code to a phone the signed-in shopper wants to add (D118). */
5063
+ requestPhoneLink({ phone }: {
5064
+ phone: string;
5065
+ }): Promise<{
5066
+ expiresInMinutes: number;
5067
+ }>;
5068
+ /** Adds the phone with its code; from then on it signs in to this account too. */
5069
+ verifyPhoneLink({ phone, otp }: {
5070
+ phone: string;
5071
+ otp: string;
5072
+ }): Promise<{
5073
+ id: string;
5074
+ userId: string;
5075
+ email: string;
5076
+ emailVerified: boolean;
5077
+ phone: string | null;
5078
+ phoneVerified: boolean;
5038
5079
  firstName: string;
5039
5080
  lastName: string;
5040
5081
  name: string;
@@ -374,6 +374,8 @@ type Customer = {
374
374
  id: number;
375
375
  email: string;
376
376
  email_verified: boolean;
377
+ /** The phone was proved with a code and signs in to this account (D118). */
378
+ phone_verified?: boolean;
377
379
  name: string;
378
380
  phone: string;
379
381
  created_at: string;
@@ -1126,6 +1128,7 @@ declare function toUser(c: Customer): {
1126
1128
  email: string;
1127
1129
  emailVerified: boolean;
1128
1130
  phone: string | null;
1131
+ phoneVerified: boolean;
1129
1132
  firstName: string;
1130
1133
  lastName: string;
1131
1134
  name: string;
@@ -4686,6 +4689,7 @@ declare class UserService extends BaseService {
4686
4689
  avatar: null;
4687
4690
  role: string;
4688
4691
  emailVerified: boolean;
4692
+ phoneVerified: boolean;
4689
4693
  storeId: null;
4690
4694
  }>;
4691
4695
  signup({ email, password, firstName, lastName, phone, }: {
@@ -4708,6 +4712,7 @@ declare class UserService extends BaseService {
4708
4712
  avatar: null;
4709
4713
  role: string;
4710
4714
  emailVerified: boolean;
4715
+ phoneVerified: boolean;
4711
4716
  storeId: null;
4712
4717
  }>;
4713
4718
  /** Signs out here and on the engine. The storefront assigns the answer to its user: `null`. */
@@ -4718,6 +4723,7 @@ declare class UserService extends BaseService {
4718
4723
  email: string;
4719
4724
  emailVerified: boolean;
4720
4725
  phone: string | null;
4726
+ phoneVerified: boolean;
4721
4727
  firstName: string;
4722
4728
  lastName: string;
4723
4729
  name: string;
@@ -4739,6 +4745,7 @@ declare class UserService extends BaseService {
4739
4745
  email: string;
4740
4746
  emailVerified: boolean;
4741
4747
  phone: string | null;
4748
+ phoneVerified: boolean;
4742
4749
  firstName: string;
4743
4750
  lastName: string;
4744
4751
  name: string;
@@ -4763,6 +4770,7 @@ declare class UserService extends BaseService {
4763
4770
  email: string;
4764
4771
  emailVerified: boolean;
4765
4772
  phone: string | null;
4773
+ phoneVerified: boolean;
4766
4774
  firstName: string;
4767
4775
  lastName: string;
4768
4776
  name: string;
@@ -4793,6 +4801,7 @@ declare class UserService extends BaseService {
4793
4801
  avatar: null;
4794
4802
  role: string;
4795
4803
  emailVerified: boolean;
4804
+ phoneVerified: boolean;
4796
4805
  storeId: null;
4797
4806
  }>;
4798
4807
  /**
@@ -4918,6 +4927,7 @@ declare class UserService extends BaseService {
4918
4927
  avatar: null;
4919
4928
  role: string;
4920
4929
  emailVerified: boolean;
4930
+ phoneVerified: boolean;
4921
4931
  storeId: null;
4922
4932
  }>;
4923
4933
  /** An identity call, with a 404 from a build without the module said in words. */
@@ -4934,7 +4944,7 @@ declare class AuthService extends UserService {
4934
4944
  * How this store signs customers in: `email_password` or `phone_otp`.
4935
4945
  * A store whose accounts module says nothing signs in by email.
4936
4946
  */
4937
- loginMethod(): Promise<'email_password' | 'phone_otp'>;
4947
+ loginMethod(): Promise<'email_password' | 'phone_otp' | 'email_or_phone'>;
4938
4948
  forgotPassword({ email }: {
4939
4949
  email: string;
4940
4950
  referrer?: string;
@@ -4958,6 +4968,7 @@ declare class AuthService extends UserService {
4958
4968
  avatar: null;
4959
4969
  role: string;
4960
4970
  emailVerified: boolean;
4971
+ phoneVerified: boolean;
4961
4972
  storeId: null;
4962
4973
  }>;
4963
4974
  /** Answers `{ errorCode, message }` on failure rather than throwing: that is how the page reads it. */
@@ -4968,6 +4979,7 @@ declare class AuthService extends UserService {
4968
4979
  email: string;
4969
4980
  emailVerified: boolean;
4970
4981
  phone: string | null;
4982
+ phoneVerified: boolean;
4971
4983
  firstName: string;
4972
4984
  lastName: string;
4973
4985
  name: string;
@@ -5003,6 +5015,7 @@ declare class AuthService extends UserService {
5003
5015
  avatar: null;
5004
5016
  role: string;
5005
5017
  emailVerified: boolean;
5018
+ phoneVerified: boolean;
5006
5019
  storeId: null;
5007
5020
  }>;
5008
5021
  joinAsAdmin(): Promise<never>;
@@ -5015,6 +5028,7 @@ declare class ProfileService extends UserService {
5015
5028
  email: string;
5016
5029
  emailVerified: boolean;
5017
5030
  phone: string | null;
5031
+ phoneVerified: boolean;
5018
5032
  firstName: string;
5019
5033
  lastName: string;
5020
5034
  name: string;
@@ -5035,6 +5049,33 @@ declare class ProfileService extends UserService {
5035
5049
  email: string;
5036
5050
  emailVerified: boolean;
5037
5051
  phone: string | null;
5052
+ phoneVerified: boolean;
5053
+ firstName: string;
5054
+ lastName: string;
5055
+ name: string;
5056
+ fullName: string;
5057
+ avatar: null;
5058
+ role: string;
5059
+ createdAt: string;
5060
+ updatedAt: string;
5061
+ }>;
5062
+ /** Texts a code to a phone the signed-in shopper wants to add (D118). */
5063
+ requestPhoneLink({ phone }: {
5064
+ phone: string;
5065
+ }): Promise<{
5066
+ expiresInMinutes: number;
5067
+ }>;
5068
+ /** Adds the phone with its code; from then on it signs in to this account too. */
5069
+ verifyPhoneLink({ phone, otp }: {
5070
+ phone: string;
5071
+ otp: string;
5072
+ }): Promise<{
5073
+ id: string;
5074
+ userId: string;
5075
+ email: string;
5076
+ emailVerified: boolean;
5077
+ phone: string | null;
5078
+ phoneVerified: boolean;
5038
5079
  firstName: string;
5039
5080
  lastName: string;
5040
5081
  name: string;
package/dist/index.cjs CHANGED
@@ -205,6 +205,7 @@ function toMe(c) {
205
205
  avatar: null,
206
206
  role: "USER",
207
207
  emailVerified: c.email_verified,
208
+ phoneVerified: !!c.phone_verified,
208
209
  storeId: null
209
210
  };
210
211
  }
@@ -986,6 +987,7 @@ function toUser(c) {
986
987
  email: c.email,
987
988
  emailVerified: c.email_verified,
988
989
  phone: c.phone || null,
990
+ phoneVerified: !!c.phone_verified,
989
991
  firstName: firstName || "",
990
992
  lastName: rest.join(" "),
991
993
  name: c.name,
@@ -2220,7 +2222,7 @@ var AuthService = class extends UserService {
2220
2222
  async loginMethod() {
2221
2223
  try {
2222
2224
  const method = (await this.facts.plugins()).get("identity")?.settings?.login_method;
2223
- return method === "phone_otp" ? "phone_otp" : "email_password";
2225
+ return method === "phone_otp" || method === "email_or_phone" ? method : "email_password";
2224
2226
  } catch {
2225
2227
  return "email_password";
2226
2228
  }
@@ -2278,6 +2280,25 @@ var ProfileService = class extends UserService {
2278
2280
  async save(profile) {
2279
2281
  return this.updateProfile(profile);
2280
2282
  }
2283
+ /** Texts a code to a phone the signed-in shopper wants to add (D118). */
2284
+ async requestPhoneLink({ phone }) {
2285
+ const res = await this.account("/x/identity/me/phone", {
2286
+ method: "POST",
2287
+ auth: true,
2288
+ body: { phone: String(phone ?? "").trim() }
2289
+ });
2290
+ return { expiresInMinutes: res?.expires_in_minutes ?? 10 };
2291
+ }
2292
+ /** Adds the phone with its code; from then on it signs in to this account too. */
2293
+ async verifyPhoneLink({ phone, otp }) {
2294
+ const c = await this.account("/x/identity/me/phone/verify", {
2295
+ method: "POST",
2296
+ auth: true,
2297
+ body: { phone: String(phone ?? "").trim(), code: String(otp ?? "").trim() }
2298
+ });
2299
+ updateMe(c);
2300
+ return toUser(c);
2301
+ }
2281
2302
  };
2282
2303
  var userService = new UserService();
2283
2304
  var authService = new AuthService();
@@ -2624,7 +2645,7 @@ var StoreService = class extends BaseService {
2624
2645
  // The one way this store signs customers in (D116), which the sign-in
2625
2646
  // form reads as PHONE or EMAIL. Without the accounts module the static
2626
2647
  // record says.
2627
- ...plugins.has("identity") ? { loginType: plugins.get("identity")?.settings?.login_method === "phone_otp" ? "PHONE" : "EMAIL" } : {}
2648
+ ...plugins.has("identity") ? { loginType: LOGIN_TYPES[String(plugins.get("identity")?.settings?.login_method)] ?? "EMAIL" } : {}
2628
2649
  };
2629
2650
  }
2630
2651
  };
@@ -2643,6 +2664,7 @@ function regionName(code) {
2643
2664
  return code;
2644
2665
  }
2645
2666
  }
2667
+ var LOGIN_TYPES = { phone_otp: "PHONE", email_or_phone: "BOTH", email_password: "EMAIL" };
2646
2668
 
2647
2669
  // src/services/page-service.ts
2648
2670
  var PageService = class extends BaseService {