@misiki/gocommerce-connector 0.4.7 → 0.4.8

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.
@@ -2066,11 +2066,24 @@ var orderService = new OrderService();
2066
2066
 
2067
2067
  // src/services/user-service.ts
2068
2068
  var UserService = class extends BaseService {
2069
- /** Email and password. The answer is the user object the storefront keeps in its `me` cookie. */
2070
- async login({ email, password }) {
2069
+ /**
2070
+ * Email and password. The answer is the user object the storefront keeps in its `me` cookie.
2071
+ * With `phone` and `phoneToken` from `verifyOtp({ askIfNew: true })`, the phone is added to
2072
+ * the account as it signs in (D123).
2073
+ */
2074
+ async login({
2075
+ email,
2076
+ password,
2077
+ phone,
2078
+ phoneToken
2079
+ }) {
2071
2080
  const auth = await this.account("/x/identity/login", {
2072
2081
  method: "POST",
2073
- body: { email: String(email ?? "").trim(), password: String(password ?? "") }
2082
+ body: {
2083
+ email: String(email ?? "").trim(),
2084
+ password: String(password ?? ""),
2085
+ ...phoneToken ? { phone: String(phone ?? "").trim(), phone_token: phoneToken } : {}
2086
+ }
2074
2087
  });
2075
2088
  return this.signedIn(auth);
2076
2089
  }
@@ -2242,11 +2255,29 @@ var AuthService = class extends UserService {
2242
2255
  });
2243
2256
  return { expiresInMinutes: res?.expires_in_minutes ?? 10 };
2244
2257
  }
2245
- /** Signs in the account on `phone` with the code it was sent, opening one the first time. */
2246
- async verifyOtp({ phone, otp }) {
2247
- const auth = await this.account("/x/identity/otp/verify", {
2258
+ /**
2259
+ * Signs in the account on `phone` with the code it was sent, opening one the first time.
2260
+ * With `askIfNew`, on a store that signs in either way, a phone with no account opens none:
2261
+ * the answer is `{ newPhone: true, phoneToken }`, and the storefront asks "Already have an
2262
+ * account?" — `login` with the token adds the phone to it, `openPhoneAccount` opens a new one (D123).
2263
+ */
2264
+ async verifyOtp({ phone, otp, askIfNew }) {
2265
+ const res = await this.account("/x/identity/otp/verify", {
2248
2266
  method: "POST",
2249
- body: { phone: String(phone ?? "").trim(), code: String(otp ?? "").trim() }
2267
+ body: {
2268
+ phone: String(phone ?? "").trim(),
2269
+ code: String(otp ?? "").trim(),
2270
+ ...askIfNew ? { ask_if_new: true } : {}
2271
+ }
2272
+ });
2273
+ if ("new_phone" in res && res.new_phone) return { newPhone: true, phoneToken: res.phone_token };
2274
+ return this.signedIn(res);
2275
+ }
2276
+ /** Opens a new account on a phone `verifyOtp({ askIfNew: true })` proved, and signs it in (D123). */
2277
+ async openPhoneAccount({ phone, phoneToken }) {
2278
+ const auth = await this.account("/x/identity/otp/new-account", {
2279
+ method: "POST",
2280
+ body: { phone: String(phone ?? "").trim(), phone_token: phoneToken }
2250
2281
  });
2251
2282
  return this.signedIn(auth);
2252
2283
  }