@anker-in/shopify-sdk 1.2.0-beta.1 → 1.2.0-beta.11

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/index.mjs CHANGED
@@ -766,6 +766,110 @@ var blogWithMetafieldsFragment = (
766
766
  `
767
767
  );
768
768
 
769
+ // src/fragments/page.ts
770
+ var pageFragment = (
771
+ /* GraphQL */
772
+ `
773
+ fragment page on Page {
774
+ id
775
+ handle
776
+ title
777
+ body
778
+ bodySummary
779
+ createdAt
780
+ updatedAt
781
+ seo {
782
+ ...seo
783
+ }
784
+ }
785
+ ${seoFragment}
786
+ `
787
+ );
788
+ var pageWithMetafieldsFragment = (
789
+ /* GraphQL */
790
+ `
791
+ fragment pageWithMetafields on Page {
792
+ id
793
+ handle
794
+ title
795
+ body
796
+ bodySummary
797
+ createdAt
798
+ updatedAt
799
+ seo {
800
+ ...seo
801
+ }
802
+ metafields(identifiers: $pageMetafieldIdentifiers) {
803
+ ...metafield
804
+ }
805
+ }
806
+ ${seoFragment}
807
+ ${metafieldFragment}
808
+ `
809
+ );
810
+
811
+ // src/fragments/shop.ts
812
+ var shopFragment = (
813
+ /* GraphQL */
814
+ `
815
+ fragment shop on Shop {
816
+ name
817
+ description
818
+ primaryDomain {
819
+ url
820
+ host
821
+ }
822
+ brand {
823
+ logo {
824
+ image {
825
+ url
826
+ }
827
+ }
828
+ colors {
829
+ primary {
830
+ background
831
+ }
832
+ secondary {
833
+ background
834
+ }
835
+ }
836
+ }
837
+ }
838
+ `
839
+ );
840
+ var shopWithMetafieldsFragment = (
841
+ /* GraphQL */
842
+ `
843
+ fragment shopWithMetafields on Shop {
844
+ name
845
+ description
846
+ primaryDomain {
847
+ url
848
+ host
849
+ }
850
+ brand {
851
+ logo {
852
+ image {
853
+ url
854
+ }
855
+ }
856
+ colors {
857
+ primary {
858
+ background
859
+ }
860
+ secondary {
861
+ background
862
+ }
863
+ }
864
+ }
865
+ metafields(identifiers: $shopMetafieldIdentifiers) {
866
+ ...metafield
867
+ }
868
+ }
869
+ ${metafieldFragment}
870
+ `
871
+ );
872
+
769
873
  // src/queries/product/get-product.ts
770
874
  var getProductQuery = (
771
875
  /* GraphQL */
@@ -927,6 +1031,59 @@ var getCartQuery = (
927
1031
  `
928
1032
  );
929
1033
 
1034
+ // src/queries/collection/get-collections-by-handles.ts
1035
+ var getCollectionsByHandlesQuery = (handles) => (
1036
+ /* GraphQL */
1037
+ `
1038
+ ${collectionFragment}
1039
+ ${productFragment}
1040
+ ${variantFragment}
1041
+ ${metafieldFragment}
1042
+ ${imageFragment}
1043
+ ${seoFragment}
1044
+
1045
+ query GetCollectionsByHandles(
1046
+ $collectionMetafieldIdentifiers: [HasMetafieldsIdentifier!] = []
1047
+ $productMetafieldIdentifiers: [HasMetafieldsIdentifier!] = []
1048
+ $variantMetafieldIdentifiers: [HasMetafieldsIdentifier!] = []
1049
+ ) {
1050
+ ${handles.map(
1051
+ (handle, index) => (
1052
+ /* GraphQL */
1053
+ `
1054
+ collection_${index}: collection(handle: "${handle}") {
1055
+ ...collection
1056
+ metafields(identifiers: $collectionMetafieldIdentifiers) {
1057
+ ...metafield
1058
+ }
1059
+ products(first: 9) {
1060
+ edges {
1061
+ node {
1062
+ ...product
1063
+ metafields(identifiers: $productMetafieldIdentifiers) {
1064
+ ...metafield
1065
+ }
1066
+ variants(first: 10) {
1067
+ edges {
1068
+ node {
1069
+ ...variant
1070
+ metafields(identifiers: $variantMetafieldIdentifiers) {
1071
+ ...metafield
1072
+ }
1073
+ }
1074
+ }
1075
+ }
1076
+ }
1077
+ }
1078
+ }
1079
+ }
1080
+ `
1081
+ )
1082
+ ).join("\n")}
1083
+ }
1084
+ `
1085
+ );
1086
+
930
1087
  // src/mutations/cart/create-cart.ts
931
1088
  var createCartMutation = (
932
1089
  /* GraphQL */
@@ -1249,13 +1406,14 @@ var getProductQuery2 = (
1249
1406
  `
1250
1407
  );
1251
1408
  async function getProduct(client, options) {
1252
- const { handle, metafieldIdentifiers } = options;
1409
+ const { handle, graphqlQuery, metafieldIdentifiers } = options;
1410
+ const query = graphqlQuery || getProductQuery2;
1253
1411
  const variables = { handle };
1254
1412
  if (metafieldIdentifiers) {
1255
1413
  variables.productMetafieldIdentifiers = metafieldIdentifiers;
1256
1414
  variables.variantMetafieldIdentifiers = metafieldIdentifiers;
1257
1415
  }
1258
- const data = await client.query(getProductQuery2, variables);
1416
+ const data = await client.query(query, variables);
1259
1417
  if (!data?.product) {
1260
1418
  return void 0;
1261
1419
  }
@@ -1310,7 +1468,8 @@ var getAllProductsQuery = (
1310
1468
  `
1311
1469
  );
1312
1470
  async function fetchAllPages(client, options, afterCursor) {
1313
- const { first = 250, query, sortKey, reverse, metafieldIdentifiers } = options;
1471
+ const { first = 250, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
1472
+ const queryString = graphqlQuery || getAllProductsQuery;
1314
1473
  const variables = {
1315
1474
  first,
1316
1475
  after: afterCursor,
@@ -1322,7 +1481,7 @@ async function fetchAllPages(client, options, afterCursor) {
1322
1481
  variables.productMetafieldIdentifiers = metafieldIdentifiers;
1323
1482
  variables.variantMetafieldIdentifiers = metafieldIdentifiers;
1324
1483
  }
1325
- const data = await client.query(getAllProductsQuery, variables);
1484
+ const data = await client.query(queryString, variables);
1326
1485
  if (!data || !data.products) {
1327
1486
  return [];
1328
1487
  }
@@ -1337,7 +1496,8 @@ async function getAllProducts(client, options) {
1337
1496
  return fetchAllPages(client, options);
1338
1497
  }
1339
1498
  async function getProducts(client, options) {
1340
- const { first = 250, after, query, sortKey, reverse, metafieldIdentifiers } = options;
1499
+ const { first = 250, after, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
1500
+ const queryString = graphqlQuery || getAllProductsQuery;
1341
1501
  const variables = {
1342
1502
  first,
1343
1503
  after,
@@ -1349,7 +1509,7 @@ async function getProducts(client, options) {
1349
1509
  variables.productMetafieldIdentifiers = metafieldIdentifiers;
1350
1510
  variables.variantMetafieldIdentifiers = metafieldIdentifiers;
1351
1511
  }
1352
- const data = await client.query(getAllProductsQuery, variables);
1512
+ const data = await client.query(queryString, variables);
1353
1513
  if (!data || !data.products) {
1354
1514
  return {
1355
1515
  products: [],
@@ -1399,11 +1559,11 @@ function buildProductsByHandlesQuery(handles) {
1399
1559
  );
1400
1560
  }
1401
1561
  async function getProductsByHandles(client, options) {
1402
- const { handles, metafieldIdentifiers } = options;
1562
+ const { handles, graphqlQuery, metafieldIdentifiers } = options;
1403
1563
  if (!handles || handles.length === 0) {
1404
1564
  return [];
1405
1565
  }
1406
- const query = buildProductsByHandlesQuery(handles);
1566
+ const query = graphqlQuery || buildProductsByHandlesQuery(handles);
1407
1567
  const data = await client.query(query, {
1408
1568
  handles,
1409
1569
  // 请勿删除,这个参数虽然没有在 query 中使用,但方便在 chrome dev tools 中查看请求参数
@@ -1415,7 +1575,12 @@ async function getProductsByHandles(client, options) {
1415
1575
  if (!data) {
1416
1576
  return [];
1417
1577
  }
1418
- return Object.keys(data).map((key) => normalizeProduct(data[key]));
1578
+ return Object.values(data).map((item) => {
1579
+ if (item) {
1580
+ return normalizeProduct(item);
1581
+ }
1582
+ return void 0;
1583
+ });
1419
1584
  }
1420
1585
 
1421
1586
  // src/api/cart/normalize.ts
@@ -1519,7 +1684,8 @@ function normalizeCart(cart) {
1519
1684
 
1520
1685
  // src/api/cart/get-cart.ts
1521
1686
  async function getCart(client, options) {
1522
- const { id, cookieAdapter, metafieldIdentifiers } = options;
1687
+ const { id, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
1688
+ const query = graphqlQuery || getCartQuery;
1523
1689
  const locale = client.getLocale();
1524
1690
  const cartId = id || cookieAdapter?.getCartId(locale);
1525
1691
  console.log("cartId", cartId);
@@ -1527,7 +1693,7 @@ async function getCart(client, options) {
1527
1693
  return void 0;
1528
1694
  }
1529
1695
  try {
1530
- const data = await client.query(getCartQuery, {
1696
+ const data = await client.query(query, {
1531
1697
  cartId,
1532
1698
  ...constructMetafieldIdentifiersQueryParams(
1533
1699
  metafieldIdentifiers,
@@ -1562,12 +1728,14 @@ async function createCart(client, options = {}) {
1562
1728
  buyerIdentity,
1563
1729
  discountCodes,
1564
1730
  customAttributes,
1731
+ graphqlQuery,
1565
1732
  metafieldIdentifiers,
1566
1733
  updateCookie = false
1567
1734
  } = options;
1735
+ const query = graphqlQuery || createCartMutation;
1568
1736
  const locale = client.getLocale();
1569
1737
  try {
1570
- const data = await client.query(createCartMutation, {
1738
+ const data = await client.query(query, {
1571
1739
  lines,
1572
1740
  buyerIdentity,
1573
1741
  discountCodes,
@@ -1597,7 +1765,8 @@ async function createCart(client, options = {}) {
1597
1765
 
1598
1766
  // src/api/cart/add-cart-lines.ts
1599
1767
  async function addCartLines(client, options) {
1600
- const { cartId: providedCartId, lines, cookieAdapter, metafieldIdentifiers } = options;
1768
+ const { cartId: providedCartId, lines, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
1769
+ const query = graphqlQuery || addCartItemsMutation;
1601
1770
  const locale = client.getLocale();
1602
1771
  const cartId = providedCartId || cookieAdapter?.getCartId(locale);
1603
1772
  if (!cartId) {
@@ -1608,7 +1777,7 @@ async function addCartLines(client, options) {
1608
1777
  client.getConfig().getMetafieldNamespacePrefix()
1609
1778
  );
1610
1779
  try {
1611
- const data = await client.query(addCartItemsMutation, {
1780
+ const data = await client.query(query, {
1612
1781
  cartId,
1613
1782
  lines,
1614
1783
  ...normalizedMetafieldIdentifiers
@@ -1633,7 +1802,8 @@ async function addCartLines(client, options) {
1633
1802
 
1634
1803
  // src/api/cart/update-cart-lines.ts
1635
1804
  async function updateCartLines(client, options) {
1636
- const { cartId: providedCartId, lines, cookieAdapter, metafieldIdentifiers } = options;
1805
+ const { cartId: providedCartId, lines, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
1806
+ const query = graphqlQuery || updateCartItemsMutation;
1637
1807
  const locale = client.getLocale();
1638
1808
  const cartId = providedCartId || cookieAdapter?.getCartId(locale);
1639
1809
  if (!cartId) {
@@ -1646,7 +1816,7 @@ async function updateCartLines(client, options) {
1646
1816
  console.log("update-cart-lines metafieldIdentifiers:", metafieldIdentifiers);
1647
1817
  console.log("update-cart-lines metafieldParams:", metafieldParams);
1648
1818
  try {
1649
- const data = await client.query(updateCartItemsMutation, {
1819
+ const data = await client.query(query, {
1650
1820
  cartId,
1651
1821
  lines,
1652
1822
  ...metafieldParams
@@ -1680,14 +1850,15 @@ async function updateCartLines(client, options) {
1680
1850
 
1681
1851
  // src/api/cart/remove-cart-lines.ts
1682
1852
  async function removeCartLines(client, options) {
1683
- const { cartId: providedCartId, lineIds, cookieAdapter, metafieldIdentifiers } = options;
1853
+ const { cartId: providedCartId, lineIds, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
1854
+ const query = graphqlQuery || removeCartItemsMutation;
1684
1855
  const locale = client.getLocale();
1685
1856
  const cartId = providedCartId || cookieAdapter?.getCartId(locale);
1686
1857
  if (!cartId) {
1687
1858
  throw new Error("Invalid input used for this operation: Miss cartId");
1688
1859
  }
1689
1860
  try {
1690
- const data = await client.query(removeCartItemsMutation, {
1861
+ const data = await client.query(query, {
1691
1862
  cartId,
1692
1863
  lineIds,
1693
1864
  ...constructMetafieldIdentifiersQueryParams(
@@ -1714,14 +1885,15 @@ async function removeCartLines(client, options) {
1714
1885
 
1715
1886
  // src/api/cart/update-cart-codes.ts
1716
1887
  async function updateCartCodes(client, options) {
1717
- const { cartId: providedCartId, discountCodes, cookieAdapter, metafieldIdentifiers } = options;
1888
+ const { cartId: providedCartId, discountCodes, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
1889
+ const query = graphqlQuery || updateCartDiscountCodeMutation;
1718
1890
  const locale = client.getLocale();
1719
1891
  const cartId = providedCartId || cookieAdapter?.getCartId(locale);
1720
1892
  if (!cartId) {
1721
1893
  throw new Error("Invalid input used for this operation: Miss cartId");
1722
1894
  }
1723
1895
  try {
1724
- const data = await client.query(updateCartDiscountCodeMutation, {
1896
+ const data = await client.query(query, {
1725
1897
  cartId,
1726
1898
  discountCodes,
1727
1899
  ...constructMetafieldIdentifiersQueryParams(
@@ -1745,14 +1917,15 @@ async function updateCartCodes(client, options) {
1745
1917
 
1746
1918
  // src/api/cart/update-cart-attributes.ts
1747
1919
  async function updateCartAttributes(client, options) {
1748
- const { cartId: providedCartId, attributes, cookieAdapter, metafieldIdentifiers } = options;
1920
+ const { cartId: providedCartId, attributes, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
1921
+ const query = graphqlQuery || updateCartAttributesMutation;
1749
1922
  const locale = client.getLocale();
1750
1923
  const cartId = providedCartId || cookieAdapter?.getCartId(locale);
1751
1924
  if (!cartId) {
1752
1925
  throw new Error("Invalid input used for this operation: Miss cartId");
1753
1926
  }
1754
1927
  try {
1755
- const data = await client.query(updateCartAttributesMutation, {
1928
+ const data = await client.query(query, {
1756
1929
  cartId,
1757
1930
  attributes,
1758
1931
  ...constructMetafieldIdentifiersQueryParams(
@@ -1779,14 +1952,15 @@ async function updateCartAttributes(client, options) {
1779
1952
 
1780
1953
  // src/api/cart/update-cart-delivery-options.ts
1781
1954
  async function updateCartDeliveryOptions(client, options) {
1782
- const { cartId: providedCartId, selectedDeliveryOptions, cookieAdapter, metafieldIdentifiers } = options;
1955
+ const { cartId: providedCartId, selectedDeliveryOptions, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
1956
+ const query = graphqlQuery || updateCartDeliveryOptionsMutation;
1783
1957
  const locale = client.getLocale();
1784
1958
  const cartId = providedCartId || cookieAdapter?.getCartId(locale);
1785
1959
  if (!cartId) {
1786
1960
  throw new Error("Invalid input used for this operation: Miss cartId");
1787
1961
  }
1788
1962
  try {
1789
- const data = await client.query(updateCartDeliveryOptionsMutation, {
1963
+ const data = await client.query(query, {
1790
1964
  cartId,
1791
1965
  selectedDeliveryOptions,
1792
1966
  ...constructMetafieldIdentifiersQueryParams(
@@ -1813,14 +1987,15 @@ async function updateCartDeliveryOptions(client, options) {
1813
1987
 
1814
1988
  // src/api/cart/update-buyer-identity.ts
1815
1989
  async function updateBuyerIdentity(client, options) {
1816
- const { cartId: providedCartId, buyerIdentity, cookieAdapter, metafieldIdentifiers } = options;
1990
+ const { cartId: providedCartId, buyerIdentity, cookieAdapter, graphqlQuery, metafieldIdentifiers } = options;
1991
+ const query = graphqlQuery || updateBuyerIdentityMutation;
1817
1992
  const locale = client.getLocale();
1818
1993
  const cartId = providedCartId || cookieAdapter?.getCartId(locale);
1819
1994
  if (!cartId) {
1820
1995
  throw new Error("Invalid input used for this operation: Miss cartId");
1821
1996
  }
1822
1997
  try {
1823
- const data = await client.query(updateBuyerIdentityMutation, {
1998
+ const data = await client.query(query, {
1824
1999
  cartId,
1825
2000
  buyerIdentity,
1826
2001
  ...constructMetafieldIdentifiersQueryParams(
@@ -1891,12 +2066,13 @@ var getCollectionQuery = (
1891
2066
  `
1892
2067
  );
1893
2068
  async function getCollection(client, options) {
1894
- const { handle, metafieldIdentifiers } = options;
2069
+ const { handle, graphqlQuery, metafieldIdentifiers } = options;
2070
+ const query = graphqlQuery || getCollectionQuery;
1895
2071
  const variables = { handle };
1896
2072
  if (metafieldIdentifiers) {
1897
2073
  variables.metafieldIdentifiers = metafieldIdentifiers;
1898
2074
  }
1899
- const data = await client.query(getCollectionQuery, variables);
2075
+ const data = await client.query(query, variables);
1900
2076
  if (!data?.collection) {
1901
2077
  return void 0;
1902
2078
  }
@@ -1939,7 +2115,8 @@ var getAllCollectionsQuery = (
1939
2115
  `
1940
2116
  );
1941
2117
  async function fetchAllPages2(client, options, afterCursor) {
1942
- const { first = 250, query, sortKey, reverse, metafieldIdentifiers } = options;
2118
+ const { first = 250, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
2119
+ const queryString = graphqlQuery || getAllCollectionsQuery;
1943
2120
  const variables = {
1944
2121
  first,
1945
2122
  after: afterCursor,
@@ -1950,7 +2127,7 @@ async function fetchAllPages2(client, options, afterCursor) {
1950
2127
  if (metafieldIdentifiers) {
1951
2128
  variables.metafieldIdentifiers = metafieldIdentifiers;
1952
2129
  }
1953
- const data = await client.query(getAllCollectionsQuery, variables);
2130
+ const data = await client.query(queryString, variables);
1954
2131
  if (!data || !data.collections) {
1955
2132
  return [];
1956
2133
  }
@@ -1965,7 +2142,8 @@ async function getAllCollections(client, options) {
1965
2142
  return fetchAllPages2(client, options);
1966
2143
  }
1967
2144
  async function getCollections(client, options) {
1968
- const { first = 250, after, query, sortKey, reverse, metafieldIdentifiers } = options;
2145
+ const { first = 250, after, query, graphqlQuery, sortKey, reverse, metafieldIdentifiers } = options;
2146
+ const queryString = graphqlQuery || getAllCollectionsQuery;
1969
2147
  const variables = {
1970
2148
  first,
1971
2149
  after,
@@ -1976,7 +2154,7 @@ async function getCollections(client, options) {
1976
2154
  if (metafieldIdentifiers) {
1977
2155
  variables.metafieldIdentifiers = metafieldIdentifiers;
1978
2156
  }
1979
- const data = await client.query(getAllCollectionsQuery, variables);
2157
+ const data = await client.query(queryString, variables);
1980
2158
  if (!data || !data.collections) {
1981
2159
  return {
1982
2160
  collections: [],
@@ -1993,6 +2171,33 @@ async function getCollections(client, options) {
1993
2171
  };
1994
2172
  }
1995
2173
 
2174
+ // src/api/collection/get-collections-by-handles.ts
2175
+ async function getCollectionsByHandles(client, options) {
2176
+ const { handles, graphqlQuery, metafieldIdentifiers } = options;
2177
+ if (handles.length === 0) {
2178
+ return [];
2179
+ }
2180
+ const query = graphqlQuery || getCollectionsByHandlesQuery(handles);
2181
+ const data = await client.query(query, {
2182
+ handles,
2183
+ // 请勿删除,这个参数虽然没有在 query 中使用,但方便在 chrome dev tools 中查看请求参数
2184
+ ...constructMetafieldIdentifiersQueryParams(
2185
+ metafieldIdentifiers,
2186
+ client.getConfig().getMetafieldNamespacePrefix()
2187
+ )
2188
+ });
2189
+ if (!data) {
2190
+ return [];
2191
+ }
2192
+ const collections = Object.values(data).map((item) => {
2193
+ if (!item) {
2194
+ return void 0;
2195
+ }
2196
+ return normalizeCollection(item);
2197
+ });
2198
+ return collections;
2199
+ }
2200
+
1996
2201
  // src/api/blog/normalize.ts
1997
2202
  function normalizeBlog(blog) {
1998
2203
  return {
@@ -2037,16 +2242,16 @@ function normalizeMetafields2(metafields) {
2037
2242
 
2038
2243
  // src/api/blog/get-blog.ts
2039
2244
  async function getBlog(client, options) {
2040
- const { handle, metafieldIdentifiers } = options;
2245
+ const { handle, graphqlQuery, metafieldIdentifiers } = options;
2041
2246
  const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2042
2247
  const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
2043
- const query = (
2248
+ const defaultQuery = (
2044
2249
  /* GraphQL */
2045
2250
  `
2046
2251
  query getBlog(
2047
2252
  $handle: String!
2048
2253
  ${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2049
- ) @inContext(language: $language) {
2254
+ ) {
2050
2255
  blog(handle: $handle) {
2051
2256
  ...${hasMetafields ? "blogWithMetafields" : "blog"}
2052
2257
  }
@@ -2054,6 +2259,7 @@ async function getBlog(client, options) {
2054
2259
  ${fragment}
2055
2260
  `
2056
2261
  );
2262
+ const query = graphqlQuery || defaultQuery;
2057
2263
  const variables = { handle };
2058
2264
  if (hasMetafields) {
2059
2265
  variables.blogMetafieldIdentifiers = metafieldIdentifiers;
@@ -2067,10 +2273,10 @@ async function getBlog(client, options) {
2067
2273
 
2068
2274
  // src/api/blog/get-all-blogs.ts
2069
2275
  async function fetchAllPages3(client, options, afterCursor) {
2070
- const { first = 250, query, metafieldIdentifiers } = options;
2276
+ const { first = 250, query, graphqlQuery, metafieldIdentifiers } = options;
2071
2277
  const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2072
2278
  const fragment = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
2073
- const queryString = (
2279
+ const defaultQueryString = (
2074
2280
  /* GraphQL */
2075
2281
  `
2076
2282
  query getAllBlogs(
@@ -2078,7 +2284,7 @@ async function fetchAllPages3(client, options, afterCursor) {
2078
2284
  $after: String
2079
2285
  ${query ? "$query: String!" : ""}
2080
2286
  ${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2081
- ) @inContext(language: $language) {
2287
+ ) {
2082
2288
  blogs(
2083
2289
  first: $first
2084
2290
  after: $after
@@ -2098,6 +2304,7 @@ async function fetchAllPages3(client, options, afterCursor) {
2098
2304
  ${pageInfoFragment}
2099
2305
  `
2100
2306
  );
2307
+ const queryString = graphqlQuery || defaultQueryString;
2101
2308
  const variables = { first, after: afterCursor };
2102
2309
  if (query) {
2103
2310
  variables.query = query;
@@ -2122,11 +2329,11 @@ async function getAllBlogs(client, options) {
2122
2329
 
2123
2330
  // src/api/blog/get-article.ts
2124
2331
  async function getArticle(client, options) {
2125
- const { blogHandle, articleHandle, metafieldIdentifiers } = options;
2332
+ const { blogHandle, articleHandle, graphqlQuery, metafieldIdentifiers } = options;
2126
2333
  const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2127
2334
  const articleFrag = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
2128
2335
  const blogFrag = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
2129
- const query = (
2336
+ const defaultQuery = (
2130
2337
  /* GraphQL */
2131
2338
  `
2132
2339
  query getArticle(
@@ -2134,7 +2341,7 @@ async function getArticle(client, options) {
2134
2341
  $articleHandle: String!
2135
2342
  ${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2136
2343
  ${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2137
- ) @inContext(language: $language) {
2344
+ ) {
2138
2345
  blog(handle: $blogHandle) {
2139
2346
  ...${hasMetafields ? "blogWithMetafields" : "blog"}
2140
2347
  articleByHandle(handle: $articleHandle) {
@@ -2149,6 +2356,7 @@ async function getArticle(client, options) {
2149
2356
  ${blogFrag}
2150
2357
  `
2151
2358
  );
2359
+ const query = graphqlQuery || defaultQuery;
2152
2360
  const variables = { blogHandle, articleHandle };
2153
2361
  if (hasMetafields) {
2154
2362
  variables.blogMetafieldIdentifiers = metafieldIdentifiers;
@@ -2163,10 +2371,17 @@ async function getArticle(client, options) {
2163
2371
 
2164
2372
  // src/api/blog/get-articles.ts
2165
2373
  async function fetchAllPages4(client, options, afterCursor) {
2166
- const { first = 250, query, sortKey = "PUBLISHED_AT", reverse = false, metafieldIdentifiers } = options;
2374
+ const {
2375
+ first = 250,
2376
+ query,
2377
+ graphqlQuery,
2378
+ sortKey = "PUBLISHED_AT",
2379
+ reverse = false,
2380
+ metafieldIdentifiers
2381
+ } = options;
2167
2382
  const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2168
2383
  const fragment = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
2169
- const queryString = (
2384
+ const defaultQueryString = (
2170
2385
  /* GraphQL */
2171
2386
  `
2172
2387
  query getArticles(
@@ -2176,7 +2391,7 @@ async function fetchAllPages4(client, options, afterCursor) {
2176
2391
  $sortKey: ArticleSortKeys!
2177
2392
  $reverse: Boolean!
2178
2393
  ${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2179
- ) @inContext(language: $language) {
2394
+ ) {
2180
2395
  articles(
2181
2396
  first: $first
2182
2397
  after: $after
@@ -2198,6 +2413,7 @@ async function fetchAllPages4(client, options, afterCursor) {
2198
2413
  ${pageInfoFragment}
2199
2414
  `
2200
2415
  );
2416
+ const queryString = graphqlQuery || defaultQueryString;
2201
2417
  const variables = {
2202
2418
  first,
2203
2419
  after: afterCursor,
@@ -2227,11 +2443,18 @@ async function getArticles(client, options) {
2227
2443
 
2228
2444
  // src/api/blog/get-articles-in-blog.ts
2229
2445
  async function fetchAllPages5(client, options, afterCursor) {
2230
- const { blogHandle, first = 250, sortKey = "PUBLISHED_AT", reverse = false, metafieldIdentifiers } = options;
2446
+ const {
2447
+ blogHandle,
2448
+ first = 250,
2449
+ graphqlQuery,
2450
+ sortKey = "PUBLISHED_AT",
2451
+ reverse = false,
2452
+ metafieldIdentifiers
2453
+ } = options;
2231
2454
  const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2232
2455
  const articleFrag = hasMetafields ? articleWithMetafieldsFragment : articleFragment;
2233
2456
  const blogFrag = hasMetafields ? blogWithMetafieldsFragment : blogFragment;
2234
- const query = (
2457
+ const defaultQuery = (
2235
2458
  /* GraphQL */
2236
2459
  `
2237
2460
  query getArticlesInBlog(
@@ -2242,7 +2465,7 @@ async function fetchAllPages5(client, options, afterCursor) {
2242
2465
  $reverse: Boolean!
2243
2466
  ${hasMetafields ? "$blogMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2244
2467
  ${hasMetafields ? "$articleMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2245
- ) @inContext(language: $language) {
2468
+ ) {
2246
2469
  blog(handle: $blogHandle) {
2247
2470
  ...${hasMetafields ? "blogWithMetafields" : "blog"}
2248
2471
  articles(
@@ -2267,6 +2490,7 @@ async function fetchAllPages5(client, options, afterCursor) {
2267
2490
  ${pageInfoFragment}
2268
2491
  `
2269
2492
  );
2493
+ const query = graphqlQuery || defaultQuery;
2270
2494
  const variables = {
2271
2495
  blogHandle,
2272
2496
  first,
@@ -2293,6 +2517,121 @@ async function getArticlesInBlog(client, options) {
2293
2517
  return fetchAllPages5(client, options);
2294
2518
  }
2295
2519
 
2296
- 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, 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 };
2520
+ // src/api/page/normalize.ts
2521
+ function normalizePage(page) {
2522
+ return {
2523
+ id: page.id,
2524
+ handle: page.handle,
2525
+ title: page.title,
2526
+ body: page.body,
2527
+ bodySummary: page.bodySummary,
2528
+ createdAt: page.createdAt,
2529
+ updatedAt: page.updatedAt,
2530
+ seo: page.seo,
2531
+ metafields: normalizeMetafields3(page.metafields)
2532
+ };
2533
+ }
2534
+ function normalizeMetafields3(metafields) {
2535
+ if (!metafields || metafields.length === 0) {
2536
+ return void 0;
2537
+ }
2538
+ return metafields.reduce((acc, metafield) => {
2539
+ if (metafield && metafield.key) {
2540
+ acc[metafield.key] = metafield.value;
2541
+ }
2542
+ return acc;
2543
+ }, {});
2544
+ }
2545
+
2546
+ // src/api/page/get-page.ts
2547
+ async function getPage(client, options) {
2548
+ const { handle, graphqlQuery, metafieldIdentifiers } = options;
2549
+ const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2550
+ const fragment = hasMetafields ? pageWithMetafieldsFragment : pageFragment;
2551
+ const defaultQuery = (
2552
+ /* GraphQL */
2553
+ `
2554
+ query getPage(
2555
+ $handle: String!
2556
+ ${hasMetafields ? "$pageMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2557
+ ) {
2558
+ page(handle: $handle) {
2559
+ ...${hasMetafields ? "pageWithMetafields" : "page"}
2560
+ }
2561
+ }
2562
+ ${fragment}
2563
+ `
2564
+ );
2565
+ const query = graphqlQuery || defaultQuery;
2566
+ const variables = { handle };
2567
+ if (hasMetafields) {
2568
+ variables.pageMetafieldIdentifiers = metafieldIdentifiers;
2569
+ }
2570
+ const data = await client.query(query, variables);
2571
+ if (!data || !data.page) {
2572
+ return void 0;
2573
+ }
2574
+ return normalizePage(data.page);
2575
+ }
2576
+
2577
+ // src/api/shop/normalize.ts
2578
+ function normalizeShop(shop) {
2579
+ return {
2580
+ name: shop.name,
2581
+ description: shop.description,
2582
+ primaryDomain: shop.primaryDomain,
2583
+ brand: shop.brand ? {
2584
+ logo: shop.brand.logo,
2585
+ colors: shop.brand.colors ? {
2586
+ primary: shop.brand.colors.primary?.background,
2587
+ secondary: shop.brand.colors.secondary?.background
2588
+ } : void 0
2589
+ } : void 0,
2590
+ metafields: normalizeMetafields4(shop.metafields)
2591
+ };
2592
+ }
2593
+ function normalizeMetafields4(metafields) {
2594
+ if (!metafields || metafields.length === 0) {
2595
+ return void 0;
2596
+ }
2597
+ return metafields.reduce((acc, metafield) => {
2598
+ if (metafield && metafield.key) {
2599
+ acc[metafield.key] = metafield.value;
2600
+ }
2601
+ return acc;
2602
+ }, {});
2603
+ }
2604
+
2605
+ // src/api/shop/get-shop.ts
2606
+ async function getShop(client, options) {
2607
+ const { graphqlQuery, metafieldIdentifiers } = options;
2608
+ const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2609
+ const fragment = hasMetafields ? shopWithMetafieldsFragment : shopFragment;
2610
+ const defaultQuery = (
2611
+ /* GraphQL */
2612
+ `
2613
+ query getShop(
2614
+ ${hasMetafields ? "$shopMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2615
+ ) {
2616
+ shop {
2617
+ ...${hasMetafields ? "shopWithMetafields" : "shop"}
2618
+ }
2619
+ }
2620
+ ${fragment}
2621
+ `
2622
+ );
2623
+ const query = graphqlQuery || defaultQuery;
2624
+ const variables = {};
2625
+ if (hasMetafields) {
2626
+ variables.shopMetafieldIdentifiers = metafieldIdentifiers;
2627
+ }
2628
+ const data = await client.query(query, variables);
2629
+ if (!data || !data.shop) {
2630
+ return void 0;
2631
+ }
2632
+ return normalizeShop(data.shop);
2633
+ }
2634
+
2635
+ 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 };
2297
2636
  //# sourceMappingURL=index.mjs.map
2298
2637
  //# sourceMappingURL=index.mjs.map