@anker-in/shopify-sdk 1.1.0 → 1.1.1
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/index.js +42 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,17 +2,39 @@ 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
|
-
|
|
5
|
+
var SPECIAL_METAFIELD_NAMESPACES = ["__discountCodeApp", "discounts_function"];
|
|
6
|
+
function constructMetafieldIdentifiersQueryParams(metafieldIdentifiers, metafieldNamespacePrefix) {
|
|
7
|
+
if (!metafieldIdentifiers || Object.keys(metafieldIdentifiers).length === 0) {
|
|
8
|
+
return {
|
|
9
|
+
productMetafieldIdentifiers: [],
|
|
10
|
+
variantMetafieldIdentifiers: []
|
|
11
|
+
};
|
|
12
|
+
}
|
|
6
13
|
const identifiers = Object.entries(metafieldIdentifiers).reduce(
|
|
7
14
|
(queryInput, [key, value]) => {
|
|
8
15
|
const metafieldIdentifiers2 = value;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
const mappedIdentifiers = metafieldIdentifiers2.map((item) => {
|
|
17
|
+
if (SPECIAL_METAFIELD_NAMESPACES.includes(item.namespace)) {
|
|
18
|
+
return {
|
|
19
|
+
namespace: item.namespace,
|
|
20
|
+
key: item.key
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
namespace: `${metafieldNamespacePrefix}combo`,
|
|
25
|
+
key: item.namespace
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
const uniqueIdentifiers = mappedIdentifiers.filter(
|
|
29
|
+
(item, index, self) => index === self.findIndex((t) => t.namespace === item.namespace && t.key === item.key)
|
|
30
|
+
);
|
|
31
|
+
queryInput[`${key}MetafieldIdentifiers`] = uniqueIdentifiers;
|
|
13
32
|
return queryInput;
|
|
14
33
|
},
|
|
15
|
-
{
|
|
34
|
+
{
|
|
35
|
+
productMetafieldIdentifiers: [],
|
|
36
|
+
variantMetafieldIdentifiers: []
|
|
37
|
+
}
|
|
16
38
|
);
|
|
17
39
|
return identifiers;
|
|
18
40
|
}
|
|
@@ -34,13 +56,19 @@ var normalizeMetafields = (metafields) => {
|
|
|
34
56
|
return metafields?.reduce(
|
|
35
57
|
(prev, cur) => {
|
|
36
58
|
if (cur) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
59
|
+
if (SPECIAL_METAFIELD_NAMESPACES.includes(cur.namespace)) {
|
|
60
|
+
const namespace = cur.namespace;
|
|
61
|
+
prev[namespace] = prev[namespace] || {};
|
|
62
|
+
prev[namespace][cur.key] = parseMetafield(cur);
|
|
63
|
+
} else {
|
|
64
|
+
const namespace = cur.key;
|
|
65
|
+
prev[namespace] = prev[namespace] || {};
|
|
66
|
+
const parsedMetafields = parseMetafield(cur);
|
|
67
|
+
if (parsedMetafields) {
|
|
68
|
+
Object.entries(parsedMetafields).forEach(([key, innerMetafields]) => {
|
|
69
|
+
prev[namespace][key] = prev[namespace][key] ?? (innerMetafields ? parseMetafield(innerMetafields) : null);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
44
72
|
}
|
|
45
73
|
}
|
|
46
74
|
return prev;
|
|
@@ -1498,13 +1526,6 @@ async function getCart(client, options) {
|
|
|
1498
1526
|
if (!cartId) {
|
|
1499
1527
|
return void 0;
|
|
1500
1528
|
}
|
|
1501
|
-
console.log(
|
|
1502
|
-
"metafieldIdentifiers",
|
|
1503
|
-
constructMetafieldIdentifiersQueryParams(
|
|
1504
|
-
metafieldIdentifiers,
|
|
1505
|
-
client.getConfig().getMetafieldNamespacePrefix()
|
|
1506
|
-
)
|
|
1507
|
-
);
|
|
1508
1529
|
try {
|
|
1509
1530
|
const data = await client.query(getCartQuery, {
|
|
1510
1531
|
cartId,
|
|
@@ -1520,7 +1541,7 @@ async function getCart(client, options) {
|
|
|
1520
1541
|
return void 0;
|
|
1521
1542
|
}
|
|
1522
1543
|
const normalizedCart = normalizeCart(data.cart);
|
|
1523
|
-
if (cookieAdapter && normalizedCart.id) {
|
|
1544
|
+
if (cookieAdapter && normalizedCart.id && !id) {
|
|
1524
1545
|
cookieAdapter.setCartId(locale, normalizedCart.id);
|
|
1525
1546
|
}
|
|
1526
1547
|
return normalizedCart;
|