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