@anker-in/shopify-sdk 1.0.2 → 1.1.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/index.mjs CHANGED
@@ -429,6 +429,8 @@ var cartFragment = (
429
429
  }
430
430
  buyerIdentity {
431
431
  email
432
+ phone
433
+ countryCode
432
434
  customer {
433
435
  email
434
436
  id
@@ -438,8 +440,11 @@ var cartFragment = (
438
440
  address1
439
441
  address2
440
442
  city
443
+ province
441
444
  country
442
445
  zip
446
+ firstName
447
+ lastName
443
448
  }
444
449
  }
445
450
  }
@@ -1073,6 +1078,30 @@ var updateCartDeliveryOptionsMutation = (
1073
1078
  ${cartFragment}
1074
1079
  `
1075
1080
  );
1081
+
1082
+ // src/mutations/cart/update-buyer-identity.ts
1083
+ var updateBuyerIdentityMutation = (
1084
+ /* GraphQL */
1085
+ `
1086
+ mutation cartBuyerIdentityUpdate(
1087
+ $buyerIdentity: CartBuyerIdentityInput!
1088
+ $cartId: ID!
1089
+ $variantMetafieldIdentifiers: [HasMetafieldsIdentifier!] = []
1090
+ $productMetafieldIdentifiers: [HasMetafieldsIdentifier!] = []
1091
+ ) {
1092
+ cartBuyerIdentityUpdate(cartId: $cartId, buyerIdentity: $buyerIdentity) {
1093
+ cart {
1094
+ ...cart
1095
+ }
1096
+ userErrors {
1097
+ field
1098
+ message
1099
+ }
1100
+ }
1101
+ }
1102
+ ${cartFragment}
1103
+ `
1104
+ );
1076
1105
  var normalizeSellingPlan = ({ edges }) => {
1077
1106
  return edges?.map(({ node }) => node);
1078
1107
  };
@@ -1429,8 +1458,6 @@ function normalizeCart(cart) {
1429
1458
  id: cart.id,
1430
1459
  url: cart.checkoutUrl,
1431
1460
  ready: true,
1432
- customerId: cart?.buyerIdentity?.customer?.id || "",
1433
- email: cart?.buyerIdentity?.email || "",
1434
1461
  createdAt: cart.createdAt,
1435
1462
  currency: {
1436
1463
  code: cart.cost?.subtotalAmount?.currencyCode || "USD"
@@ -1456,7 +1483,9 @@ function normalizeCart(cart) {
1456
1483
  // Map delivery amount from cart cost
1457
1484
  deliveryAmount: cart?.deliveryGroups?.nodes?.[0]?.selectedDeliveryOption?.estimatedCost,
1458
1485
  // Map delivery groups from cart
1459
- deliveryGroups: cart?.deliveryGroups?.nodes?.map((group) => group)
1486
+ deliveryGroups: cart?.deliveryGroups?.nodes,
1487
+ // Map buyer identity
1488
+ buyerIdentity: cart?.buyerIdentity
1460
1489
  };
1461
1490
  }
1462
1491
 
@@ -1761,6 +1790,40 @@ async function updateCartDeliveryOptions(client, options) {
1761
1790
  }
1762
1791
  }
1763
1792
 
1793
+ // src/api/cart/update-buyer-identity.ts
1794
+ async function updateBuyerIdentity(client, options) {
1795
+ const { cartId: providedCartId, buyerIdentity, cookieAdapter, metafieldIdentifiers } = options;
1796
+ const locale = client.getLocale();
1797
+ const cartId = providedCartId || cookieAdapter?.getCartId(locale);
1798
+ if (!cartId) {
1799
+ throw new Error("Invalid input used for this operation: Miss cartId");
1800
+ }
1801
+ try {
1802
+ const data = await client.query(updateBuyerIdentityMutation, {
1803
+ cartId,
1804
+ buyerIdentity,
1805
+ ...constructMetafieldIdentifiersQueryParams(
1806
+ metafieldIdentifiers,
1807
+ client.getConfig().getMetafieldNamespacePrefix()
1808
+ )
1809
+ });
1810
+ if (data?.cartBuyerIdentityUpdate?.userErrors?.length) {
1811
+ console.error("[updateBuyerIdentity] User errors:", data.cartBuyerIdentityUpdate.userErrors);
1812
+ }
1813
+ if (!data?.cartBuyerIdentityUpdate?.cart) {
1814
+ return void 0;
1815
+ }
1816
+ const normalizedCart = normalizeCart(data.cartBuyerIdentityUpdate.cart);
1817
+ if (cookieAdapter && normalizedCart.id) {
1818
+ cookieAdapter.setCartId(locale, normalizedCart.id);
1819
+ }
1820
+ return normalizedCart;
1821
+ } catch (error) {
1822
+ console.error("[updateBuyerIdentity] Error:", error);
1823
+ throw error;
1824
+ }
1825
+ }
1826
+
1764
1827
  // src/api/collection/normalize.ts
1765
1828
  function normalizeCollection(collection) {
1766
1829
  const products = collection.products?.edges?.map((edge) => normalizeProduct(edge.node));
@@ -2209,6 +2272,6 @@ async function getArticlesInBlog(client, options) {
2209
2272
  return fetchAllPages5(client, options);
2210
2273
  }
2211
2274
 
2212
- 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, updateCartAttributes, updateCartAttributesMutation, updateCartCodes, updateCartDeliveryOptions, updateCartDeliveryOptionsMutation, updateCartDiscountCodeMutation, updateCartItemsMutation, updateCartLines, variantFragment };
2275
+ 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 };
2213
2276
  //# sourceMappingURL=index.mjs.map
2214
2277
  //# sourceMappingURL=index.mjs.map