@misiki/gocommerce-connector 0.4.7 → 0.4.9
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.
- package/dist/{index-CQTW5q1J.d.cts → index-oCv5Dabq.d.cts} +45 -6
- package/dist/{index-CQTW5q1J.d.ts → index-oCv5Dabq.d.ts} +45 -6
- package/dist/index.cjs +46 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +46 -10
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +46 -10
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +46 -10
- package/dist/services/index.js.map +1 -1
- package/package.json +1 -1
package/dist/services/index.cjs
CHANGED
|
@@ -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
|
-
/**
|
|
2070
|
-
|
|
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: {
|
|
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
|
}
|
|
@@ -2234,19 +2247,42 @@ var AuthService = class extends UserService {
|
|
|
2234
2247
|
return { errorCode: err.code ?? "invalid_token", message: err.message };
|
|
2235
2248
|
}
|
|
2236
2249
|
}
|
|
2237
|
-
/**
|
|
2238
|
-
|
|
2250
|
+
/**
|
|
2251
|
+
* Texts a 4-digit sign-in code to `phone`, which needs its country code. `domain`, the page's
|
|
2252
|
+
* host and in the browser read from it, lets the engine end the text "@domain #code" when the
|
|
2253
|
+
* host is the store's own, which Chrome on Android reads to fill the code in (D124).
|
|
2254
|
+
*/
|
|
2255
|
+
async getOtp({ phone, domain }) {
|
|
2256
|
+
const site = domain ?? (typeof window !== "undefined" ? window.location?.hostname : void 0);
|
|
2239
2257
|
const res = await this.account("/x/identity/otp", {
|
|
2240
2258
|
method: "POST",
|
|
2241
|
-
body: { phone: String(phone ?? "").trim() }
|
|
2259
|
+
body: { phone: String(phone ?? "").trim(), ...site ? { domain: site } : {} }
|
|
2242
2260
|
});
|
|
2243
2261
|
return { expiresInMinutes: res?.expires_in_minutes ?? 10 };
|
|
2244
2262
|
}
|
|
2245
|
-
/**
|
|
2246
|
-
|
|
2247
|
-
|
|
2263
|
+
/**
|
|
2264
|
+
* Signs in the account on `phone` with the code it was sent, opening one the first time.
|
|
2265
|
+
* With `askIfNew`, on a store that signs in either way, a phone with no account opens none:
|
|
2266
|
+
* the answer is `{ newPhone: true, phoneToken }`, and the storefront asks "Already have an
|
|
2267
|
+
* account?" — `login` with the token adds the phone to it, `openPhoneAccount` opens a new one (D123).
|
|
2268
|
+
*/
|
|
2269
|
+
async verifyOtp({ phone, otp, askIfNew }) {
|
|
2270
|
+
const res = await this.account("/x/identity/otp/verify", {
|
|
2248
2271
|
method: "POST",
|
|
2249
|
-
body: {
|
|
2272
|
+
body: {
|
|
2273
|
+
phone: String(phone ?? "").trim(),
|
|
2274
|
+
code: String(otp ?? "").trim(),
|
|
2275
|
+
...askIfNew ? { ask_if_new: true } : {}
|
|
2276
|
+
}
|
|
2277
|
+
});
|
|
2278
|
+
if ("new_phone" in res && res.new_phone) return { newPhone: true, phoneToken: res.phone_token };
|
|
2279
|
+
return this.signedIn(res);
|
|
2280
|
+
}
|
|
2281
|
+
/** Opens a new account on a phone `verifyOtp({ askIfNew: true })` proved, and signs it in (D123). */
|
|
2282
|
+
async openPhoneAccount({ phone, phoneToken }) {
|
|
2283
|
+
const auth = await this.account("/x/identity/otp/new-account", {
|
|
2284
|
+
method: "POST",
|
|
2285
|
+
body: { phone: String(phone ?? "").trim(), phone_token: phoneToken }
|
|
2250
2286
|
});
|
|
2251
2287
|
return this.signedIn(auth);
|
|
2252
2288
|
}
|