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