@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.
@@ -132,6 +132,7 @@ function toMe(c) {
132
132
  avatar: null,
133
133
  role: "USER",
134
134
  emailVerified: c.email_verified,
135
+ phoneVerified: !!c.phone_verified,
135
136
  storeId: null
136
137
  };
137
138
  }
@@ -954,6 +955,7 @@ function toUser(c) {
954
955
  email: c.email,
955
956
  emailVerified: c.email_verified,
956
957
  phone: c.phone || null,
958
+ phoneVerified: !!c.phone_verified,
957
959
  firstName: firstName || "",
958
960
  lastName: rest.join(" "),
959
961
  name: c.name,
@@ -2201,7 +2203,7 @@ var AuthService = class extends UserService {
2201
2203
  async loginMethod() {
2202
2204
  try {
2203
2205
  const method = (await this.facts.plugins()).get("identity")?.settings?.login_method;
2204
- return method === "phone_otp" ? "phone_otp" : "email_password";
2206
+ return method === "phone_otp" || method === "email_or_phone" ? method : "email_password";
2205
2207
  } catch {
2206
2208
  return "email_password";
2207
2209
  }
@@ -2259,6 +2261,25 @@ var ProfileService = class extends UserService {
2259
2261
  async save(profile) {
2260
2262
  return this.updateProfile(profile);
2261
2263
  }
2264
+ /** Texts a code to a phone the signed-in shopper wants to add (D118). */
2265
+ async requestPhoneLink({ phone }) {
2266
+ const res = await this.account("/x/identity/me/phone", {
2267
+ method: "POST",
2268
+ auth: true,
2269
+ body: { phone: String(phone ?? "").trim() }
2270
+ });
2271
+ return { expiresInMinutes: res?.expires_in_minutes ?? 10 };
2272
+ }
2273
+ /** Adds the phone with its code; from then on it signs in to this account too. */
2274
+ async verifyPhoneLink({ phone, otp }) {
2275
+ const c = await this.account("/x/identity/me/phone/verify", {
2276
+ method: "POST",
2277
+ auth: true,
2278
+ body: { phone: String(phone ?? "").trim(), code: String(otp ?? "").trim() }
2279
+ });
2280
+ updateMe(c);
2281
+ return toUser(c);
2282
+ }
2262
2283
  };
2263
2284
  var userService = new UserService();
2264
2285
  var authService = new AuthService();
@@ -2608,7 +2629,7 @@ var StoreService = class extends BaseService {
2608
2629
  // The one way this store signs customers in (D116), which the sign-in
2609
2630
  // form reads as PHONE or EMAIL. Without the accounts module the static
2610
2631
  // record says.
2611
- ...plugins.has("identity") ? { loginType: plugins.get("identity")?.settings?.login_method === "phone_otp" ? "PHONE" : "EMAIL" } : {}
2632
+ ...plugins.has("identity") ? { loginType: LOGIN_TYPES[String(plugins.get("identity")?.settings?.login_method)] ?? "EMAIL" } : {}
2612
2633
  };
2613
2634
  }
2614
2635
  };
@@ -2627,6 +2648,7 @@ function regionName(code) {
2627
2648
  return code;
2628
2649
  }
2629
2650
  }
2651
+ var LOGIN_TYPES = { phone_otp: "PHONE", email_or_phone: "BOTH", email_password: "EMAIL" };
2630
2652
 
2631
2653
  // src/services/page-service.ts
2632
2654
  var PageService = class extends BaseService {