@anker-in/shopify-sdk 1.2.0-beta.8 → 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 +453 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +446 -146
- package/dist/index.mjs.map +1 -1
- package/dist/queries/index.js +6 -4
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +6 -4
- package/dist/queries/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,11 +750,123 @@ 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
|
+
}
|
|
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
|
+
}
|
|
764
793
|
${seoFragment}
|
|
765
794
|
${metafieldFragment}
|
|
766
795
|
`
|
|
767
796
|
);
|
|
768
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
|
+
}
|
|
866
|
+
${metafieldFragment}
|
|
867
|
+
`
|
|
868
|
+
);
|
|
869
|
+
|
|
769
870
|
// src/queries/product/get-product.ts
|
|
770
871
|
var getProductQuery = (
|
|
771
872
|
/* GraphQL */
|
|
@@ -960,10 +1061,12 @@ var getCollectionsByHandlesQuery = (handles) => (
|
|
|
960
1061
|
...metafield
|
|
961
1062
|
}
|
|
962
1063
|
variants(first: 10) {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1064
|
+
edges {
|
|
1065
|
+
node {
|
|
1066
|
+
...variant
|
|
1067
|
+
metafields(identifiers: $variantMetafieldIdentifiers) {
|
|
1068
|
+
...metafield
|
|
1069
|
+
}
|
|
967
1070
|
}
|
|
968
1071
|
}
|
|
969
1072
|
}
|
|
@@ -1300,13 +1403,16 @@ var getProductQuery2 = (
|
|
|
1300
1403
|
`
|
|
1301
1404
|
);
|
|
1302
1405
|
async function getProduct(client, options) {
|
|
1303
|
-
const { handle, metafieldIdentifiers } = options;
|
|
1406
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
1407
|
+
const query = graphqlQuery || getProductQuery2;
|
|
1304
1408
|
const variables = { handle };
|
|
1305
|
-
|
|
1306
|
-
variables
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1409
|
+
const data = await client.query(query, {
|
|
1410
|
+
...variables,
|
|
1411
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
1412
|
+
metafieldIdentifiers,
|
|
1413
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
1414
|
+
)
|
|
1415
|
+
});
|
|
1310
1416
|
if (!data?.product) {
|
|
1311
1417
|
return void 0;
|
|
1312
1418
|
}
|
|
@@ -1360,8 +1466,9 @@ var getAllProductsQuery = (
|
|
|
1360
1466
|
${imageFragment}
|
|
1361
1467
|
`
|
|
1362
1468
|
);
|
|
1363
|
-
async function
|
|
1364
|
-
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;
|
|
1365
1472
|
const variables = {
|
|
1366
1473
|
first,
|
|
1367
1474
|
after: afterCursor,
|
|
@@ -1369,26 +1476,37 @@ async function fetchAllPages(client, options, afterCursor) {
|
|
|
1369
1476
|
sortKey,
|
|
1370
1477
|
reverse
|
|
1371
1478
|
};
|
|
1372
|
-
|
|
1373
|
-
variables
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1479
|
+
const data = await client.query(queryString, {
|
|
1480
|
+
...variables,
|
|
1481
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
1482
|
+
metafieldIdentifiers,
|
|
1483
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
1484
|
+
)
|
|
1485
|
+
});
|
|
1377
1486
|
if (!data || !data.products) {
|
|
1378
1487
|
return [];
|
|
1379
1488
|
}
|
|
1380
1489
|
const products = data.products.edges.map((edge) => normalizeProduct(edge.node));
|
|
1381
1490
|
if (data.products.pageInfo.hasNextPage) {
|
|
1382
|
-
const nextProducts = await
|
|
1491
|
+
const nextProducts = await fetchAllProducts(client, options, data.products.pageInfo.endCursor);
|
|
1383
1492
|
return [...products, ...nextProducts];
|
|
1384
1493
|
}
|
|
1385
1494
|
return products;
|
|
1386
1495
|
}
|
|
1387
1496
|
async function getAllProducts(client, options) {
|
|
1388
|
-
return
|
|
1497
|
+
return fetchAllProducts(client, options);
|
|
1389
1498
|
}
|
|
1390
1499
|
async function getProducts(client, options) {
|
|
1391
|
-
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;
|
|
1392
1510
|
const variables = {
|
|
1393
1511
|
first,
|
|
1394
1512
|
after,
|
|
@@ -1400,7 +1518,7 @@ async function getProducts(client, options) {
|
|
|
1400
1518
|
variables.productMetafieldIdentifiers = metafieldIdentifiers;
|
|
1401
1519
|
variables.variantMetafieldIdentifiers = metafieldIdentifiers;
|
|
1402
1520
|
}
|
|
1403
|
-
const data = await client.query(
|
|
1521
|
+
const data = await client.query(queryString, variables);
|
|
1404
1522
|
if (!data || !data.products) {
|
|
1405
1523
|
return {
|
|
1406
1524
|
products: [],
|
|
@@ -1450,11 +1568,11 @@ function buildProductsByHandlesQuery(handles) {
|
|
|
1450
1568
|
);
|
|
1451
1569
|
}
|
|
1452
1570
|
async function getProductsByHandles(client, options) {
|
|
1453
|
-
const { handles, metafieldIdentifiers } = options;
|
|
1571
|
+
const { handles, graphqlQuery, metafieldIdentifiers } = options;
|
|
1454
1572
|
if (!handles || handles.length === 0) {
|
|
1455
1573
|
return [];
|
|
1456
1574
|
}
|
|
1457
|
-
const query = buildProductsByHandlesQuery(handles);
|
|
1575
|
+
const query = graphqlQuery || buildProductsByHandlesQuery(handles);
|
|
1458
1576
|
const data = await client.query(query, {
|
|
1459
1577
|
handles,
|
|
1460
1578
|
// 请勿删除,这个参数虽然没有在 query 中使用,但方便在 chrome dev tools 中查看请求参数
|
|
@@ -1575,7 +1693,8 @@ function normalizeCart(cart) {
|
|
|
1575
1693
|
|
|
1576
1694
|
// src/api/cart/get-cart.ts
|
|
1577
1695
|
async function getCart(client, options) {
|
|
1578
|
-
const { id, cookieAdapter, metafieldIdentifiers } = options;
|
|
1696
|
+
const { id, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1697
|
+
const query = graphqlQuery || getCartQuery;
|
|
1579
1698
|
const locale = client.getLocale();
|
|
1580
1699
|
const cartId = id || cookieAdapter?.getCartId(locale);
|
|
1581
1700
|
console.log("cartId", cartId);
|
|
@@ -1583,7 +1702,7 @@ async function getCart(client, options) {
|
|
|
1583
1702
|
return void 0;
|
|
1584
1703
|
}
|
|
1585
1704
|
try {
|
|
1586
|
-
const data = await client.query(
|
|
1705
|
+
const data = await client.query(query, {
|
|
1587
1706
|
cartId,
|
|
1588
1707
|
...constructMetafieldIdentifiersQueryParams(
|
|
1589
1708
|
metafieldIdentifiers,
|
|
@@ -1618,12 +1737,14 @@ async function createCart(client, options = {}) {
|
|
|
1618
1737
|
buyerIdentity,
|
|
1619
1738
|
discountCodes,
|
|
1620
1739
|
customAttributes,
|
|
1740
|
+
graphqlQuery,
|
|
1621
1741
|
metafieldIdentifiers,
|
|
1622
1742
|
updateCookie = false
|
|
1623
1743
|
} = options;
|
|
1744
|
+
const query = graphqlQuery || createCartMutation;
|
|
1624
1745
|
const locale = client.getLocale();
|
|
1625
1746
|
try {
|
|
1626
|
-
const data = await client.query(
|
|
1747
|
+
const data = await client.query(query, {
|
|
1627
1748
|
lines,
|
|
1628
1749
|
buyerIdentity,
|
|
1629
1750
|
discountCodes,
|
|
@@ -1653,7 +1774,8 @@ async function createCart(client, options = {}) {
|
|
|
1653
1774
|
|
|
1654
1775
|
// src/api/cart/add-cart-lines.ts
|
|
1655
1776
|
async function addCartLines(client, options) {
|
|
1656
|
-
const { cartId: providedCartId, lines, cookieAdapter, metafieldIdentifiers } = options;
|
|
1777
|
+
const { cartId: providedCartId, lines, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1778
|
+
const query = graphqlQuery || addCartItemsMutation;
|
|
1657
1779
|
const locale = client.getLocale();
|
|
1658
1780
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1659
1781
|
if (!cartId) {
|
|
@@ -1664,7 +1786,7 @@ async function addCartLines(client, options) {
|
|
|
1664
1786
|
client.getConfig().getMetafieldNamespacePrefix()
|
|
1665
1787
|
);
|
|
1666
1788
|
try {
|
|
1667
|
-
const data = await client.query(
|
|
1789
|
+
const data = await client.query(query, {
|
|
1668
1790
|
cartId,
|
|
1669
1791
|
lines,
|
|
1670
1792
|
...normalizedMetafieldIdentifiers
|
|
@@ -1689,7 +1811,8 @@ async function addCartLines(client, options) {
|
|
|
1689
1811
|
|
|
1690
1812
|
// src/api/cart/update-cart-lines.ts
|
|
1691
1813
|
async function updateCartLines(client, options) {
|
|
1692
|
-
const { cartId: providedCartId, lines, cookieAdapter, metafieldIdentifiers } = options;
|
|
1814
|
+
const { cartId: providedCartId, lines, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1815
|
+
const query = graphqlQuery || updateCartItemsMutation;
|
|
1693
1816
|
const locale = client.getLocale();
|
|
1694
1817
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1695
1818
|
if (!cartId) {
|
|
@@ -1702,7 +1825,7 @@ async function updateCartLines(client, options) {
|
|
|
1702
1825
|
console.log("update-cart-lines metafieldIdentifiers:", metafieldIdentifiers);
|
|
1703
1826
|
console.log("update-cart-lines metafieldParams:", metafieldParams);
|
|
1704
1827
|
try {
|
|
1705
|
-
const data = await client.query(
|
|
1828
|
+
const data = await client.query(query, {
|
|
1706
1829
|
cartId,
|
|
1707
1830
|
lines,
|
|
1708
1831
|
...metafieldParams
|
|
@@ -1736,14 +1859,15 @@ async function updateCartLines(client, options) {
|
|
|
1736
1859
|
|
|
1737
1860
|
// src/api/cart/remove-cart-lines.ts
|
|
1738
1861
|
async function removeCartLines(client, options) {
|
|
1739
|
-
const { cartId: providedCartId, lineIds, cookieAdapter, metafieldIdentifiers } = options;
|
|
1862
|
+
const { cartId: providedCartId, lineIds, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1863
|
+
const query = graphqlQuery || removeCartItemsMutation;
|
|
1740
1864
|
const locale = client.getLocale();
|
|
1741
1865
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1742
1866
|
if (!cartId) {
|
|
1743
1867
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1744
1868
|
}
|
|
1745
1869
|
try {
|
|
1746
|
-
const data = await client.query(
|
|
1870
|
+
const data = await client.query(query, {
|
|
1747
1871
|
cartId,
|
|
1748
1872
|
lineIds,
|
|
1749
1873
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1770,14 +1894,15 @@ async function removeCartLines(client, options) {
|
|
|
1770
1894
|
|
|
1771
1895
|
// src/api/cart/update-cart-codes.ts
|
|
1772
1896
|
async function updateCartCodes(client, options) {
|
|
1773
|
-
const { cartId: providedCartId, discountCodes, cookieAdapter, metafieldIdentifiers } = options;
|
|
1897
|
+
const { cartId: providedCartId, discountCodes, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1898
|
+
const query = graphqlQuery || updateCartDiscountCodeMutation;
|
|
1774
1899
|
const locale = client.getLocale();
|
|
1775
1900
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1776
1901
|
if (!cartId) {
|
|
1777
1902
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1778
1903
|
}
|
|
1779
1904
|
try {
|
|
1780
|
-
const data = await client.query(
|
|
1905
|
+
const data = await client.query(query, {
|
|
1781
1906
|
cartId,
|
|
1782
1907
|
discountCodes,
|
|
1783
1908
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1801,14 +1926,15 @@ async function updateCartCodes(client, options) {
|
|
|
1801
1926
|
|
|
1802
1927
|
// src/api/cart/update-cart-attributes.ts
|
|
1803
1928
|
async function updateCartAttributes(client, options) {
|
|
1804
|
-
const { cartId: providedCartId, attributes, cookieAdapter, metafieldIdentifiers } = options;
|
|
1929
|
+
const { cartId: providedCartId, attributes, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1930
|
+
const query = graphqlQuery || updateCartAttributesMutation;
|
|
1805
1931
|
const locale = client.getLocale();
|
|
1806
1932
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1807
1933
|
if (!cartId) {
|
|
1808
1934
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1809
1935
|
}
|
|
1810
1936
|
try {
|
|
1811
|
-
const data = await client.query(
|
|
1937
|
+
const data = await client.query(query, {
|
|
1812
1938
|
cartId,
|
|
1813
1939
|
attributes,
|
|
1814
1940
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1835,14 +1961,15 @@ async function updateCartAttributes(client, options) {
|
|
|
1835
1961
|
|
|
1836
1962
|
// src/api/cart/update-cart-delivery-options.ts
|
|
1837
1963
|
async function updateCartDeliveryOptions(client, options) {
|
|
1838
|
-
const { cartId: providedCartId, selectedDeliveryOptions, cookieAdapter, metafieldIdentifiers } = options;
|
|
1964
|
+
const { cartId: providedCartId, selectedDeliveryOptions, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
1965
|
+
const query = graphqlQuery || updateCartDeliveryOptionsMutation;
|
|
1839
1966
|
const locale = client.getLocale();
|
|
1840
1967
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1841
1968
|
if (!cartId) {
|
|
1842
1969
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1843
1970
|
}
|
|
1844
1971
|
try {
|
|
1845
|
-
const data = await client.query(
|
|
1972
|
+
const data = await client.query(query, {
|
|
1846
1973
|
cartId,
|
|
1847
1974
|
selectedDeliveryOptions,
|
|
1848
1975
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1869,14 +1996,15 @@ async function updateCartDeliveryOptions(client, options) {
|
|
|
1869
1996
|
|
|
1870
1997
|
// src/api/cart/update-buyer-identity.ts
|
|
1871
1998
|
async function updateBuyerIdentity(client, options) {
|
|
1872
|
-
const { cartId: providedCartId, buyerIdentity, cookieAdapter, metafieldIdentifiers } = options;
|
|
1999
|
+
const { cartId: providedCartId, buyerIdentity, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
|
|
2000
|
+
const query = graphqlQuery || updateBuyerIdentityMutation;
|
|
1873
2001
|
const locale = client.getLocale();
|
|
1874
2002
|
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1875
2003
|
if (!cartId) {
|
|
1876
2004
|
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1877
2005
|
}
|
|
1878
2006
|
try {
|
|
1879
|
-
const data = await client.query(
|
|
2007
|
+
const data = await client.query(query, {
|
|
1880
2008
|
cartId,
|
|
1881
2009
|
buyerIdentity,
|
|
1882
2010
|
...constructMetafieldIdentifiersQueryParams(
|
|
@@ -1947,12 +2075,16 @@ var getCollectionQuery = (
|
|
|
1947
2075
|
`
|
|
1948
2076
|
);
|
|
1949
2077
|
async function getCollection(client, options) {
|
|
1950
|
-
const { handle, metafieldIdentifiers } = options;
|
|
2078
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2079
|
+
const query = graphqlQuery || getCollectionQuery;
|
|
1951
2080
|
const variables = { handle };
|
|
1952
|
-
|
|
1953
|
-
variables
|
|
1954
|
-
|
|
1955
|
-
|
|
2081
|
+
const data = await client.query(query, {
|
|
2082
|
+
...variables,
|
|
2083
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2084
|
+
metafieldIdentifiers,
|
|
2085
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2086
|
+
)
|
|
2087
|
+
});
|
|
1956
2088
|
if (!data?.collection) {
|
|
1957
2089
|
return void 0;
|
|
1958
2090
|
}
|
|
@@ -1994,8 +2126,9 @@ var getAllCollectionsQuery = (
|
|
|
1994
2126
|
${imageFragment}
|
|
1995
2127
|
`
|
|
1996
2128
|
);
|
|
1997
|
-
async function
|
|
1998
|
-
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;
|
|
1999
2132
|
const variables = {
|
|
2000
2133
|
first,
|
|
2001
2134
|
after: afterCursor,
|
|
@@ -2003,25 +2136,41 @@ async function fetchAllPages2(client, options, afterCursor) {
|
|
|
2003
2136
|
sortKey,
|
|
2004
2137
|
reverse
|
|
2005
2138
|
};
|
|
2006
|
-
|
|
2007
|
-
variables
|
|
2008
|
-
|
|
2009
|
-
|
|
2139
|
+
const data = await client.query(queryString, {
|
|
2140
|
+
...variables,
|
|
2141
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2142
|
+
metafieldIdentifiers,
|
|
2143
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2144
|
+
)
|
|
2145
|
+
});
|
|
2010
2146
|
if (!data || !data.collections) {
|
|
2011
2147
|
return [];
|
|
2012
2148
|
}
|
|
2013
2149
|
const collections = data.collections.edges.map((edge) => normalizeCollection(edge.node));
|
|
2014
2150
|
if (data.collections.pageInfo.hasNextPage) {
|
|
2015
|
-
const nextCollections = await
|
|
2151
|
+
const nextCollections = await fetchAllPages(
|
|
2152
|
+
client,
|
|
2153
|
+
options,
|
|
2154
|
+
data.collections.pageInfo.endCursor
|
|
2155
|
+
);
|
|
2016
2156
|
return [...collections, ...nextCollections];
|
|
2017
2157
|
}
|
|
2018
2158
|
return collections;
|
|
2019
2159
|
}
|
|
2020
2160
|
async function getAllCollections(client, options) {
|
|
2021
|
-
return
|
|
2161
|
+
return fetchAllPages(client, options);
|
|
2022
2162
|
}
|
|
2023
2163
|
async function getCollections(client, options) {
|
|
2024
|
-
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;
|
|
2025
2174
|
const variables = {
|
|
2026
2175
|
first,
|
|
2027
2176
|
after,
|
|
@@ -2029,10 +2178,13 @@ async function getCollections(client, options) {
|
|
|
2029
2178
|
sortKey,
|
|
2030
2179
|
reverse
|
|
2031
2180
|
};
|
|
2032
|
-
|
|
2033
|
-
variables
|
|
2034
|
-
|
|
2035
|
-
|
|
2181
|
+
const data = await client.query(queryString, {
|
|
2182
|
+
...variables,
|
|
2183
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2184
|
+
metafieldIdentifiers,
|
|
2185
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2186
|
+
)
|
|
2187
|
+
});
|
|
2036
2188
|
if (!data || !data.collections) {
|
|
2037
2189
|
return {
|
|
2038
2190
|
collections: [],
|
|
@@ -2050,15 +2202,12 @@ async function getCollections(client, options) {
|
|
|
2050
2202
|
}
|
|
2051
2203
|
|
|
2052
2204
|
// src/api/collection/get-collections-by-handles.ts
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
options
|
|
2056
|
-
}) => {
|
|
2057
|
-
const { handles, metafieldIdentifiers } = options;
|
|
2205
|
+
async function getCollectionsByHandles(client, options) {
|
|
2206
|
+
const { handles, graphqlQuery, metafieldIdentifiers } = options;
|
|
2058
2207
|
if (handles.length === 0) {
|
|
2059
2208
|
return [];
|
|
2060
2209
|
}
|
|
2061
|
-
const query = getCollectionsByHandlesQuery(handles);
|
|
2210
|
+
const query = graphqlQuery || getCollectionsByHandlesQuery(handles);
|
|
2062
2211
|
const data = await client.query(query, {
|
|
2063
2212
|
handles,
|
|
2064
2213
|
// 请勿删除,这个参数虽然没有在 query 中使用,但方便在 chrome dev tools 中查看请求参数
|
|
@@ -2077,7 +2226,7 @@ var getCollectionsByHandles = async ({
|
|
|
2077
2226
|
return normalizeCollection(item);
|
|
2078
2227
|
});
|
|
2079
2228
|
return collections;
|
|
2080
|
-
}
|
|
2229
|
+
}
|
|
2081
2230
|
|
|
2082
2231
|
// src/api/blog/normalize.ts
|
|
2083
2232
|
function normalizeBlog(blog) {
|
|
@@ -2123,28 +2272,34 @@ function normalizeMetafields2(metafields) {
|
|
|
2123
2272
|
|
|
2124
2273
|
// src/api/blog/get-blog.ts
|
|
2125
2274
|
async function getBlog(client, options) {
|
|
2126
|
-
const { handle, metafieldIdentifiers } = options;
|
|
2127
|
-
const hasMetafields = metafieldIdentifiers
|
|
2275
|
+
const { handle, graphqlQuery, metafieldIdentifiers } = options;
|
|
2276
|
+
const hasMetafields = metafieldIdentifiers?.blog?.length;
|
|
2128
2277
|
const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2129
|
-
const
|
|
2278
|
+
const defaultQuery = (
|
|
2130
2279
|
/* GraphQL */
|
|
2131
2280
|
`
|
|
2132
2281
|
query getBlog(
|
|
2133
2282
|
$handle: String!
|
|
2134
2283
|
${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2135
|
-
)
|
|
2284
|
+
) {
|
|
2136
2285
|
blog(handle: $handle) {
|
|
2137
2286
|
...${hasMetafields ? "blogWithMetafields" : "blog"}
|
|
2138
2287
|
}
|
|
2139
2288
|
}
|
|
2289
|
+
${hasMetafields ? metafieldFragment : ""}
|
|
2290
|
+
${seoFragment}
|
|
2140
2291
|
${fragment}
|
|
2141
2292
|
`
|
|
2142
2293
|
);
|
|
2294
|
+
const query = graphqlQuery || defaultQuery;
|
|
2143
2295
|
const variables = { handle };
|
|
2144
|
-
|
|
2145
|
-
variables
|
|
2146
|
-
|
|
2147
|
-
|
|
2296
|
+
const data = await client.query(query, {
|
|
2297
|
+
...variables,
|
|
2298
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2299
|
+
metafieldIdentifiers,
|
|
2300
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2301
|
+
)
|
|
2302
|
+
});
|
|
2148
2303
|
if (!data || !data.blog) {
|
|
2149
2304
|
return void 0;
|
|
2150
2305
|
}
|
|
@@ -2152,11 +2307,11 @@ async function getBlog(client, options) {
|
|
|
2152
2307
|
}
|
|
2153
2308
|
|
|
2154
2309
|
// src/api/blog/get-all-blogs.ts
|
|
2155
|
-
async function
|
|
2156
|
-
const { first = 250, query, metafieldIdentifiers } = options;
|
|
2157
|
-
const hasMetafields = metafieldIdentifiers
|
|
2310
|
+
async function fetchAllPages2(client, options, afterCursor) {
|
|
2311
|
+
const { first = 250, query, graphqlQuery, metafieldIdentifiers } = options;
|
|
2312
|
+
const hasMetafields = !!metafieldIdentifiers?.blog?.length;
|
|
2158
2313
|
const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
|
|
2159
|
-
const
|
|
2314
|
+
const defaultQueryString = (
|
|
2160
2315
|
/* GraphQL */
|
|
2161
2316
|
`
|
|
2162
2317
|
query getAllBlogs(
|
|
@@ -2164,7 +2319,7 @@ async function fetchAllPages3(client, options, afterCursor) {
|
|
|
2164
2319
|
$after: String
|
|
2165
2320
|
${query ? "$query: String!" : ""}
|
|
2166
2321
|
${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2167
|
-
)
|
|
2322
|
+
) {
|
|
2168
2323
|
blogs(
|
|
2169
2324
|
first: $first
|
|
2170
2325
|
after: $after
|
|
@@ -2180,67 +2335,80 @@ async function fetchAllPages3(client, options, afterCursor) {
|
|
|
2180
2335
|
}
|
|
2181
2336
|
}
|
|
2182
2337
|
}
|
|
2338
|
+
${hasMetafields ? metafieldFragment : ""}
|
|
2339
|
+
${seoFragment}
|
|
2183
2340
|
${fragment}
|
|
2184
2341
|
${pageInfoFragment}
|
|
2185
2342
|
`
|
|
2186
2343
|
);
|
|
2344
|
+
const queryString = graphqlQuery || defaultQueryString;
|
|
2187
2345
|
const variables = { first, after: afterCursor };
|
|
2188
2346
|
if (query) {
|
|
2189
2347
|
variables.query = query;
|
|
2190
2348
|
}
|
|
2191
|
-
|
|
2192
|
-
variables
|
|
2193
|
-
|
|
2194
|
-
|
|
2349
|
+
const data = await client.query(queryString, {
|
|
2350
|
+
...variables,
|
|
2351
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2352
|
+
metafieldIdentifiers,
|
|
2353
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2354
|
+
)
|
|
2355
|
+
});
|
|
2195
2356
|
if (!data || !data.blogs) {
|
|
2196
2357
|
return [];
|
|
2197
2358
|
}
|
|
2198
2359
|
const blogs = data.blogs.edges?.map((edge) => normalizeBlog(edge.node)) || [];
|
|
2199
2360
|
if (data.blogs.pageInfo.hasNextPage) {
|
|
2200
|
-
const nextBlogs = await
|
|
2361
|
+
const nextBlogs = await fetchAllPages2(client, options, data.blogs.pageInfo.endCursor);
|
|
2201
2362
|
return [...blogs, ...nextBlogs];
|
|
2202
2363
|
}
|
|
2203
2364
|
return blogs;
|
|
2204
2365
|
}
|
|
2205
2366
|
async function getAllBlogs(client, options) {
|
|
2206
|
-
return
|
|
2367
|
+
return fetchAllPages2(client, options);
|
|
2207
2368
|
}
|
|
2208
2369
|
|
|
2209
2370
|
// src/api/blog/get-article.ts
|
|
2210
2371
|
async function getArticle(client, options) {
|
|
2211
|
-
const { blogHandle, articleHandle, metafieldIdentifiers } = options;
|
|
2212
|
-
const
|
|
2213
|
-
const
|
|
2214
|
-
const
|
|
2215
|
-
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 = (
|
|
2216
2378
|
/* GraphQL */
|
|
2217
2379
|
`
|
|
2218
2380
|
query getArticle(
|
|
2219
2381
|
$blogHandle: String!
|
|
2220
2382
|
$articleHandle: String!
|
|
2221
|
-
${
|
|
2222
|
-
${
|
|
2223
|
-
)
|
|
2383
|
+
${hasBlogMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2384
|
+
${hasArticleMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2385
|
+
) {
|
|
2224
2386
|
blog(handle: $blogHandle) {
|
|
2225
|
-
...${
|
|
2387
|
+
...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
|
|
2226
2388
|
articleByHandle(handle: $articleHandle) {
|
|
2227
|
-
...${
|
|
2389
|
+
...${hasArticleMetafields ? "articleWithMetafields" : "article"}
|
|
2228
2390
|
blog {
|
|
2229
|
-
...${
|
|
2391
|
+
...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
|
|
2230
2392
|
}
|
|
2231
2393
|
}
|
|
2232
2394
|
}
|
|
2233
2395
|
}
|
|
2396
|
+
${imageFragment}
|
|
2397
|
+
${hasArticleMetafields || hasBlogMetafields ? metafieldFragment : ""}
|
|
2398
|
+
${seoFragment}
|
|
2234
2399
|
${articleFrag}
|
|
2235
2400
|
${blogFrag}
|
|
2236
2401
|
`
|
|
2237
2402
|
);
|
|
2403
|
+
const query = graphqlQuery || defaultQuery;
|
|
2238
2404
|
const variables = { blogHandle, articleHandle };
|
|
2239
|
-
|
|
2240
|
-
variables
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2405
|
+
const data = await client.query(query, {
|
|
2406
|
+
...variables,
|
|
2407
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2408
|
+
metafieldIdentifiers,
|
|
2409
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2410
|
+
)
|
|
2411
|
+
});
|
|
2244
2412
|
if (!data || !data.blog || !data.blog.articleByHandle) {
|
|
2245
2413
|
return void 0;
|
|
2246
2414
|
}
|
|
@@ -2248,11 +2416,18 @@ async function getArticle(client, options) {
|
|
|
2248
2416
|
}
|
|
2249
2417
|
|
|
2250
2418
|
// src/api/blog/get-articles.ts
|
|
2251
|
-
async function
|
|
2252
|
-
const {
|
|
2253
|
-
|
|
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;
|
|
2254
2429
|
const fragment = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
|
|
2255
|
-
const
|
|
2430
|
+
const defaultQueryString = (
|
|
2256
2431
|
/* GraphQL */
|
|
2257
2432
|
`
|
|
2258
2433
|
query getArticles(
|
|
@@ -2262,7 +2437,7 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2262
2437
|
$sortKey: ArticleSortKeys!
|
|
2263
2438
|
$reverse: Boolean!
|
|
2264
2439
|
${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2265
|
-
)
|
|
2440
|
+
) {
|
|
2266
2441
|
articles(
|
|
2267
2442
|
first: $first
|
|
2268
2443
|
after: $after
|
|
@@ -2280,10 +2455,14 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2280
2455
|
}
|
|
2281
2456
|
}
|
|
2282
2457
|
}
|
|
2458
|
+
${imageFragment}
|
|
2459
|
+
${hasMetafields ? metafieldFragment : ""}
|
|
2460
|
+
${seoFragment}
|
|
2283
2461
|
${fragment}
|
|
2284
2462
|
${pageInfoFragment}
|
|
2285
2463
|
`
|
|
2286
2464
|
);
|
|
2465
|
+
const queryString = graphqlQuery || defaultQueryString;
|
|
2287
2466
|
const variables = {
|
|
2288
2467
|
first,
|
|
2289
2468
|
after: afterCursor,
|
|
@@ -2293,31 +2472,42 @@ async function fetchAllPages4(client, options, afterCursor) {
|
|
|
2293
2472
|
if (query) {
|
|
2294
2473
|
variables.query = query;
|
|
2295
2474
|
}
|
|
2296
|
-
|
|
2297
|
-
variables
|
|
2298
|
-
|
|
2299
|
-
|
|
2475
|
+
const data = await client.query(queryString, {
|
|
2476
|
+
...variables,
|
|
2477
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2478
|
+
metafieldIdentifiers,
|
|
2479
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2480
|
+
)
|
|
2481
|
+
});
|
|
2300
2482
|
if (!data || !data.articles) {
|
|
2301
2483
|
return [];
|
|
2302
2484
|
}
|
|
2303
2485
|
const articles = data.articles.edges?.map((edge) => normalizeArticle(edge.node)) || [];
|
|
2304
2486
|
if (data.articles.pageInfo.hasNextPage) {
|
|
2305
|
-
const nextArticles = await
|
|
2487
|
+
const nextArticles = await fetchAllArticles(client, options, data.articles.pageInfo.endCursor);
|
|
2306
2488
|
return [...articles, ...nextArticles];
|
|
2307
2489
|
}
|
|
2308
2490
|
return articles;
|
|
2309
2491
|
}
|
|
2310
2492
|
async function getArticles(client, options) {
|
|
2311
|
-
return
|
|
2493
|
+
return fetchAllArticles(client, options);
|
|
2312
2494
|
}
|
|
2313
2495
|
|
|
2314
2496
|
// src/api/blog/get-articles-in-blog.ts
|
|
2315
|
-
async function
|
|
2316
|
-
const {
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
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 = (
|
|
2321
2511
|
/* GraphQL */
|
|
2322
2512
|
`
|
|
2323
2513
|
query getArticlesInBlog(
|
|
@@ -2326,11 +2516,11 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2326
2516
|
$after: String
|
|
2327
2517
|
$sortKey: ArticleSortKeys!
|
|
2328
2518
|
$reverse: Boolean!
|
|
2329
|
-
${
|
|
2330
|
-
${
|
|
2331
|
-
)
|
|
2519
|
+
${hasBlogMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2520
|
+
${hasArticleMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
|
|
2521
|
+
) {
|
|
2332
2522
|
blog(handle: $blogHandle) {
|
|
2333
|
-
...${
|
|
2523
|
+
...${hasBlogMetafields ? "blogWithMetafields" : "blog"}
|
|
2334
2524
|
articles(
|
|
2335
2525
|
first: $first
|
|
2336
2526
|
after: $after
|
|
@@ -2339,7 +2529,7 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2339
2529
|
) {
|
|
2340
2530
|
edges {
|
|
2341
2531
|
node {
|
|
2342
|
-
...${
|
|
2532
|
+
...${hasArticleMetafields ? "articleWithMetafields" : "article"}
|
|
2343
2533
|
}
|
|
2344
2534
|
}
|
|
2345
2535
|
pageInfo {
|
|
@@ -2348,11 +2538,15 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2348
2538
|
}
|
|
2349
2539
|
}
|
|
2350
2540
|
}
|
|
2541
|
+
${imageFragment}
|
|
2542
|
+
${hasArticleMetafields || hasBlogMetafields ? metafieldFragment : ""}
|
|
2543
|
+
${seoFragment}
|
|
2351
2544
|
${articleFrag}
|
|
2352
2545
|
${blogFrag}
|
|
2353
2546
|
${pageInfoFragment}
|
|
2354
2547
|
`
|
|
2355
2548
|
);
|
|
2549
|
+
const query = graphqlQuery || defaultQuery;
|
|
2356
2550
|
const variables = {
|
|
2357
2551
|
blogHandle,
|
|
2358
2552
|
first,
|
|
@@ -2360,25 +2554,131 @@ async function fetchAllPages5(client, options, afterCursor) {
|
|
|
2360
2554
|
sortKey,
|
|
2361
2555
|
reverse
|
|
2362
2556
|
};
|
|
2363
|
-
|
|
2364
|
-
variables
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2557
|
+
const data = await client.query(query, {
|
|
2558
|
+
...variables,
|
|
2559
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
2560
|
+
metafieldIdentifiers,
|
|
2561
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
2562
|
+
)
|
|
2563
|
+
});
|
|
2368
2564
|
if (!data || !data.blog || !data.blog.articles) {
|
|
2369
2565
|
return [];
|
|
2370
2566
|
}
|
|
2371
2567
|
const articles = data.blog.articles.edges?.map((edge) => normalizeArticle(edge.node)) || [];
|
|
2372
2568
|
if (data.blog.articles.pageInfo.hasNextPage) {
|
|
2373
|
-
const nextArticles = await
|
|
2569
|
+
const nextArticles = await fetchArticlesInBlog(
|
|
2570
|
+
client,
|
|
2571
|
+
options,
|
|
2572
|
+
data.blog.articles.pageInfo.endCursor
|
|
2573
|
+
);
|
|
2374
2574
|
return [...articles, ...nextArticles];
|
|
2375
2575
|
}
|
|
2376
2576
|
return articles;
|
|
2377
2577
|
}
|
|
2378
2578
|
async function getArticlesInBlog(client, options) {
|
|
2379
|
-
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);
|
|
2380
2680
|
}
|
|
2381
2681
|
|
|
2382
|
-
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 };
|
|
2383
2683
|
//# sourceMappingURL=index.mjs.map
|
|
2384
2684
|
//# sourceMappingURL=index.mjs.map
|