@misiki/gocommerce-connector 0.4.5 → 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.
- package/dist/{index-CmPI-hcH.d.cts → index-CQTW5q1J.d.cts} +47 -1
- package/dist/{index-CmPI-hcH.d.ts → index-CQTW5q1J.d.ts} +47 -1
- package/dist/index.cjs +50 -4
- 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 +50 -4
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +50 -4
- 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 +50 -4
- package/dist/services/index.js.map +1 -1
- package/package.json +1 -1
package/dist/services/index.cjs
CHANGED
|
@@ -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,
|
|
@@ -1013,6 +1015,13 @@ var StoreFacts = class extends BaseService {
|
|
|
1013
1015
|
profile() {
|
|
1014
1016
|
return remember(this.key("profile"), () => this.data("/api/store"));
|
|
1015
1017
|
}
|
|
1018
|
+
/** Where the store delivers (D117): its priced zones' countries, or everywhere. */
|
|
1019
|
+
shipsTo() {
|
|
1020
|
+
return remember(this.key("ships-to"), async () => {
|
|
1021
|
+
const r = await this.data("/api/checkout/countries");
|
|
1022
|
+
return { everywhere: r?.everywhere ?? true, countries: r?.countries ?? [] };
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1016
1025
|
checkoutOptions() {
|
|
1017
1026
|
return remember(this.key("checkout"), () => this.data("/api/checkout"));
|
|
1018
1027
|
}
|
|
@@ -2194,7 +2203,7 @@ var AuthService = class extends UserService {
|
|
|
2194
2203
|
async loginMethod() {
|
|
2195
2204
|
try {
|
|
2196
2205
|
const method = (await this.facts.plugins()).get("identity")?.settings?.login_method;
|
|
2197
|
-
return method === "phone_otp"
|
|
2206
|
+
return method === "phone_otp" || method === "email_or_phone" ? method : "email_password";
|
|
2198
2207
|
} catch {
|
|
2199
2208
|
return "email_password";
|
|
2200
2209
|
}
|
|
@@ -2252,6 +2261,25 @@ var ProfileService = class extends UserService {
|
|
|
2252
2261
|
async save(profile) {
|
|
2253
2262
|
return this.updateProfile(profile);
|
|
2254
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
|
+
}
|
|
2255
2283
|
};
|
|
2256
2284
|
var userService = new UserService();
|
|
2257
2285
|
var authService = new AuthService();
|
|
@@ -2560,12 +2588,14 @@ var StoreService = class extends BaseService {
|
|
|
2560
2588
|
return super.post(path, data);
|
|
2561
2589
|
}
|
|
2562
2590
|
async live() {
|
|
2563
|
-
const [ready, plugins, menus, base, profile] = await Promise.all([
|
|
2591
|
+
const [ready, plugins, menus, base, profile, ships] = await Promise.all([
|
|
2564
2592
|
this.facts.ready(),
|
|
2565
2593
|
this.facts.plugins().catch(() => /* @__PURE__ */ new Map()),
|
|
2566
2594
|
new MenuService(this._fetch).engineMenus(),
|
|
2567
2595
|
readStaticStore(),
|
|
2568
|
-
this.facts.profile().catch(() => null)
|
|
2596
|
+
this.facts.profile().catch(() => null),
|
|
2597
|
+
// An engine without the route rules nothing out.
|
|
2598
|
+
this.facts.shipsTo().catch(() => ({ everywhere: true, countries: [] }))
|
|
2569
2599
|
]);
|
|
2570
2600
|
const code = ready.currency;
|
|
2571
2601
|
const sameCurrency = (base.currency?.code ?? base.currencyCode) === code;
|
|
@@ -2595,14 +2625,30 @@ var StoreService = class extends BaseService {
|
|
|
2595
2625
|
}
|
|
2596
2626
|
},
|
|
2597
2627
|
...menus?.length ? { menu: menus } : {},
|
|
2628
|
+
...deliverable(base, ships),
|
|
2598
2629
|
// The one way this store signs customers in (D116), which the sign-in
|
|
2599
2630
|
// form reads as PHONE or EMAIL. Without the accounts module the static
|
|
2600
2631
|
// record says.
|
|
2601
|
-
...plugins.has("identity") ? { loginType: plugins.get("identity")?.settings?.login_method
|
|
2632
|
+
...plugins.has("identity") ? { loginType: LOGIN_TYPES[String(plugins.get("identity")?.settings?.login_method)] ?? "EMAIL" } : {}
|
|
2602
2633
|
};
|
|
2603
2634
|
}
|
|
2604
2635
|
};
|
|
2605
2636
|
var storeService = new StoreService();
|
|
2637
|
+
function deliverable(base, ships) {
|
|
2638
|
+
if (ships.everywhere || !ships.countries.length) return {};
|
|
2639
|
+
const known = new Map((base.countries ?? []).map((c) => [String(c.code).toUpperCase(), c]));
|
|
2640
|
+
const countries = ships.countries.map((code) => known.get(code) ?? { code, name: regionName(code) });
|
|
2641
|
+
const keep = base.country && ships.countries.includes(String(base.country.code).toUpperCase());
|
|
2642
|
+
return { countries, ...keep ? {} : { country: countries[0] } };
|
|
2643
|
+
}
|
|
2644
|
+
function regionName(code) {
|
|
2645
|
+
try {
|
|
2646
|
+
return new Intl.DisplayNames(["en"], { type: "region" }).of(code) ?? code;
|
|
2647
|
+
} catch {
|
|
2648
|
+
return code;
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
var LOGIN_TYPES = { phone_otp: "PHONE", email_or_phone: "BOTH", email_password: "EMAIL" };
|
|
2606
2652
|
|
|
2607
2653
|
// src/services/page-service.ts
|
|
2608
2654
|
var PageService = class extends BaseService {
|