@plasmicpkgs/commerce-swell 0.0.6 → 0.0.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/cart/use-cart.d.ts +1 -9
- package/dist/commerce-swell.cjs.development.js +210 -38
- package/dist/commerce-swell.cjs.development.js.map +1 -1
- package/dist/commerce-swell.cjs.production.min.js +1 -1
- package/dist/commerce-swell.cjs.production.min.js.map +1 -1
- package/dist/commerce-swell.esm.js +210 -38
- package/dist/commerce-swell.esm.js.map +1 -1
- package/dist/product/use-product.d.ts +7 -0
- package/dist/product/use-search.d.ts +4 -14
- package/dist/provider.d.ts +6 -0
- package/dist/site/use-brands.d.ts +1 -7
- package/dist/site/use-categories.d.ts +1 -7
- package/dist/types/site.d.ts +3 -0
- package/dist/utils/category-tree.d.ts +2 -0
- package/dist/utils/common.d.ts +1 -0
- package/package.json +4 -4
package/dist/cart/use-cart.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { SWRHook } from '@plasmicpkgs/commerce';
|
|
2
2
|
import type { CartType } from '@plasmicpkgs/commerce';
|
|
3
|
-
declare const _default
|
|
4
|
-
swrOptions?: Partial<import("swr/dist/types").PublicConfiguration<CartType.Cart | null | undefined, import("@plasmicpkgs/commerce").CommerceError, import("@plasmicpkgs/commerce").HookFetcher<CartType.Cart | null | undefined, {
|
|
5
|
-
cartId?: string | undefined;
|
|
6
|
-
}, any>>> | undefined;
|
|
7
|
-
} | undefined) => import("swr").SWRResponse<CartType.Cart | null | undefined, import("@plasmicpkgs/commerce").CommerceError> & {
|
|
8
|
-
isLoading: boolean;
|
|
9
|
-
} & {
|
|
10
|
-
isEmpty: boolean;
|
|
11
|
-
};
|
|
3
|
+
declare const _default;
|
|
12
4
|
export default _default;
|
|
13
5
|
declare type GetCartHook = CartType.GetCartHook;
|
|
14
6
|
export declare const handler: SWRHook<GetCartHook>;
|
|
@@ -1531,50 +1531,213 @@ var handler$3 = {
|
|
|
1531
1531
|
}
|
|
1532
1532
|
};
|
|
1533
1533
|
|
|
1534
|
+
function ensure(x, msg) {
|
|
1535
|
+
if (msg === void 0) {
|
|
1536
|
+
msg = "";
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
if (x === null || x === undefined) {
|
|
1540
|
+
debugger;
|
|
1541
|
+
throw new Error("Value must not be undefined or null" + (msg ? "- " + msg : ""));
|
|
1542
|
+
} else {
|
|
1543
|
+
return x;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
var walkCategoryTree = function walkCategoryTree(category, categories) {
|
|
1548
|
+
if (!category || !categories) {
|
|
1549
|
+
return [];
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
var queue = [category];
|
|
1553
|
+
var result = [];
|
|
1554
|
+
|
|
1555
|
+
while (queue.length > 0) {
|
|
1556
|
+
var _curr$children$map, _curr$children;
|
|
1557
|
+
|
|
1558
|
+
var curr = ensure(queue.shift());
|
|
1559
|
+
result.push(curr);
|
|
1560
|
+
queue.push.apply(queue, (_curr$children$map = (_curr$children = curr.children) == null ? void 0 : _curr$children.map(function (child) {
|
|
1561
|
+
return ensure(categories.find(function (category) {
|
|
1562
|
+
return category.id === child.id;
|
|
1563
|
+
}));
|
|
1564
|
+
})) != null ? _curr$children$map : []);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
return result;
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1534
1570
|
var handler$4 = {
|
|
1535
1571
|
fetchOptions: {
|
|
1536
1572
|
query: 'products',
|
|
1537
1573
|
method: 'list'
|
|
1538
1574
|
},
|
|
1539
1575
|
fetcher: function fetcher(_ref) {
|
|
1540
|
-
return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
1541
|
-
var input, fetch, sortMap, categoryId, brandId, search, _input$sort, sort, count, mappedSort,
|
|
1576
|
+
return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
1577
|
+
var input, options, fetch, sortMap, categoryId, includeSubCategories, categories, brandId, search, _input$sort, sort, count, mappedSort, products, _fetch, includedCategories;
|
|
1542
1578
|
|
|
1543
|
-
return runtime_1.wrap(function
|
|
1579
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1544
1580
|
while (1) {
|
|
1545
|
-
switch (
|
|
1581
|
+
switch (_context3.prev = _context3.next) {
|
|
1546
1582
|
case 0:
|
|
1547
|
-
input = _ref.input, fetch = _ref.fetch;
|
|
1583
|
+
input = _ref.input, options = _ref.options, fetch = _ref.fetch;
|
|
1548
1584
|
sortMap = new Map([['latest-desc', ''], ['price-asc', 'price_asc'], ['price-desc', 'price_desc'], ['trending-desc', 'popularity']]);
|
|
1549
|
-
categoryId = input.categoryId, brandId = input.brandId, search = input.search, _input$sort = input.sort, sort = _input$sort === void 0 ? 'latest-desc' : _input$sort, count = input.count;
|
|
1585
|
+
categoryId = input.categoryId, includeSubCategories = input.includeSubCategories, categories = input.categories, brandId = input.brandId, search = input.search, _input$sort = input.sort, sort = _input$sort === void 0 ? 'latest-desc' : _input$sort, count = input.count;
|
|
1550
1586
|
mappedSort = sortMap.get(sort);
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1587
|
+
products = [];
|
|
1588
|
+
|
|
1589
|
+
_fetch = /*#__PURE__*/function () {
|
|
1590
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(categoryId) {
|
|
1591
|
+
var _yield$fetch, results;
|
|
1592
|
+
|
|
1593
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1594
|
+
while (1) {
|
|
1595
|
+
switch (_context.prev = _context.next) {
|
|
1596
|
+
case 0:
|
|
1597
|
+
_context.next = 2;
|
|
1598
|
+
return fetch({
|
|
1599
|
+
query: options.query,
|
|
1600
|
+
method: options.method,
|
|
1601
|
+
variables: {
|
|
1602
|
+
category: categoryId,
|
|
1603
|
+
brand: brandId,
|
|
1604
|
+
search: search,
|
|
1605
|
+
sort: mappedSort,
|
|
1606
|
+
expand: ["variants"],
|
|
1607
|
+
limit: count
|
|
1608
|
+
}
|
|
1609
|
+
});
|
|
1610
|
+
|
|
1611
|
+
case 2:
|
|
1612
|
+
_yield$fetch = _context.sent;
|
|
1613
|
+
results = _yield$fetch.results;
|
|
1614
|
+
return _context.abrupt("return", results);
|
|
1615
|
+
|
|
1616
|
+
case 5:
|
|
1617
|
+
case "end":
|
|
1618
|
+
return _context.stop();
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
}, _callee);
|
|
1622
|
+
}));
|
|
1564
1623
|
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1624
|
+
return function _fetch(_x) {
|
|
1625
|
+
return _ref2.apply(this, arguments);
|
|
1626
|
+
};
|
|
1627
|
+
}();
|
|
1628
|
+
|
|
1629
|
+
if (includeSubCategories) {
|
|
1630
|
+
_context3.next = 12;
|
|
1631
|
+
break;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
_context3.next = 9;
|
|
1635
|
+
return _fetch(categoryId);
|
|
1636
|
+
|
|
1637
|
+
case 9:
|
|
1638
|
+
products = _context3.sent;
|
|
1639
|
+
_context3.next = 16;
|
|
1640
|
+
break;
|
|
1641
|
+
|
|
1642
|
+
case 12:
|
|
1643
|
+
includedCategories = walkCategoryTree(categories == null ? void 0 : categories.find(function (category) {
|
|
1644
|
+
return category.id === categoryId;
|
|
1645
|
+
}), categories);
|
|
1646
|
+
_context3.next = 15;
|
|
1647
|
+
return Promise.all(includedCategories.flatMap( /*#__PURE__*/function () {
|
|
1648
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(category) {
|
|
1649
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1650
|
+
while (1) {
|
|
1651
|
+
switch (_context2.prev = _context2.next) {
|
|
1652
|
+
case 0:
|
|
1653
|
+
return _context2.abrupt("return", _fetch(category.id));
|
|
1654
|
+
|
|
1655
|
+
case 1:
|
|
1656
|
+
case "end":
|
|
1657
|
+
return _context2.stop();
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
}, _callee2);
|
|
1661
|
+
}));
|
|
1662
|
+
|
|
1663
|
+
return function (_x2) {
|
|
1664
|
+
return _ref3.apply(this, arguments);
|
|
1665
|
+
};
|
|
1666
|
+
}()));
|
|
1667
|
+
|
|
1668
|
+
case 15:
|
|
1669
|
+
products = _context3.sent.flatMap(function (products) {
|
|
1670
|
+
return products;
|
|
1671
|
+
}).slice(0, count);
|
|
1672
|
+
|
|
1673
|
+
case 16:
|
|
1674
|
+
return _context3.abrupt("return", {
|
|
1675
|
+
products: products.map(function (product) {
|
|
1676
|
+
return normalizeProduct(product);
|
|
1677
|
+
}),
|
|
1678
|
+
found: products.length > 0
|
|
1571
1679
|
});
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1680
|
+
|
|
1681
|
+
case 17:
|
|
1682
|
+
case "end":
|
|
1683
|
+
return _context3.stop();
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
}, _callee3);
|
|
1687
|
+
}))();
|
|
1688
|
+
},
|
|
1689
|
+
useHook: function useHook(_ref4) {
|
|
1690
|
+
var useData = _ref4.useData;
|
|
1691
|
+
return function (input) {
|
|
1692
|
+
if (input === void 0) {
|
|
1693
|
+
input = {};
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
return useData({
|
|
1697
|
+
input: [['search', input.search], ['categoryId', input.categoryId], ['includeSubCategories', input.includeSubCategories], ['categories', input.categories], ['brandId', input.brandId], ['sort', input.sort], ['count', input.count]],
|
|
1698
|
+
swrOptions: _extends({
|
|
1699
|
+
revalidateOnFocus: false
|
|
1700
|
+
}, input.swrOptions)
|
|
1701
|
+
});
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
var handler$5 = {
|
|
1707
|
+
fetchOptions: {
|
|
1708
|
+
query: 'products',
|
|
1709
|
+
method: 'get'
|
|
1710
|
+
},
|
|
1711
|
+
fetcher: function fetcher(_ref) {
|
|
1712
|
+
return _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
1713
|
+
var input, options, fetch, id, product;
|
|
1714
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
1715
|
+
while (1) {
|
|
1716
|
+
switch (_context.prev = _context.next) {
|
|
1717
|
+
case 0:
|
|
1718
|
+
input = _ref.input, options = _ref.options, fetch = _ref.fetch;
|
|
1719
|
+
id = input.id;
|
|
1720
|
+
_context.next = 4;
|
|
1721
|
+
return fetch({
|
|
1722
|
+
query: options.query,
|
|
1723
|
+
method: options.method,
|
|
1724
|
+
variables: [id]
|
|
1575
1725
|
});
|
|
1576
1726
|
|
|
1577
|
-
case
|
|
1727
|
+
case 4:
|
|
1728
|
+
product = _context.sent;
|
|
1729
|
+
|
|
1730
|
+
if (product) {
|
|
1731
|
+
_context.next = 7;
|
|
1732
|
+
break;
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
return _context.abrupt("return", null);
|
|
1736
|
+
|
|
1737
|
+
case 7:
|
|
1738
|
+
return _context.abrupt("return", normalizeProduct(product));
|
|
1739
|
+
|
|
1740
|
+
case 8:
|
|
1578
1741
|
case "end":
|
|
1579
1742
|
return _context.stop();
|
|
1580
1743
|
}
|
|
@@ -1590,7 +1753,7 @@ var handler$4 = {
|
|
|
1590
1753
|
}
|
|
1591
1754
|
|
|
1592
1755
|
return useData({
|
|
1593
|
-
input: [['
|
|
1756
|
+
input: [['id', input.id]],
|
|
1594
1757
|
swrOptions: _extends({
|
|
1595
1758
|
revalidateOnFocus: false
|
|
1596
1759
|
}, input.swrOptions)
|
|
@@ -1599,7 +1762,7 @@ var handler$4 = {
|
|
|
1599
1762
|
}
|
|
1600
1763
|
};
|
|
1601
1764
|
|
|
1602
|
-
var handler$
|
|
1765
|
+
var handler$6 = {
|
|
1603
1766
|
fetchOptions: {
|
|
1604
1767
|
query: 'categories',
|
|
1605
1768
|
method: 'get'
|
|
@@ -1617,7 +1780,10 @@ var handler$5 = {
|
|
|
1617
1780
|
_context.next = 3;
|
|
1618
1781
|
return fetch({
|
|
1619
1782
|
query: 'categories',
|
|
1620
|
-
method: 'get'
|
|
1783
|
+
method: 'get',
|
|
1784
|
+
variables: {
|
|
1785
|
+
expand: ["children"]
|
|
1786
|
+
}
|
|
1621
1787
|
});
|
|
1622
1788
|
|
|
1623
1789
|
case 3:
|
|
@@ -1625,12 +1791,14 @@ var handler$5 = {
|
|
|
1625
1791
|
return _context.abrupt("return", (_data$results$map = data.results.map(function (_ref2) {
|
|
1626
1792
|
var id = _ref2.id,
|
|
1627
1793
|
name = _ref2.name,
|
|
1628
|
-
slug = _ref2.slug
|
|
1794
|
+
slug = _ref2.slug,
|
|
1795
|
+
children = _ref2.children;
|
|
1629
1796
|
return {
|
|
1630
1797
|
id: id,
|
|
1631
1798
|
name: name,
|
|
1632
1799
|
slug: slug,
|
|
1633
|
-
path: "/" + slug
|
|
1800
|
+
path: "/" + slug,
|
|
1801
|
+
children: children.results
|
|
1634
1802
|
};
|
|
1635
1803
|
})) != null ? _data$results$map : []);
|
|
1636
1804
|
|
|
@@ -1666,7 +1834,7 @@ var handler$5 = {
|
|
|
1666
1834
|
}
|
|
1667
1835
|
};
|
|
1668
1836
|
|
|
1669
|
-
var handler$
|
|
1837
|
+
var handler$7 = {
|
|
1670
1838
|
fetchOptions: {
|
|
1671
1839
|
query: 'attributes',
|
|
1672
1840
|
method: 'get'
|
|
@@ -1862,11 +2030,15 @@ var getSwellProvider = function getSwellProvider(storeId, publicKey) {
|
|
|
1862
2030
|
useRemoveItem: handler$2
|
|
1863
2031
|
},
|
|
1864
2032
|
products: {
|
|
1865
|
-
useSearch: handler$4
|
|
2033
|
+
useSearch: handler$4,
|
|
2034
|
+
useProduct: handler$5
|
|
1866
2035
|
},
|
|
1867
2036
|
site: {
|
|
1868
|
-
useCategories: handler$
|
|
1869
|
-
useBrands: handler$
|
|
2037
|
+
useCategories: handler$6,
|
|
2038
|
+
useBrands: handler$7
|
|
2039
|
+
},
|
|
2040
|
+
extraFeatures: {
|
|
2041
|
+
includeSubCategories: true
|
|
1870
2042
|
}
|
|
1871
2043
|
};
|
|
1872
2044
|
};
|