@anker-in/shopify-sdk 1.0.2 → 1.1.0-beta.2
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 +1 -1
- package/dist/fragments/index.d.ts +1 -1
- package/dist/fragments/index.js +5 -0
- package/dist/fragments/index.js.map +1 -1
- package/dist/fragments/index.mjs +5 -0
- package/dist/fragments/index.mjs.map +1 -1
- package/dist/index.d.mts +55 -6
- package/dist/index.d.ts +55 -6
- package/dist/index.js +87 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -17
- package/dist/index.mjs.map +1 -1
- package/dist/mutations/index.d.mts +10 -8
- package/dist/mutations/index.d.ts +10 -8
- package/dist/mutations/index.js +30 -0
- package/dist/mutations/index.js.map +1 -1
- package/dist/mutations/index.mjs +30 -1
- package/dist/mutations/index.mjs.map +1 -1
- package/dist/queries/index.d.mts +1 -1
- package/dist/queries/index.d.ts +1 -1
- package/dist/queries/index.js +5 -0
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +5 -0
- package/dist/queries/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,17 +2,30 @@ import { SOLD_OUT_PRICE } from '@anker-in/shopify-core';
|
|
|
2
2
|
export * from '@anker-in/shopify-core';
|
|
3
3
|
|
|
4
4
|
// src/utils.ts
|
|
5
|
-
function constructMetafieldIdentifiersQueryParams(metafieldIdentifiers
|
|
5
|
+
function constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, metafieldNamespacePrefix) {
|
|
6
|
+
if (!metafieldIdentifiers || Object.keys(metafieldIdentifiers).length === 0) {
|
|
7
|
+
return {
|
|
8
|
+
productMetafieldIdentifiers: [],
|
|
9
|
+
variantMetafieldIdentifiers: []
|
|
10
|
+
};
|
|
11
|
+
}
|
|
6
12
|
const identifiers = Object.entries(metafieldIdentifiers).reduce(
|
|
7
13
|
(queryInput, [key, value]) => {
|
|
8
14
|
const metafieldIdentifiers2 = value;
|
|
9
|
-
|
|
10
|
-
namespace:
|
|
11
|
-
key: item.
|
|
15
|
+
const mappedIdentifiers = metafieldIdentifiers2.map((item) => ({
|
|
16
|
+
namespace: `${metafieldNamespacePrefix}combo`,
|
|
17
|
+
key: item.namespace
|
|
12
18
|
}));
|
|
19
|
+
const uniqueIdentifiers = mappedIdentifiers.filter(
|
|
20
|
+
(item, index, self) => index === self.findIndex((t) => t.namespace === item.namespace && t.key === item.key)
|
|
21
|
+
);
|
|
22
|
+
queryInput[`${key}MetafieldIdentifiers`] = uniqueIdentifiers;
|
|
13
23
|
return queryInput;
|
|
14
24
|
},
|
|
15
|
-
{
|
|
25
|
+
{
|
|
26
|
+
productMetafieldIdentifiers: [],
|
|
27
|
+
variantMetafieldIdentifiers: []
|
|
28
|
+
}
|
|
16
29
|
);
|
|
17
30
|
return identifiers;
|
|
18
31
|
}
|
|
@@ -429,6 +442,8 @@ var cartFragment = (
|
|
|
429
442
|
}
|
|
430
443
|
buyerIdentity {
|
|
431
444
|
email
|
|
445
|
+
phone
|
|
446
|
+
countryCode
|
|
432
447
|
customer {
|
|
433
448
|
email
|
|
434
449
|
id
|
|
@@ -438,8 +453,11 @@ var cartFragment = (
|
|
|
438
453
|
address1
|
|
439
454
|
address2
|
|
440
455
|
city
|
|
456
|
+
province
|
|
441
457
|
country
|
|
442
458
|
zip
|
|
459
|
+
firstName
|
|
460
|
+
lastName
|
|
443
461
|
}
|
|
444
462
|
}
|
|
445
463
|
}
|
|
@@ -1073,6 +1091,30 @@ var updateCartDeliveryOptionsMutation = (
|
|
|
1073
1091
|
${cartFragment}
|
|
1074
1092
|
`
|
|
1075
1093
|
);
|
|
1094
|
+
|
|
1095
|
+
// src/mutations/cart/update-buyer-identity.ts
|
|
1096
|
+
var updateBuyerIdentityMutation = (
|
|
1097
|
+
/* GraphQL */
|
|
1098
|
+
`
|
|
1099
|
+
mutation cartBuyerIdentityUpdate(
|
|
1100
|
+
$buyerIdentity: CartBuyerIdentityInput!
|
|
1101
|
+
$cartId: ID!
|
|
1102
|
+
$variantMetafieldIdentifiers: [HasMetafieldsIdentifier!] = []
|
|
1103
|
+
$productMetafieldIdentifiers: [HasMetafieldsIdentifier!] = []
|
|
1104
|
+
) {
|
|
1105
|
+
cartBuyerIdentityUpdate(cartId: $cartId, buyerIdentity: $buyerIdentity) {
|
|
1106
|
+
cart {
|
|
1107
|
+
...cart
|
|
1108
|
+
}
|
|
1109
|
+
userErrors {
|
|
1110
|
+
field
|
|
1111
|
+
message
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
${cartFragment}
|
|
1116
|
+
`
|
|
1117
|
+
);
|
|
1076
1118
|
var normalizeSellingPlan = ({ edges }) => {
|
|
1077
1119
|
return edges?.map(({ node }) => node);
|
|
1078
1120
|
};
|
|
@@ -1429,8 +1471,6 @@ function normalizeCart(cart) {
|
|
|
1429
1471
|
id: cart.id,
|
|
1430
1472
|
url: cart.checkoutUrl,
|
|
1431
1473
|
ready: true,
|
|
1432
|
-
customerId: cart?.buyerIdentity?.customer?.id || "",
|
|
1433
|
-
email: cart?.buyerIdentity?.email || "",
|
|
1434
1474
|
createdAt: cart.createdAt,
|
|
1435
1475
|
currency: {
|
|
1436
1476
|
code: cart.cost?.subtotalAmount?.currencyCode || "USD"
|
|
@@ -1456,7 +1496,9 @@ function normalizeCart(cart) {
|
|
|
1456
1496
|
// Map delivery amount from cart cost
|
|
1457
1497
|
deliveryAmount: cart?.deliveryGroups?.nodes?.[0]?.selectedDeliveryOption?.estimatedCost,
|
|
1458
1498
|
// Map delivery groups from cart
|
|
1459
|
-
deliveryGroups: cart?.deliveryGroups?.nodes
|
|
1499
|
+
deliveryGroups: cart?.deliveryGroups?.nodes,
|
|
1500
|
+
// Map buyer identity
|
|
1501
|
+
buyerIdentity: cart?.buyerIdentity
|
|
1460
1502
|
};
|
|
1461
1503
|
}
|
|
1462
1504
|
|
|
@@ -1469,13 +1511,6 @@ async function getCart(client, options) {
|
|
|
1469
1511
|
if (!cartId) {
|
|
1470
1512
|
return void 0;
|
|
1471
1513
|
}
|
|
1472
|
-
console.log(
|
|
1473
|
-
"metafieldIdentifiers",
|
|
1474
|
-
constructMetafieldIdentifiersQueryParams(
|
|
1475
|
-
metafieldIdentifiers,
|
|
1476
|
-
client.getConfig().getMetafieldNamespacePrefix()
|
|
1477
|
-
)
|
|
1478
|
-
);
|
|
1479
1514
|
try {
|
|
1480
1515
|
const data = await client.query(getCartQuery, {
|
|
1481
1516
|
cartId,
|
|
@@ -1491,7 +1526,7 @@ async function getCart(client, options) {
|
|
|
1491
1526
|
return void 0;
|
|
1492
1527
|
}
|
|
1493
1528
|
const normalizedCart = normalizeCart(data.cart);
|
|
1494
|
-
if (cookieAdapter && normalizedCart.id) {
|
|
1529
|
+
if (cookieAdapter && normalizedCart.id && !id) {
|
|
1495
1530
|
cookieAdapter.setCartId(locale, normalizedCart.id);
|
|
1496
1531
|
}
|
|
1497
1532
|
return normalizedCart;
|
|
@@ -1761,6 +1796,40 @@ async function updateCartDeliveryOptions(client, options) {
|
|
|
1761
1796
|
}
|
|
1762
1797
|
}
|
|
1763
1798
|
|
|
1799
|
+
// src/api/cart/update-buyer-identity.ts
|
|
1800
|
+
async function updateBuyerIdentity(client, options) {
|
|
1801
|
+
const { cartId: providedCartId, buyerIdentity, cookieAdapter, metafieldIdentifiers } = options;
|
|
1802
|
+
const locale = client.getLocale();
|
|
1803
|
+
const cartId = providedCartId || cookieAdapter?.getCartId(locale);
|
|
1804
|
+
if (!cartId) {
|
|
1805
|
+
throw new Error("Invalid input used for this operation: Miss cartId");
|
|
1806
|
+
}
|
|
1807
|
+
try {
|
|
1808
|
+
const data = await client.query(updateBuyerIdentityMutation, {
|
|
1809
|
+
cartId,
|
|
1810
|
+
buyerIdentity,
|
|
1811
|
+
...constructMetafieldIdentifiersQueryParams(
|
|
1812
|
+
metafieldIdentifiers,
|
|
1813
|
+
client.getConfig().getMetafieldNamespacePrefix()
|
|
1814
|
+
)
|
|
1815
|
+
});
|
|
1816
|
+
if (data?.cartBuyerIdentityUpdate?.userErrors?.length) {
|
|
1817
|
+
console.error("[updateBuyerIdentity] User errors:", data.cartBuyerIdentityUpdate.userErrors);
|
|
1818
|
+
}
|
|
1819
|
+
if (!data?.cartBuyerIdentityUpdate?.cart) {
|
|
1820
|
+
return void 0;
|
|
1821
|
+
}
|
|
1822
|
+
const normalizedCart = normalizeCart(data.cartBuyerIdentityUpdate.cart);
|
|
1823
|
+
if (cookieAdapter && normalizedCart.id) {
|
|
1824
|
+
cookieAdapter.setCartId(locale, normalizedCart.id);
|
|
1825
|
+
}
|
|
1826
|
+
return normalizedCart;
|
|
1827
|
+
} catch (error) {
|
|
1828
|
+
console.error("[updateBuyerIdentity] Error:", error);
|
|
1829
|
+
throw error;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1764
1833
|
// src/api/collection/normalize.ts
|
|
1765
1834
|
function normalizeCollection(collection) {
|
|
1766
1835
|
const products = collection.products?.edges?.map((edge) => normalizeProduct(edge.node));
|
|
@@ -2209,6 +2278,6 @@ async function getArticlesInBlog(client, options) {
|
|
|
2209
2278
|
return fetchAllPages5(client, options);
|
|
2210
2279
|
}
|
|
2211
2280
|
|
|
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 };
|
|
2281
|
+
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
2282
|
//# sourceMappingURL=index.mjs.map
|
|
2214
2283
|
//# sourceMappingURL=index.mjs.map
|