@faststore/api 1.10.4 → 1.10.6
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/CHANGELOG.md +11 -0
- package/dist/api.cjs.development.js +64 -1
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +64 -1
- package/dist/api.esm.js.map +1 -1
- package/dist/platforms/vtex/clients/commerce/index.d.ts +11 -0
- package/dist/platforms/vtex/clients/commerce/types/Product.d.ts +174 -0
- package/dist/platforms/vtex/clients/index.d.ts +7 -0
- package/dist/platforms/vtex/resolvers/query.d.ts +3 -3
- package/dist/platforms/vtex/utils/facets.d.ts +14 -0
- package/package.json +3 -3
- package/src/platforms/vtex/clients/commerce/index.ts +24 -2
- package/src/platforms/vtex/clients/commerce/types/Product.ts +199 -0
- package/src/platforms/vtex/resolvers/query.ts +39 -14
- package/src/platforms/vtex/utils/facets.ts +41 -0
package/dist/api.esm.js
CHANGED
|
@@ -40,6 +40,19 @@ const VtexCommerce = ({
|
|
|
40
40
|
},
|
|
41
41
|
portal: {
|
|
42
42
|
pagetype: slug => fetchAPI(`${base}/api/catalog_system/pub/portal/pagetype/${slug}`)
|
|
43
|
+
},
|
|
44
|
+
products: {
|
|
45
|
+
crossselling: ({
|
|
46
|
+
type,
|
|
47
|
+
productId,
|
|
48
|
+
groupByProduct = true
|
|
49
|
+
}) => {
|
|
50
|
+
const params = new URLSearchParams({
|
|
51
|
+
sc: ctx.storage.channel.salesChannel,
|
|
52
|
+
groupByProduct: groupByProduct.toString()
|
|
53
|
+
});
|
|
54
|
+
return fetchAPI(`${base}/api/catalog_system/pub/products/crossselling/${type}/${productId}?${params}`);
|
|
55
|
+
}
|
|
43
56
|
}
|
|
44
57
|
},
|
|
45
58
|
checkout: {
|
|
@@ -637,6 +650,14 @@ class ChannelMarshal {
|
|
|
637
650
|
|
|
638
651
|
}
|
|
639
652
|
|
|
653
|
+
const FACET_CROSS_SELLING_MAP = {
|
|
654
|
+
buy: "whoboughtalsobought",
|
|
655
|
+
view: "whosawalsosaw",
|
|
656
|
+
similars: "similars",
|
|
657
|
+
viewAndBought: "whosawalsobought",
|
|
658
|
+
accessories: "accessories",
|
|
659
|
+
suggestions: "suggestions"
|
|
660
|
+
};
|
|
640
661
|
/**
|
|
641
662
|
* Transform facets from the store to VTEX platform facets.
|
|
642
663
|
* For instance, the channel in Store becomes trade-policy and regionId in VTEX's realm
|
|
@@ -678,6 +699,16 @@ const transformSelectedFacet = ({
|
|
|
678
699
|
};
|
|
679
700
|
}
|
|
680
701
|
|
|
702
|
+
case "buy":
|
|
703
|
+
case "view":
|
|
704
|
+
case "similars":
|
|
705
|
+
case "viewAndBought":
|
|
706
|
+
case "accessories":
|
|
707
|
+
case "suggestions":
|
|
708
|
+
{
|
|
709
|
+
return []; // remove this facet from search
|
|
710
|
+
}
|
|
711
|
+
|
|
681
712
|
default:
|
|
682
713
|
return {
|
|
683
714
|
key,
|
|
@@ -694,6 +725,18 @@ const parseRange = range => {
|
|
|
694
725
|
|
|
695
726
|
return splitted;
|
|
696
727
|
};
|
|
728
|
+
const isCrossSelling = x => typeof FACET_CROSS_SELLING_MAP[x] === "string";
|
|
729
|
+
const findCrossSelling = facets => {
|
|
730
|
+
var _filtered$;
|
|
731
|
+
|
|
732
|
+
const filtered = facets == null ? void 0 : facets.filter(x => isCrossSelling(x.key));
|
|
733
|
+
|
|
734
|
+
if (Array.isArray(filtered) && filtered.length > 1) {
|
|
735
|
+
throw new BadRequestError(`You passed ${filtered.length} cross selling facets but only one is allowed. Please leave one of the following facet: ${filtered.map(x => x.key).join(',')}`);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
return (_filtered$ = filtered == null ? void 0 : filtered[0]) != null ? _filtered$ : null;
|
|
739
|
+
};
|
|
697
740
|
const findSlug = facets => {
|
|
698
741
|
var _facets$find$value, _facets$find;
|
|
699
742
|
|
|
@@ -1561,6 +1604,7 @@ const Query = {
|
|
|
1561
1604
|
// Insert channel in context for later usage
|
|
1562
1605
|
const channel = findChannel(selectedFacets);
|
|
1563
1606
|
const locale = findLocale(selectedFacets);
|
|
1607
|
+
const crossSelling = findCrossSelling(selectedFacets);
|
|
1564
1608
|
|
|
1565
1609
|
if (channel) {
|
|
1566
1610
|
mutateChannelContext(ctx, channel);
|
|
@@ -1570,11 +1614,30 @@ const Query = {
|
|
|
1570
1614
|
mutateLocaleContext(ctx, locale);
|
|
1571
1615
|
}
|
|
1572
1616
|
|
|
1617
|
+
let query = term;
|
|
1618
|
+
/**
|
|
1619
|
+
* In case we are using crossSelling, we need to modify the search
|
|
1620
|
+
* we will be performing on our search engine. The idea in here
|
|
1621
|
+
* is to use the cross selling API for fetching the productIds our
|
|
1622
|
+
* search will return for us.
|
|
1623
|
+
* Doing this two request workflow makes it possible to have cross
|
|
1624
|
+
* selling with Search features, like pagination, internationalization
|
|
1625
|
+
* etc
|
|
1626
|
+
*/
|
|
1627
|
+
|
|
1628
|
+
if (crossSelling) {
|
|
1629
|
+
const products = await ctx.clients.commerce.catalog.products.crossselling({
|
|
1630
|
+
type: FACET_CROSS_SELLING_MAP[crossSelling.key],
|
|
1631
|
+
productId: crossSelling.value
|
|
1632
|
+
});
|
|
1633
|
+
query = `product:${products.map(x => x.productId).slice(0, first).join(";")}`;
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1573
1636
|
const after = maybeAfter ? Number(maybeAfter) : 0;
|
|
1574
1637
|
const searchArgs = {
|
|
1575
1638
|
page: Math.ceil(after / first),
|
|
1576
1639
|
count: first,
|
|
1577
|
-
query
|
|
1640
|
+
query,
|
|
1578
1641
|
sort: SORT_MAP[sort != null ? sort : 'score_desc'],
|
|
1579
1642
|
selectedFacets: (_selectedFacets$flatM = selectedFacets == null ? void 0 : selectedFacets.flatMap(transformSelectedFacet)) != null ? _selectedFacets$flatM : []
|
|
1580
1643
|
};
|