@misiki/gocommerce-connector 0.27.0 → 0.29.0
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/README.md +5 -0
- package/dist/{index-BY0qUnNO.d.cts → index-DOlNI60Y.d.cts} +14 -22
- package/dist/{index-BY0qUnNO.d.ts → index-DOlNI60Y.d.ts} +14 -22
- package/dist/index.cjs +28 -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 +28 -4
- package/dist/index.js.map +1 -1
- package/dist/services/index.cjs +28 -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 +28 -4
- package/dist/services/index.js.map +1 -1
- package/package.json +1 -1
package/dist/services/index.cjs
CHANGED
|
@@ -367,12 +367,19 @@ var BaseService = class _BaseService {
|
|
|
367
367
|
* Prices a cart at the signed-in shopper's customer-group prices. The
|
|
368
368
|
* engine does this only for an account whose email is confirmed (403
|
|
369
369
|
* otherwise), and the cart stays the shopper's either way — so a refusal
|
|
370
|
-
* is not an error, and neither is a build without ext/identity.
|
|
370
|
+
* is not an error, and neither is a build without ext/identity. A refused
|
|
371
|
+
* claim still gives the cart the account's email, which the claim would
|
|
372
|
+
* have set, or the checkout asks the shopper for it again.
|
|
371
373
|
*/
|
|
372
374
|
async claimCartForAccount(cartId) {
|
|
373
375
|
try {
|
|
374
376
|
await this.engine("/x/identity/me/carts", { method: "POST", body: { cart_id: cartId }, auth: true });
|
|
375
377
|
} catch {
|
|
378
|
+
const email = currentMe()?.email;
|
|
379
|
+
if (email)
|
|
380
|
+
await this.engine(`/api/carts/${encodeURIComponent(cartId)}/email`, { method: "PUT", body: { email } }).catch(
|
|
381
|
+
() => void 0
|
|
382
|
+
);
|
|
376
383
|
}
|
|
377
384
|
}
|
|
378
385
|
// ------------------------------------------------------------ Litekart verbs
|
|
@@ -1567,7 +1574,23 @@ function attributesFrom(p) {
|
|
|
1567
1574
|
return Object.keys(out).length ? out : void 0;
|
|
1568
1575
|
}
|
|
1569
1576
|
var counts = (values) => Object.fromEntries((values ?? []).map((v) => [v.value, v.count]));
|
|
1570
|
-
function
|
|
1577
|
+
function categoryFacets(counted, tree) {
|
|
1578
|
+
const byId = new Map(tree.map((c) => [c.id, c]));
|
|
1579
|
+
const totals = /* @__PURE__ */ new Map();
|
|
1580
|
+
for (const { id: id2, count } of counted) {
|
|
1581
|
+
for (let c = byId.get(id2); c; c = c.parent_id === null ? void 0 : byId.get(c.parent_id)) {
|
|
1582
|
+
totals.set(c.id, (totals.get(c.id) ?? 0) + count);
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
const kept = tree.filter((c) => totals.has(c.id)).sort((a, b) => a.position - b.position || a.id - b.id);
|
|
1586
|
+
const parentOf = (c) => c.parent_id !== null && byId.has(c.parent_id) ? c.parent_id : null;
|
|
1587
|
+
const under = (parent) => kept.filter((c) => parentOf(c) === parent).flatMap((c) => [{ name: c.title, slug: c.slug, count: totals.get(c.id), depth: c.depth }, ...under(c.id)]);
|
|
1588
|
+
return [
|
|
1589
|
+
...under(null),
|
|
1590
|
+
...counted.filter((c) => !byId.has(c.id)).map((c) => ({ name: c.title, slug: c.slug, count: c.count, depth: 0 }))
|
|
1591
|
+
];
|
|
1592
|
+
}
|
|
1593
|
+
function toStorefrontFacets(f, tree = []) {
|
|
1571
1594
|
if (!f) return { priceStat: {}, categories: [], tags: [], allFilters: {} };
|
|
1572
1595
|
const allFilters = {};
|
|
1573
1596
|
const group = (key, values) => {
|
|
@@ -1578,7 +1601,7 @@ function toStorefrontFacets(f) {
|
|
|
1578
1601
|
for (const [handle, values] of Object.entries(f.attributes ?? {})) group(`attributes.${handle}`, values);
|
|
1579
1602
|
return {
|
|
1580
1603
|
priceStat: f.price ? { min: toMajor(f.price.min), max: toMajor(f.price.max) } : {},
|
|
1581
|
-
categories: (f.categories ?? []
|
|
1604
|
+
categories: categoryFacets(f.categories ?? [], tree),
|
|
1582
1605
|
tags: (f.tags ?? []).map((t) => ({ name: t.value, count: t.count })),
|
|
1583
1606
|
allFilters
|
|
1584
1607
|
};
|
|
@@ -1611,13 +1634,14 @@ var SearchService = class extends CatalogService {
|
|
|
1611
1634
|
productTypes: listParam(p, "product_type"),
|
|
1612
1635
|
facets: true
|
|
1613
1636
|
});
|
|
1637
|
+
const tree = res.facets?.categories?.length ? await this.facts.categories().catch(() => []) : [];
|
|
1614
1638
|
return {
|
|
1615
1639
|
data: res.data,
|
|
1616
1640
|
count: res.count,
|
|
1617
1641
|
totalPages: res.noOfPage,
|
|
1618
1642
|
page: res.page,
|
|
1619
1643
|
categoryHierarchy: res.categoryHierarchy,
|
|
1620
|
-
facets: toStorefrontFacets(res.facets)
|
|
1644
|
+
facets: toStorefrontFacets(res.facets, tree)
|
|
1621
1645
|
};
|
|
1622
1646
|
} catch (err) {
|
|
1623
1647
|
if (err?.status === 404) return this.emptyResult();
|