@anker-in/shopify-sdk 1.2.0-beta.9 → 1.2.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/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs.map +1 -1
- package/dist/fragments/index.d.mts +17 -5
- package/dist/fragments/index.d.ts +17 -5
- package/dist/fragments/index.js +116 -6
- package/dist/fragments/index.js.map +1 -1
- package/dist/fragments/index.mjs +113 -7
- package/dist/fragments/index.mjs.map +1 -1
- package/dist/index.d.mts +151 -53
- package/dist/index.d.ts +151 -53
- package/dist/index.js +447 -141
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +440 -142
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -5,23 +5,21 @@ export * from '@anker-in/shopify-core';
|
|
|
5
5
|
var SPECIAL_METAFIELD_NAMESPACES = ["__discountCodeApp", "discounts_function"];
|
|
6
6
|
function constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, metafieldNamespacePrefix) {
|
|
7
7
|
if (!metafieldIdentifiers || Object.keys(metafieldIdentifiers).length === 0) {
|
|
8
|
-
return {
|
|
9
|
-
productMetafieldIdentifiers: [],
|
|
10
|
-
variantMetafieldIdentifiers: []
|
|
11
|
-
};
|
|
8
|
+
return {};
|
|
12
9
|
}
|
|
13
10
|
const identifiers = Object.entries(metafieldIdentifiers).reduce(
|
|
14
11
|
(queryInput, [key, value]) => {
|
|
15
12
|
const metafieldIdentifiers2 = value;
|
|
13
|
+
const comboNamespace = `${metafieldNamespacePrefix}combo`;
|
|
16
14
|
const mappedIdentifiers = metafieldIdentifiers2.map((item) => {
|
|
17
|
-
if (SPECIAL_METAFIELD_NAMESPACES.includes(item.namespace)) {
|
|
15
|
+
if (SPECIAL_METAFIELD_NAMESPACES.includes(item.namespace) || item.namespace?.startsWith(comboNamespace)) {
|
|
18
16
|
return {
|
|
19
17
|
namespace: item.namespace,
|
|
20
18
|
key: item.key
|
|
21
19
|
};
|
|
22
20
|
}
|
|
23
21
|
return {
|
|
24
|
-
namespace:
|
|
22
|
+
namespace: comboNamespace,
|
|
25
23
|
key: item.namespace
|
|
26
24
|
};
|
|
27
25
|
});
|
|
@@ -31,10 +29,7 @@ function constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, metafiel
|
|
|
31
29
|
queryInput[`${key}MetafieldIdentifiers`] = uniqueIdentifiers;
|
|
32
30
|
return queryInput;
|
|
33
31
|
},
|
|
34
|
-
{
|
|
35
|
-
productMetafieldIdentifiers: [],
|
|
36
|
-
variantMetafieldIdentifiers: []
|
|
37
|
-
}
|
|
32
|
+
{}
|
|
38
33
|
);
|
|
39
34
|
return identifiers;
|
|
40
35
|
}
|
|
@@ -698,8 +693,6 @@ var articleFragment = (
|
|
|
698
693
|
name
|
|
699
694
|
}
|
|
700
695
|
}
|
|
701
|
-
${imageFragment}
|
|
702
|
-
${seoFragment}
|
|
703
696
|
`
|
|
704
697
|
);
|
|
705
698
|
var articleWithMetafieldsFragment = (
|
|
@@ -728,9 +721,6 @@ var articleWithMetafieldsFragment = (
|
|
|
728
721
|
...metafield
|
|
729
722
|
}
|
|
730
723
|
}
|
|
731
|
-
${imageFragment}
|
|
732
|
-
${seoFragment}
|
|
733
|
-
${metafieldFragment}
|
|
734
724
|
`
|
|
735
725
|
);
|
|
736
726
|
var blogFragment = (
|
|
@@ -744,7 +734,6 @@ var blogFragment = (
|
|
|
744
734
|
...seo
|
|
745
735
|
}
|
|
746
736
|
}
|
|
747
|
-
${seoFragment}
|
|
748
737
|
`
|
|
749
738
|
);
|
|
750
739
|
var blogWithMetafieldsFragment = (
|
|
@@ -761,7 +750,119 @@ var blogWithMetafieldsFragment = (
|
|
|
761
750
|
...metafield
|
|
762
751
|
}
|
|
763
752
|
}
|
|
753
|
+
`
|
|
754
|
+
);
|
|
755
|
+
|
|
756
|
+
// src/fragments/page.ts
|
|
757
|
+
var pageFragment = (
|
|
758
|
+
/* GraphQL */
|
|
759
|
+
`
|
|
760
|
+
fragment page on Page {
|
|
761
|
+
id
|
|
762
|
+
handle
|
|
763
|
+
title
|
|
764
|
+
body
|
|
765
|
+
bodySummary
|
|
766
|
+
createdAt
|
|
767
|
+
updatedAt
|
|
768
|
+
seo {
|
|
769
|
+
...seo
|
|
770
|
+
}
|
|
771
|
+
}
|
|
764
772
|
${seoFragment}
|
|
773
|
+
`
|
|
774
|
+
);
|
|
775
|
+
var pageWithMetafieldsFragment = (
|
|
776
|
+
/* GraphQL */
|
|
777
|
+
`
|
|
778
|
+
fragment pageWithMetafields on Page {
|
|
779
|
+
id
|
|
780
|
+
handle
|
|
781
|
+
title
|
|
782
|
+
body
|
|
783
|
+
bodySummary
|
|
784
|
+
createdAt
|
|
785
|
+
updatedAt
|
|
786
|
+
seo {
|
|
787
|
+
...seo
|
|
788
|
+
}
|
|
789
|
+
metafields(identifiers: $pageMetafieldIdentifiers) {
|
|
790
|
+
...metafield
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
${seoFragment}
|
|
794
|
+
${metafieldFragment}
|
|
795
|
+
`
|
|
796
|
+
);
|
|
797
|
+
|
|
798
|
+
// src/fragments/shop.ts
|
|
799
|
+
var shopFragment = (
|
|
800
|
+
/* GraphQL */
|
|
801
|
+
`
|
|
802
|
+
fragment shop on Shop {
|
|
803
|
+
name
|
|
804
|
+
description
|
|
805
|
+
moneyFormat
|
|
806
|
+
primaryDomain {
|
|
807
|
+
host
|
|
808
|
+
url
|
|
809
|
+
}
|
|
810
|
+
paymentSettings {
|
|
811
|
+
currencyCode
|
|
812
|
+
enabledPresentmentCurrencies
|
|
813
|
+
}
|
|
814
|
+
brand {
|
|
815
|
+
logo {
|
|
816
|
+
image {
|
|
817
|
+
url
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
colors {
|
|
821
|
+
primary {
|
|
822
|
+
background
|
|
823
|
+
}
|
|
824
|
+
secondary {
|
|
825
|
+
background
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
`
|
|
831
|
+
);
|
|
832
|
+
var shopWithMetafieldsFragment = (
|
|
833
|
+
/* GraphQL */
|
|
834
|
+
`
|
|
835
|
+
fragment shopWithMetafields on Shop {
|
|
836
|
+
name
|
|
837
|
+
description
|
|
838
|
+
moneyFormat
|
|
839
|
+
primaryDomain {
|
|
840
|
+
host
|
|
841
|
+
url
|
|
842
|
+
}
|
|
843
|
+
paymentSettings {
|
|
844
|
+
currencyCode
|
|
845
|
+
enabledPresentmentCurrencies
|
|
846
|
+
}
|
|
847
|
+
brand {
|
|
848
|
+
logo {
|
|
849
|
+
image {
|
|
850
|
+
url
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
colors {
|
|
854
|
+
primary {
|
|
855
|
+
background
|
|
856
|
+
}
|
|
857
|
+
secondary {
|
|
858
|
+
background
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
metafields(identifiers: $shopMetafieldIdentifiers) {
|
|
863
|
+
...metafield
|
|
864
|
+
}
|
|
865
|
+
}
|
|
765
866
|
${metafieldFragment}
|
|
766
867
|
`
|
|
767
868
|
);
|
|
@@ -1302,13 +1403,16 @@ var getProductQuery2 = (
|
|
|
1302
1403
|
`
|
|
1303
1404
|
);
|
|
1304
1405
|
async function getProduct(client, options) {
|
|
1305
|
-
const { handle, metafieldIdentifiers } = options;
|
|
1406
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
1407
|
+
const query = graphqlQuery || getProductQuery2;
|
|
1306
1408
|
const variables = { handle };
|
|
1307
|
-
|
|
1308
|
-
variables
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1409
|
+
const data = await client.query(query, {
|
|
1410
|
+
...variables,
|
|
1411
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
1412
|
+
metafieldIdentifiers,
|
|
1413
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
1414
|
+
)
|
|
1415
|
+
});
|
|
1312
1416
|
if (!data?.product) {
|
|
1313
1417
|
return void 0;
|
|
1314
1418
|
}
|
|
@@ -1362,8 +1466,9 @@ var getAllProductsQuery = (
|
|
|
1362
1466
|
${imageFragment}
|
|
1363
1467
|
`
|
|
1364
1468
|
);
|
|
1365
|
-
async function
|
|
1366
|
-
const { first = 250, query, sortKey, reverse, metafieldIdentifiers } = options;
|
|
1469
|
+
async function fetchAllProducts(client, options, afterCursor) {
|
|
1470
|
+
const { first = 250, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
|
|
1471
|
+
const queryString = graphqlQuery || getAllProductsQuery;
|
|
1367
1472
|
const variables = {
|
|
1368
1473
|
first,
|
|
1369
1474
|
after: afterCursor,
|
|
@@ -1371,26 +1476,37 @@ async function fetchAllPages(client, options, afterCursor) {
|
|
|
1371
1476
|
sortKey,
|
|
1372
1477
|
reverse
|
|
1373
1478
|
};
|
|
1374
|
-
|
|
1375
|
-
variables
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1479
|
+
const data = await client.query(queryString, {
|
|
1480
|
+
...variables,
|
|
1481
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
1482
|
+
metafieldIdentifiers,
|
|
1483
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
1484
|
+
)
|
|
1485
|
+
});
|
|
1379
1486
|
if (!data || !data.products) {
|
|
1380
1487
|
return [];
|
|
1381
1488
|
}
|
|
1382
1489
|
const products = data.products.edges.map((edge) => normalizeProduct(edge.node));
|
|
1383
1490
|
if (data.products.pageInfo.hasNextPage) {
|
|
1384
|
-
const nextProducts = await
|
|
1491
|
+
const nextProducts = await fetchAllProducts(client, options, data.products.pageInfo.endCursor);
|
|
1385
1492
|
return [...products, ...nextProducts];
|
|
1386
1493
|
}
|
|
1387
1494
|
return products;
|
|
1388
1495
|
}
|
|
1389
1496
|
async function getAllProducts(client, options) {
|
|
1390
|
-
return
|
|
1497
|
+
return fetchAllProducts(client, options);
|
|
1391
1498
|
}
|
|
1392
1499
|
async function getProducts(client, options) {
|
|
1393
|
-
const {
|
|
1500
|
+
const {
|
|
1501
|
+
first = 250,
|
|
1502
|
+
after,
|
|
1503
|
+
query,
|
|
1504
|
+
graphqlQuery,
|
|
1505
|
+
sortKey,
|
|
1506
|
+
reverse,
|
|
1507
|
+
metafieldIdentifiers
|
|
1508
|
+
} = options;
|
|
1509
|
+
const queryString = graphqlQuery || getAllProductsQuery;
|
|
1394
1510
|
const variables = {
|
|
1395
1511
|
first,
|
|
1396
1512
|
after,
|
|
@@ -1402,7 +1518,7 @@ async function getProducts(client, options) {
|
|
|
1402
1518
|
variables.productMetafieldIdentifiers = metafieldIdentifiers;
|
|
1403
1519
|
variables.variantMetafieldIdentifiers = metafieldIdentifiers;
|
|
1404
1520
|
}
|
|
1405
|
-
const data = await client.query(
|
|
1521
|
+
const data = await client.query(queryString, variables);
|
|
1406
1522
|
if (!data || !data.products) {
|
|
1407
1523
|
return {
|
|
1408
1524
|
products: [],
|
|
@@ -1452,11 +1568,11 @@ function buildProductsByHandlesQuery(handles) {
|
|
|
1452
1568
|
);
|
|
1453
1569
|
}
|
|
1454
1570
|
async function getProductsByHandles(client, options) {
|
|
1455
|
-
const { handles, metafieldIdentifiers } = options;
|
|
1571
|
+
const { handles, graphqlQuery, metafieldIdentifiers } = options;
|
|
1456
1572
|
if (!handles || handles.length === 0) {
|
|
1457
1573
|
return [];
|
|
1458
1574
|
}
|
|
1459
|
-
const query = buildProductsByHandlesQuery(handles);
|
|
1575
|
+
const query = graphqlQuery || buildProductsByHandlesQuery(handles);
|
|
1460
1576
|
const data = await client.query(query, {
|
|
1461
1577
|
handles,
|
|
1462
1578
|
// 请勿删除,这个参数虽然没有在 query 中使用,但方便在 chrome dev tools 中查看请求参数
|
|
@@ -1577,7 +1693,8 @@ function normalizeCart(cart) {
|
|
|
1577
1693
|
|
|
1578
1694
|
// src/api/cart/get-cart.ts
|
|
1579
1695
|
async function getCart(client, options) {
|
|
1580
|
-
const { id, cookieAdapter, metafieldIdentifiers } = options;
|
|
1696
|
+
const { id, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1697
|
+
const query = graphqlQuery || getCartQuery;
|
|
1581
1698
|
const locale = client.getLocale();
|
|
1582
1699
|
const cartId = id || cookieAdapter?.getCartId(locale);
|
|
1583
1700
|
console.log("cartId", cartId);
|
|
@@ -1585,7 +1702,7 @@ async function getCart(client, options) {
|
|
|
1585
1702
|
return void 0;
|
|
1586
1703
|
}
|
|
1587
1704
|
try {
|
|
1588
|
-
const data = await client.query(
|
|
1705
|
+
const data = await client.query(query, {
|
|
1589
1706
|
cartId,
|
|
1590
1707
|
...constructMetafieldIdentifiersQueryParams(
|
|
1591
1708
|
metafieldIdentifiers,
|
|
@@ -1620,12 +1737,14 @@ async function createCart(client, options = {}) {
|
|
|
1620
1737
|
buyerIdentity,
|
|
1621
1738
|
discountCodes,
|
|
1622
1739
|
customAttributes,
|
|
1740
|
+
graphqlQuery,
|
|
1623
1741
|
metafieldIdentifiers,
|
|
1624
1742
|
updateCookie = false
|
|
1625
1743
|
} = options;
|
|
1744
|
+
const query = graphqlQuery || createCartMutation;
|
|
1626
1745
|
const locale = client.getLocale();
|
|
1627
1746
|
try {
|
|
1628
|
-
const data = await client.query(
|
|
1747
|
+
const data = await client.query(query, {
|
|
1629
1748
|
lines,
|
|
1630
1749
|
buyerIdentity,
|
|
1631
1750
|
discountCodes,
|
|
@@ -1655,7 +1774,8 @@ async function createCart(client, options = {}) {
|
|
|
1655
1774
|
|
|
1656
1775
|
// src/api/cart/add-cart-lines.ts
|
|
1657
1776
|
async function addCartLines(client, options) {
|
|
1658
|
-
const { cartId: providedCartId, lines, cookieAdapter, metafieldIdentifiers } = options;
|
|
1777
|
+
const { cartId: providedCartId, lines, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1778
|
+
const query = graphqlQuery || addCartItemsMutation;
|
|
1659
1779
|
const locale = client.getLocale();
|
|
1660
1780
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1661
1781
|
if (!cartId) {
|
|
@@ -1666,7 +1786,7 @@ async function addCartLines(client, options) {
|
|
|
1666
1786
|
client.getConfig().getMetafieldNamespacePrefix()
|
|
1667
1787
|
);
|
|
1668
1788
|
try {
|
|
1669
|
-
const data = await client.query(
|
|
1789
|
+
const data = await client.query(query, {
|
|
1670
1790
|
cartId,
|
|
1671
1791
|
lines,
|
|
1672
1792
|
...normalizedMetafieldIdentifiers
|
|
@@ -1691,7 +1811,8 @@ async function addCartLines(client, options) {
|
|
|
1691
1811
|
|
|
1692
1812
|
// src/api/cart/update-cart-lines.ts
|
|
1693
1813
|
async function updateCartLines(client, options) {
|
|
1694
|
-
const { cartId: providedCartId, lines, cookieAdapter, metafieldIdentifiers } = options;
|
|
1814
|
+
const { cartId: providedCartId, lines, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1815
|
+
const query = graphqlQuery || updateCartItemsMutation;
|
|
1695
1816
|
const locale = client.getLocale();
|
|
1696
1817
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1697
1818
|
if (!cartId) {
|
|
@@ -1704,7 +1825,7 @@ async function updateCartLines(client, options) {
|
|
|
1704
1825
|
console.log("update-cart-lines metafieldIdentifiers:", metafieldIdentifiers);
|
|
1705
1826
|
console.log("update-cart-lines metafieldParams:", metafieldParams);
|
|
1706
1827
|
try {
|
|
1707
|
-
const data = await client.query(
|
|
1828
|
+
const data = await client.query(query, {
|
|
1708
1829
|
cartId,
|
|
1709
1830
|
lines,
|
|
1710
1831
|
...metafieldParams
|
|
@@ -1738,14 +1859,15 @@ async function updateCartLines(client, options) {
|
|
|
1738
1859
|
|
|
1739
1860
|
// src/api/cart/remove-cart-lines.ts
|
|
1740
1861
|
async function removeCartLines(client, options) {
|
|
1741
|
-
const { cartId: providedCartId, lineIds, cookieAdapter, metafieldIdentifiers } = options;
|
|
1862
|
+
const { cartId: providedCartId, lineIds, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1863
|
+
const query = graphqlQuery || removeCartItemsMutation;
|
|
1742
1864
|
const locale = client.getLocale();
|
|
1743
1865
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1744
1866
|
if (!cartId) {
|
|
1745
1867
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1746
1868
|
}
|
|
1747
1869
|
try {
|
|
1748
|
-
const data = await client.query(
|
|
1870
|
+
const data = await client.query(query, {
|
|
1749
1871
|
cartId,
|
|
1750
1872
|
lineIds,
|
|
1751
1873
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1772,14 +1894,15 @@ async function removeCartLines(client, options) {
|
|
|
1772
1894
|
|
|
1773
1895
|
// src/api/cart/update-cart-codes.ts
|
|
1774
1896
|
async function updateCartCodes(client, options) {
|
|
1775
|
-
const { cartId: providedCartId, discountCodes, cookieAdapter, metafieldIdentifiers } = options;
|
|
1897
|
+
const { cartId: providedCartId, discountCodes, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1898
|
+
const query = graphqlQuery || updateCartDiscountCodeMutation;
|
|
1776
1899
|
const locale = client.getLocale();
|
|
1777
1900
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1778
1901
|
if (!cartId) {
|
|
1779
1902
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1780
1903
|
}
|
|
1781
1904
|
try {
|
|
1782
|
-
const data = await client.query(
|
|
1905
|
+
const data = await client.query(query, {
|
|
1783
1906
|
cartId,
|
|
1784
1907
|
discountCodes,
|
|
1785
1908
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1803,14 +1926,15 @@ async function updateCartCodes(client, options) {
|
|
|
1803
1926
|
|
|
1804
1927
|
// src/api/cart/update-cart-attributes.ts
|
|
1805
1928
|
async function updateCartAttributes(client, options) {
|
|
1806
|
-
const { cartId: providedCartId, attributes, cookieAdapter, metafieldIdentifiers } = options;
|
|
1929
|
+
const { cartId: providedCartId, attributes, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1930
|
+
const query = graphqlQuery || updateCartAttributesMutation;
|
|
1807
1931
|
const locale = client.getLocale();
|
|
1808
1932
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1809
1933
|
if (!cartId) {
|
|
1810
1934
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1811
1935
|
}
|
|
1812
1936
|
try {
|
|
1813
|
-
const data = await client.query(
|
|
1937
|
+
const data = await client.query(query, {
|
|
1814
1938
|
cartId,
|
|
1815
1939
|
attributes,
|
|
1816
1940
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1837,14 +1961,15 @@ async function updateCartAttributes(client, options) {
|
|
|
1837
1961
|
|
|
1838
1962
|
// src/api/cart/update-cart-delivery-options.ts
|
|
1839
1963
|
async function updateCartDeliveryOptions(client, options) {
|
|
1840
|
-
const { cartId: providedCartId, selectedDeliveryOptions, cookieAdapter, metafieldIdentifiers } = options;
|
|
1964
|
+
const { cartId: providedCartId, selectedDeliveryOptions, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1965
|
+
const query = graphqlQuery || updateCartDeliveryOptionsMutation;
|
|
1841
1966
|
const locale = client.getLocale();
|
|
1842
1967
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1843
1968
|
if (!cartId) {
|
|
1844
1969
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1845
1970
|
}
|
|
1846
1971
|
try {
|
|
1847
|
-
const data = await client.query(
|
|
1972
|
+
const data = await client.query(query, {
|
|
1848
1973
|
cartId,
|
|
1849
1974
|
selectedDeliveryOptions,
|
|
1850
1975
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1871,14 +1996,15 @@ async function updateCartDeliveryOptions(client, options) {
|
|
|
1871
1996
|
|
|
1872
1997
|
// src/api/cart/update-buyer-identity.ts
|
|
1873
1998
|
async function updateBuyerIdentity(client, options) {
|
|
1874
|
-
const { cartId: providedCartId, buyerIdentity, cookieAdapter, metafieldIdentifiers } = options;
|
|
1999
|
+
const { cartId: providedCartId, buyerIdentity, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
2000
|
+
const query = graphqlQuery || updateBuyerIdentityMutation;
|
|
1875
2001
|
const locale = client.getLocale();
|
|
1876
2002
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1877
2003
|
if (!cartId) {
|
|
1878
2004
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1879
2005
|
}
|
|
1880
2006
|
try {
|
|
1881
|
-
const data = await client.query(
|
|
2007
|
+
const data = await client.query(query, {
|
|
1882
2008
|
cartId,
|
|
1883
2009
|
buyerIdentity,
|
|
1884
2010
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1949,12 +2075,16 @@ var getCollectionQuery = (
|
|
|
1949
2075
|
`
|
|
1950
2076
|
);
|
|
1951
2077
|
async function getCollection(client, options) {
|
|
1952
|
-
const { handle, metafieldIdentifiers } = options;
|
|
2078
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2079
|
+
const query = graphqlQuery || getCollectionQuery;
|
|
1953
2080
|
const variables = { handle };
|
|
1954
|
-
|
|
1955
|
-
variables
|
|
1956
|
-
|
|
1957
|
-
|
|
2081
|
+
const data = await client.query(query, {
|
|
2082
|
+
...variables,
|
|
2083
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2084
|
+
metafieldIdentifiers,
|
|
2085
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2086
|
+
)
|
|
2087
|
+
});
|
|
1958
2088
|
if (!data?.collection) {
|
|
1959
2089
|
return void 0;
|
|
1960
2090
|
}
|
|
@@ -1996,8 +2126,9 @@ var getAllCollectionsQuery = (
|
|
|
1996
2126
|
${imageFragment}
|
|
1997
2127
|
`
|
|
1998
2128
|
);
|
|
1999
|
-
async function
|
|
2000
|
-
const { first = 250, query, sortKey, reverse, metafieldIdentifiers } = options;
|
|
2129
|
+
async function fetchAllPages(client, options, afterCursor) {
|
|
2130
|
+
const { first = 250, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
|
|
2131
|
+
const queryString = graphqlQuery || getAllCollectionsQuery;
|
|
2001
2132
|
const variables = {
|
|
2002
2133
|
first,
|
|
2003
2134
|
after: afterCursor,
|
|
@@ -2005,25 +2136,41 @@ async function fetchAllPages2(client, options, afterCursor) {
|
|
|
2005
2136
|
sortKey,
|
|
2006
2137
|
reverse
|
|
2007
2138
|
};
|
|
2008
|
-
|
|
2009
|
-
variables
|
|
2010
|
-
|
|
2011
|
-
|
|
2139
|
+
const data = await client.query(queryString, {
|
|
2140
|
+
...variables,
|
|
2141
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2142
|
+
metafieldIdentifiers,
|
|
2143
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2144
|
+
)
|
|
2145
|
+
});
|
|
2012
2146
|
if (!data || !data.collections) {
|
|
2013
2147
|
return [];
|
|
2014
2148
|
}
|
|
2015
2149
|
const collections = data.collections.edges.map((edge) => normalizeCollection(edge.node));
|
|
2016
2150
|
if (data.collections.pageInfo.hasNextPage) {
|
|
2017
|
-
const nextCollections = await
|
|
2151
|
+
const nextCollections = await fetchAllPages(
|
|
2152
|
+
client,
|
|
2153
|
+
options,
|
|
2154
|
+
data.collections.pageInfo.endCursor
|
|
2155
|
+
);
|
|
2018
2156
|
return [...collections, ...nextCollections];
|
|
2019
2157
|
}
|
|
2020
2158
|
return collections;
|
|
2021
2159
|
}
|
|
2022
2160
|
async function getAllCollections(client, options) {
|
|
2023
|
-
return
|
|
2161
|
+
return fetchAllPages(client, options);
|
|
2024
2162
|
}
|
|
2025
2163
|
async function getCollections(client, options) {
|
|
2026
|
-
const {
|
|
2164
|
+
const {
|
|
2165
|
+
first = 250,
|
|
2166
|
+
after,
|
|
2167
|
+
query,
|
|
2168
|
+
graphqlQuery,
|
|
2169
|
+
sortKey,
|
|
2170
|
+
reverse,
|
|
2171
|
+
metafieldIdentifiers
|
|
2172
|
+
} = options;
|
|
2173
|
+
const queryString = graphqlQuery || getAllCollectionsQuery;
|
|
2027
2174
|
const variables = {
|
|
2028
2175
|
first,
|
|
2029
2176
|
after,
|
|
@@ -2031,10 +2178,13 @@ async function getCollections(client, options) {
|
|
|
2031
2178
|
sortKey,
|
|
2032
2179
|
reverse
|
|
2033
2180
|
};
|
|
2034
|
-
|
|
2035
|
-
variables
|
|
2036
|
-
|
|
2037
|
-
|
|
2181
|
+
const data = await client.query(queryString, {
|
|
2182
|
+
...variables,
|
|
2183
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2184
|
+
metafieldIdentifiers,
|
|
2185
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2186
|
+
)
|
|
2187
|
+
});
|
|
2038
2188
|
if (!data || !data.collections) {
|
|
2039
2189
|
return {
|
|
2040
2190
|
collections: [],
|
|
@@ -2052,15 +2202,12 @@ async function getCollections(client, options) {
|
|
|
2052
2202
|
}
|
|
2053
2203
|
|
|
2054
2204
|
// src/api/collection/get-collections-by-handles.ts
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
options
|
|
2058
|
-
}) => {
|
|
2059
|
-
const { handles, metafieldIdentifiers } = options;
|
|
2205
|
+
async function getCollectionsByHandles(client, options) {
|
|
2206
|
+
const { handles, graphqlQuery, metafieldIdentifiers } = options;
|
|
2060
2207
|
if (handles.length === 0) {
|
|
2061
2208
|
return [];
|
|
2062
2209
|
}
|
|
2063
|
-
const query = getCollectionsByHandlesQuery(handles);
|
|
2210
|
+
const query = graphqlQuery || getCollectionsByHandlesQuery(handles);
|
|
2064
2211
|
const data = await client.query(query, {
|
|
2065
2212
|
handles,
|
|
2066
2213
|
// 请勿删除,这个参数虽然没有在 query 中使用,但方便在 chrome dev tools 中查看请求参数
|
|
@@ -2079,7 +2226,7 @@ var getCollectionsByHandles = async ({
|
|
|
2079
2226
|
return normalizeCollection(item);
|
|
2080
2227
|
});
|
|
2081
2228
|
return collections;
|
|
2082
|
-
}
|
|
2229
|
+
}
|
|
2083
2230
|
|
|
2084
2231
|
// src/api/blog/normalize.ts
|
|
2085
2232
|
function normalizeBlog(blog) {
|
|
@@ -2125,28 +2272,34 @@ function normalizeMetafields2(metafields) {
|
|
|
2125
2272
|
|
|
2126
2273
|
// src/api/blog/get-blog.ts
|
|
2127
2274
|
async function getBlog(client, options) {
|
|
2128
|
-
const { handle, metafieldIdentifiers } = options;
|
|
2129
|
-
const hasMetafields = metafieldIdentifiers
|
|
2275
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2276
|
+
const hasMetafields = metafieldIdentifiers?.blog?.length;
|
|
2130
2277
|
const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2131
|
-
const
|
|
2278
|
+
const defaultQuery = (
|
|
2132
2279
|
/* GraphQL */
|
|
2133
2280
|
`
|
|
2134
2281
|
query getBlog(
|
|
2135
2282
|
$handle: String!
|
|
2136
2283
|
${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2137
|
-
)
|
|
2284
|
+
) {
|
|
2138
2285
|
blog(handle: $handle) {
|
|
2139
2286
|
...${hasMetafields ? "blogWithMetafields" : "blog"}
|
|
2140
2287
|
}
|
|
2141
2288
|
}
|
|
2289
|
+
${hasMetafields ? metafieldFragment : ""}
|
|
2290
|
+
${seoFragment}
|
|
2142
2291
|
${fragment}
|
|
2143
2292
|
`
|
|
2144
2293
|
);
|
|
2294
|
+
const query = graphqlQuery || defaultQuery;
|
|
2145
2295
|
const variables = { handle };
|
|
2146
|
-
|
|
2147
|
-
variables
|
|
2148
|
-
|
|
2149
|
-
|
|
2296
|
+
const data = await client.query(query, {
|
|
2297
|
+
...variables,
|
|
2298
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2299
|
+
metafieldIdentifiers,
|
|
2300
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2301
|
+
)
|
|
2302
|
+
});
|
|
2150
2303
|
if (!data || !data.blog) {
|
|
2151
2304
|
return void 0;
|
|
2152
2305
|
}
|
|
@@ -2154,11 +2307,11 @@ async function getBlog(client, options) {
|
|
|
2154
2307
|
}
|
|
2155
2308
|
|
|
2156
2309
|
// src/api/blog/get-all-blogs.ts
|
|
2157
|
-
async function
|
|
2158
|
-
const { first = 250, query, metafieldIdentifiers } = options;
|
|
2159
|
-
const hasMetafields = metafieldIdentifiers
|
|
2310
|
+
async function fetchAllPages2(client, options, afterCursor) {
|
|
2311
|
+
const { first = 250, query, graphqlQuery, metafieldIdentifiers } = options;
|
|
2312
|
+
const hasMetafields = !!metafieldIdentifiers?.blog?.length;
|
|
2160
2313
|
const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2161
|
-
const
|
|
2314
|
+
const defaultQueryString = (
|
|
2162
2315
|
/* GraphQL */
|
|
2163
2316
|
`
|
|
2164
2317
|
query getAllBlogs(
|
|
@@ -2166,7 +2319,7 @@ async function fetchAllPages3(client, options, afterCursor) {
|
|
|
2166
2319
|
$after: String
|
|
2167
2320
|
${query ? "$query: String!" : ""}
|
|
2168
2321
|
${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2169
|
-
)
|
|
2322
|
+
) {
|
|
2170
2323
|
blogs(
|
|
2171
2324
|
first: $first
|
|
2172
2325
|
after: $after
|
|
@@ -2182,67 +2335,80 @@ async function fetchAllPages3(client, options, afterCursor) {
|
|
|
2182
2335
|
}
|
|
2183
2336
|
}
|
|
2184
2337
|
}
|
|
2338
|
+
${hasMetafields ? metafieldFragment : ""}
|
|
2339
|
+
${seoFragment}
|
|
2185
2340
|
${fragment}
|
|
2186
2341
|
${pageInfoFragment}
|
|
2187
2342
|
`
|
|
2188
2343
|
);
|
|
2344
|
+
const queryString = graphqlQuery || defaultQueryString;
|
|
2189
2345
|
const variables = { first, after: afterCursor };
|
|
2190
2346
|
if (query) {
|
|
2191
2347
|
variables.query = query;
|
|
2192
2348
|
}
|
|
2193
|
-
|
|
2194
|
-
variables
|
|
2195
|
-
|
|
2196
|
-
|
|
2349
|
+
const data = await client.query(queryString, {
|
|
2350
|
+
...variables,
|
|
2351
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2352
|
+
metafieldIdentifiers,
|
|
2353
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2354
|
+
)
|
|
2355
|
+
});
|
|
2197
2356
|
if (!data || !data.blogs) {
|
|
2198
2357
|
return [];
|
|
2199
2358
|
}
|
|
2200
2359
|
const blogs = data.blogs.edges?.map((edge) => normalizeBlog(edge.node)) || [];
|
|
2201
2360
|
if (data.blogs.pageInfo.hasNextPage) {
|
|
2202
|
-
const nextBlogs = await
|
|
2361
|
+
const nextBlogs = await fetchAllPages2(client, options, data.blogs.pageInfo.endCursor);
|
|
2203
2362
|
return [...blogs, ...nextBlogs];
|
|
2204
2363
|
}
|
|
2205
2364
|
return blogs;
|
|
2206
2365
|
}
|
|
2207
2366
|
async function getAllBlogs(client, options) {
|
|
2208
|
-
return
|
|
2367
|
+
return fetchAllPages2(client, options);
|
|
2209
2368
|
}
|
|
2210
2369
|
|
|
2211
2370
|
// src/api/blog/get-article.ts
|
|
2212
2371
|
async function getArticle(client, options) {
|
|
2213
|
-
const { blogHandle, articleHandle, metafieldIdentifiers } = options;
|
|
2214
|
-
const
|
|
2215
|
-
const
|
|
2216
|
-
const
|
|
2217
|
-
const
|
|
2372
|
+
const { blogHandle, articleHandle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2373
|
+
const hasArticleMetafields = !!metafieldIdentifiers?.article?.length;
|
|
2374
|
+
const hasBlogMetafields = !!metafieldIdentifiers?.blog?.length;
|
|
2375
|
+
const articleFrag = hasArticleMetafields ? articleWithMetafieldsFragment : articleFragment;
|
|
2376
|
+
const blogFrag = hasBlogMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2377
|
+
const defaultQuery = (
|
|
2218
2378
|
/* GraphQL */
|
|
2219
2379
|
`
|
|
2220
2380
|
query getArticle(
|
|
2221
2381
|
$blogHandle: String!
|
|
2222
2382
|
$articleHandle: String!
|
|
2223
|
-
${
|
|
2224
|
-
${
|
|
2225
|
-
)
|
|
2383
|
+
${hasBlogMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2384
|
+
${hasArticleMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2385
|
+
) {
|
|
2226
2386
|
blog(handle: $blogHandle) {
|
|
2227
|
-
...${
|
|
2387
|
+
...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
|
|
2228
2388
|
articleByHandle(handle: $articleHandle) {
|
|
2229
|
-
...${
|
|
2389
|
+
...${hasArticleMetafields ? "articleWithMetafields" : "article"}
|
|
2230
2390
|
blog {
|
|
2231
|
-
...${
|
|
2391
|
+
...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
|
|
2232
2392
|
}
|
|
2233
2393
|
}
|
|
2234
2394
|
}
|
|
2235
2395
|
}
|
|
2396
|
+
${imageFragment}
|
|
2397
|
+
${hasArticleMetafields || hasBlogMetafields ? metafieldFragment : ""}
|
|
2398
|
+
${seoFragment}
|
|
2236
2399
|
${articleFrag}
|
|
2237
2400
|
${blogFrag}
|
|
2238
2401
|
`
|
|
2239
2402
|
);
|
|
2403
|
+
const query = graphqlQuery || defaultQuery;
|
|
2240
2404
|
const variables = { blogHandle, articleHandle };
|
|
2241
|
-
|
|
2242
|
-
variables
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2405
|
+
const data = await client.query(query, {
|
|
2406
|
+
...variables,
|
|
2407
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2408
|
+
metafieldIdentifiers,
|
|
2409
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2410
|
+
)
|
|
2411
|
+
});
|
|
2246
2412
|
if (!data || !data.blog || !data.blog.articleByHandle) {
|
|
2247
2413
|
return void 0;
|
|
2248
2414
|
}
|
|
@@ -2250,11 +2416,18 @@ async function getArticle(client, options) {
|
|
|
2250
2416
|
}
|
|
2251
2417
|
|
|
2252
2418
|
// src/api/blog/get-articles.ts
|
|
2253
|
-
async function
|
|
2254
|
-
const {
|
|
2255
|
-
|
|
2419
|
+
async function fetchAllArticles(client, options, afterCursor) {
|
|
2420
|
+
const {
|
|
2421
|
+
first = 250,
|
|
2422
|
+
query,
|
|
2423
|
+
graphqlQuery,
|
|
2424
|
+
sortKey = "PUBLISHED_AT",
|
|
2425
|
+
reverse = false,
|
|
2426
|
+
metafieldIdentifiers
|
|
2427
|
+
} = options;
|
|
2428
|
+
const hasMetafields = !!metafieldIdentifiers?.article?.length;
|
|
2256
2429
|
const fragment = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
|
|
2257
|
-
const
|
|
2430
|
+
const defaultQueryString = (
|
|
2258
2431
|
/* GraphQL */
|
|
2259
2432
|
`
|
|
2260
2433
|
query getArticles(
|
|
@@ -2264,7 +2437,7 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2264
2437
|
$sortKey: ArticleSortKeys!
|
|
2265
2438
|
$reverse: Boolean!
|
|
2266
2439
|
${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2267
|
-
)
|
|
2440
|
+
) {
|
|
2268
2441
|
articles(
|
|
2269
2442
|
first: $first
|
|
2270
2443
|
after: $after
|
|
@@ -2282,10 +2455,14 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2282
2455
|
}
|
|
2283
2456
|
}
|
|
2284
2457
|
}
|
|
2458
|
+
${imageFragment}
|
|
2459
|
+
${hasMetafields ? metafieldFragment : ""}
|
|
2460
|
+
${seoFragment}
|
|
2285
2461
|
${fragment}
|
|
2286
2462
|
${pageInfoFragment}
|
|
2287
2463
|
`
|
|
2288
2464
|
);
|
|
2465
|
+
const queryString = graphqlQuery || defaultQueryString;
|
|
2289
2466
|
const variables = {
|
|
2290
2467
|
first,
|
|
2291
2468
|
after: afterCursor,
|
|
@@ -2295,31 +2472,42 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2295
2472
|
if (query) {
|
|
2296
2473
|
variables.query = query;
|
|
2297
2474
|
}
|
|
2298
|
-
|
|
2299
|
-
variables
|
|
2300
|
-
|
|
2301
|
-
|
|
2475
|
+
const data = await client.query(queryString, {
|
|
2476
|
+
...variables,
|
|
2477
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2478
|
+
metafieldIdentifiers,
|
|
2479
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2480
|
+
)
|
|
2481
|
+
});
|
|
2302
2482
|
if (!data || !data.articles) {
|
|
2303
2483
|
return [];
|
|
2304
2484
|
}
|
|
2305
2485
|
const articles = data.articles.edges?.map((edge) => normalizeArticle(edge.node)) || [];
|
|
2306
2486
|
if (data.articles.pageInfo.hasNextPage) {
|
|
2307
|
-
const nextArticles = await
|
|
2487
|
+
const nextArticles = await fetchAllArticles(client, options, data.articles.pageInfo.endCursor);
|
|
2308
2488
|
return [...articles, ...nextArticles];
|
|
2309
2489
|
}
|
|
2310
2490
|
return articles;
|
|
2311
2491
|
}
|
|
2312
2492
|
async function getArticles(client, options) {
|
|
2313
|
-
return
|
|
2493
|
+
return fetchAllArticles(client, options);
|
|
2314
2494
|
}
|
|
2315
2495
|
|
|
2316
2496
|
// src/api/blog/get-articles-in-blog.ts
|
|
2317
|
-
async function
|
|
2318
|
-
const {
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2497
|
+
async function fetchArticlesInBlog(client, options, afterCursor) {
|
|
2498
|
+
const {
|
|
2499
|
+
blogHandle,
|
|
2500
|
+
first = 250,
|
|
2501
|
+
graphqlQuery,
|
|
2502
|
+
sortKey = "PUBLISHED_AT",
|
|
2503
|
+
reverse = false,
|
|
2504
|
+
metafieldIdentifiers
|
|
2505
|
+
} = options;
|
|
2506
|
+
const hasArticleMetafields = !!metafieldIdentifiers?.article?.length;
|
|
2507
|
+
const hasBlogMetafields = !!metafieldIdentifiers?.blog?.length;
|
|
2508
|
+
const articleFrag = hasArticleMetafields ? articleWithMetafieldsFragment : articleFragment;
|
|
2509
|
+
const blogFrag = hasBlogMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2510
|
+
const defaultQuery = (
|
|
2323
2511
|
/* GraphQL */
|
|
2324
2512
|
`
|
|
2325
2513
|
query getArticlesInBlog(
|
|
@@ -2328,11 +2516,11 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2328
2516
|
$after: String
|
|
2329
2517
|
$sortKey: ArticleSortKeys!
|
|
2330
2518
|
$reverse: Boolean!
|
|
2331
|
-
${
|
|
2332
|
-
${
|
|
2333
|
-
)
|
|
2519
|
+
${hasBlogMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2520
|
+
${hasArticleMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2521
|
+
) {
|
|
2334
2522
|
blog(handle: $blogHandle) {
|
|
2335
|
-
...${
|
|
2523
|
+
...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
|
|
2336
2524
|
articles(
|
|
2337
2525
|
first: $first
|
|
2338
2526
|
after: $after
|
|
@@ -2341,7 +2529,7 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2341
2529
|
) {
|
|
2342
2530
|
edges {
|
|
2343
2531
|
node {
|
|
2344
|
-
...${
|
|
2532
|
+
...${hasArticleMetafields ? "articleWithMetafields" : "article"}
|
|
2345
2533
|
}
|
|
2346
2534
|
}
|
|
2347
2535
|
pageInfo {
|
|
@@ -2350,11 +2538,15 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2350
2538
|
}
|
|
2351
2539
|
}
|
|
2352
2540
|
}
|
|
2541
|
+
${imageFragment}
|
|
2542
|
+
${hasArticleMetafields || hasBlogMetafields ? metafieldFragment : ""}
|
|
2543
|
+
${seoFragment}
|
|
2353
2544
|
${articleFrag}
|
|
2354
2545
|
${blogFrag}
|
|
2355
2546
|
${pageInfoFragment}
|
|
2356
2547
|
`
|
|
2357
2548
|
);
|
|
2549
|
+
const query = graphqlQuery || defaultQuery;
|
|
2358
2550
|
const variables = {
|
|
2359
2551
|
blogHandle,
|
|
2360
2552
|
first,
|
|
@@ -2362,25 +2554,131 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2362
2554
|
sortKey,
|
|
2363
2555
|
reverse
|
|
2364
2556
|
};
|
|
2365
|
-
|
|
2366
|
-
variables
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2557
|
+
const data = await client.query(query, {
|
|
2558
|
+
...variables,
|
|
2559
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2560
|
+
metafieldIdentifiers,
|
|
2561
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2562
|
+
)
|
|
2563
|
+
});
|
|
2370
2564
|
if (!data || !data.blog || !data.blog.articles) {
|
|
2371
2565
|
return [];
|
|
2372
2566
|
}
|
|
2373
2567
|
const articles = data.blog.articles.edges?.map((edge) => normalizeArticle(edge.node)) || [];
|
|
2374
2568
|
if (data.blog.articles.pageInfo.hasNextPage) {
|
|
2375
|
-
const nextArticles = await
|
|
2569
|
+
const nextArticles = await fetchArticlesInBlog(
|
|
2570
|
+
client,
|
|
2571
|
+
options,
|
|
2572
|
+
data.blog.articles.pageInfo.endCursor
|
|
2573
|
+
);
|
|
2376
2574
|
return [...articles, ...nextArticles];
|
|
2377
2575
|
}
|
|
2378
2576
|
return articles;
|
|
2379
2577
|
}
|
|
2380
2578
|
async function getArticlesInBlog(client, options) {
|
|
2381
|
-
return
|
|
2579
|
+
return fetchArticlesInBlog(client, options);
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
// src/api/page/normalize.ts
|
|
2583
|
+
function normalizePage(page) {
|
|
2584
|
+
return {
|
|
2585
|
+
id: page.id,
|
|
2586
|
+
handle: page.handle,
|
|
2587
|
+
title: page.title,
|
|
2588
|
+
body: page.body,
|
|
2589
|
+
bodySummary: page.bodySummary,
|
|
2590
|
+
createdAt: page.createdAt,
|
|
2591
|
+
updatedAt: page.updatedAt,
|
|
2592
|
+
seo: page.seo ? {
|
|
2593
|
+
...page.seo
|
|
2594
|
+
} : void 0,
|
|
2595
|
+
metafields: normalizeMetafields(page.metafields)
|
|
2596
|
+
};
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
// src/api/page/get-page.ts
|
|
2600
|
+
async function getPage(client, options) {
|
|
2601
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2602
|
+
const hasMetafields = !!metafieldIdentifiers?.page?.length;
|
|
2603
|
+
const fragment = hasMetafields ? pageWithMetafieldsFragment : pageFragment;
|
|
2604
|
+
const defaultQuery = (
|
|
2605
|
+
/* GraphQL */
|
|
2606
|
+
`
|
|
2607
|
+
query getPage(
|
|
2608
|
+
$handle: String!
|
|
2609
|
+
${hasMetafields ? "$pageMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2610
|
+
) {
|
|
2611
|
+
page(handle: $handle) {
|
|
2612
|
+
...${hasMetafields ? "pageWithMetafields" : "page"}
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
${fragment}
|
|
2616
|
+
`
|
|
2617
|
+
);
|
|
2618
|
+
const query = graphqlQuery || defaultQuery;
|
|
2619
|
+
const variables = { handle };
|
|
2620
|
+
if (hasMetafields) {
|
|
2621
|
+
variables.pageMetafieldIdentifiers = metafieldIdentifiers;
|
|
2622
|
+
}
|
|
2623
|
+
const data = await client.query(query, {
|
|
2624
|
+
...variables,
|
|
2625
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2626
|
+
metafieldIdentifiers,
|
|
2627
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2628
|
+
)
|
|
2629
|
+
});
|
|
2630
|
+
if (!data || !data.page) {
|
|
2631
|
+
return void 0;
|
|
2632
|
+
}
|
|
2633
|
+
return normalizePage(data.page);
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
// src/api/shop/normalize.ts
|
|
2637
|
+
function normalizeShop(shop) {
|
|
2638
|
+
return {
|
|
2639
|
+
name: shop.name,
|
|
2640
|
+
description: shop.description || "",
|
|
2641
|
+
moneyFormat: shop.moneyFormat,
|
|
2642
|
+
paymentSettings: shop.paymentSettings,
|
|
2643
|
+
primaryDomain: shop.primaryDomain,
|
|
2644
|
+
brand: shop.brand || void 0,
|
|
2645
|
+
metafields: normalizeMetafields(shop.metafields)
|
|
2646
|
+
};
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
// src/api/shop/get-shop.ts
|
|
2650
|
+
async function getShop(client, options) {
|
|
2651
|
+
const { graphqlQuery, metafieldIdentifiers } = options;
|
|
2652
|
+
const hasMetafields = !!metafieldIdentifiers?.shop?.length;
|
|
2653
|
+
const fragment = hasMetafields ? shopWithMetafieldsFragment : shopFragment;
|
|
2654
|
+
const defaultQuery = (
|
|
2655
|
+
/* GraphQL */
|
|
2656
|
+
`
|
|
2657
|
+
query getShop(
|
|
2658
|
+
${hasMetafields ? "$shopMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2659
|
+
) {
|
|
2660
|
+
shop {
|
|
2661
|
+
...${hasMetafields ? "shopWithMetafields" : "shop"}
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
${fragment}
|
|
2665
|
+
`
|
|
2666
|
+
);
|
|
2667
|
+
const query = graphqlQuery || defaultQuery;
|
|
2668
|
+
const variables = {};
|
|
2669
|
+
const data = await client.query(query, {
|
|
2670
|
+
...variables,
|
|
2671
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2672
|
+
metafieldIdentifiers,
|
|
2673
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2674
|
+
)
|
|
2675
|
+
});
|
|
2676
|
+
if (!data || !data.shop) {
|
|
2677
|
+
return void 0;
|
|
2678
|
+
}
|
|
2679
|
+
return normalizeShop(data.shop);
|
|
2382
2680
|
}
|
|
2383
2681
|
|
|
2384
|
-
export { ShopifyClient, addCartItemsMutation, addCartLines, articleFragment, articleWithMetafieldsFragment, blogFragment, blogWithMetafieldsFragment, cartFragment, collectionFragment, createCart, createCartMutation, createShopifyClient, getAllBlogs, getAllCollections, getAllProducts, getAllProductsPathsQuery, getArticle, getArticles, getArticlesInBlog, getBlog, getCart, getCartQuery, getCollection, getCollections, getCollectionsByHandles, getCollectionsByHandlesQuery, getProduct, getProductQuery, getProducts, getProductsByHandles, getProductsByHandlesQuery, getProductsQuery, imageFragment, metafieldFragment, metafieldFragmentStr, normalizeArticle, normalizeBlog, normalizeCart, normalizeCollection, normalizeLineItem, normalizeProduct, pageInfoFragment, productFragment, removeCartItemsMutation, removeCartLines, seoFragment, updateBuyerIdentity, updateBuyerIdentityMutation, updateCartAttributes, updateCartAttributesMutation, updateCartCodes, updateCartDeliveryOptions, updateCartDeliveryOptionsMutation, updateCartDiscountCodeMutation, updateCartItemsMutation, updateCartLines, variantFragment };
|
|
2682
|
+
export { ShopifyClient, addCartItemsMutation, addCartLines, articleFragment, articleWithMetafieldsFragment, blogFragment, blogWithMetafieldsFragment, cartFragment, collectionFragment, createCart, createCartMutation, createShopifyClient, getAllBlogs, getAllCollections, getAllProducts, getAllProductsPathsQuery, getArticle, getArticles, getArticlesInBlog, getBlog, getCart, getCartQuery, getCollection, getCollections, getCollectionsByHandles, getCollectionsByHandlesQuery, getPage, getProduct, getProductQuery, getProducts, getProductsByHandles, getProductsByHandlesQuery, getProductsQuery, getShop, imageFragment, metafieldFragment, metafieldFragmentStr, normalizeArticle, normalizeBlog, normalizeCart, normalizeCollection, normalizeLineItem, normalizePage, normalizeProduct, normalizeShop, pageFragment, pageInfoFragment, pageWithMetafieldsFragment, productFragment, removeCartItemsMutation, removeCartLines, seoFragment, shopFragment, shopWithMetafieldsFragment, updateBuyerIdentity, updateBuyerIdentityMutation, updateCartAttributes, updateCartAttributesMutation, updateCartCodes, updateCartDeliveryOptions, updateCartDeliveryOptionsMutation, updateCartDiscountCodeMutation, updateCartItemsMutation, updateCartLines, variantFragment };
|
|
2385
2683
|
//# sourceMappingURL=index.mjs.map
|
|
2386
2684
|
//# sourceMappingURL=index.mjs.map
|