@anker-in/shopify-react 1.2.2-beta.5 → 1.2.2-beta.7
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/hooks/index.d.mts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +39 -37
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +38 -36
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -37
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.d.mts +1 -1
- package/dist/provider/index.d.ts +1 -1
- package/dist/provider/index.js +14 -15
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +13 -14
- package/dist/provider/index.mjs.map +1 -1
- package/dist/{types-DnDvCDW-.d.mts → types-Bzg8_e4k.d.mts} +5 -1
- package/dist/{types-DnDvCDW-.d.ts → types-Bzg8_e4k.d.ts} +5 -1
- package/package.json +4 -4
package/dist/hooks/index.d.mts
CHANGED
|
@@ -2,8 +2,8 @@ import * as swr_mutation from 'swr/mutation';
|
|
|
2
2
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
3
3
|
import * as _anker_in_shopify_sdk from '@anker-in/shopify-sdk';
|
|
4
4
|
import { CartLineInput, NormalizedCart, NormalizedProduct, NormalizedProductVariant, NormalizedLineItem, UpdateCartLinesOptions, HasMetafieldsIdentifier, Media, NormalizedCollection, CollectionsConnection, NormalizedBlog, NormalizedArticle, NormalizedAttribute } from '@anker-in/shopify-sdk';
|
|
5
|
-
import { h as UseAddToCartOptions, g as AddToCartInput, A as AddToCartLineItem, G as GtmParams, C as BuyNowTrackConfig, e as UseScriptAutoFreeGiftResult, m as PlusMemberShippingMethodConfig, n as PlusMemberSettingsMetafields, D as DeliveryPlusType, o as SelectedPlusMemberVariant } from '../types-
|
|
6
|
-
export { p as DeliveryCustomData, P as PLUS_MEMBER_TYPE, j as PlusMemberMode, l as PlusMemberShippingMethodMetafields, S as ScriptAutoFreeGiftConfig, k as ShippingMethodMode, U as UseAutoRemoveFreeGiftsOptions, a as UseAutoRemoveFreeGiftsResult, d as isAnyGift, c as isBuyGetGift, i as isFunctionGift, b as isScriptGift, u as useAutoRemoveFreeGifts, f as useScriptAutoFreeGift } from '../types-
|
|
5
|
+
import { h as UseAddToCartOptions, g as AddToCartInput, A as AddToCartLineItem, G as GtmParams, C as BuyNowTrackConfig, e as UseScriptAutoFreeGiftResult, m as PlusMemberShippingMethodConfig, n as PlusMemberSettingsMetafields, D as DeliveryPlusType, o as SelectedPlusMemberVariant } from '../types-Bzg8_e4k.mjs';
|
|
6
|
+
export { p as DeliveryCustomData, P as PLUS_MEMBER_TYPE, j as PlusMemberMode, l as PlusMemberShippingMethodMetafields, S as ScriptAutoFreeGiftConfig, k as ShippingMethodMode, U as UseAutoRemoveFreeGiftsOptions, a as UseAutoRemoveFreeGiftsResult, d as isAnyGift, c as isBuyGetGift, i as isFunctionGift, b as isScriptGift, u as useAutoRemoveFreeGifts, f as useScriptAutoFreeGift } from '../types-Bzg8_e4k.mjs';
|
|
7
7
|
import * as swr from 'swr';
|
|
8
8
|
import swr__default, { SWRConfiguration } from 'swr';
|
|
9
9
|
import * as swr__internal from 'swr/_internal';
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import * as swr_mutation from 'swr/mutation';
|
|
|
2
2
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
3
3
|
import * as _anker_in_shopify_sdk from '@anker-in/shopify-sdk';
|
|
4
4
|
import { CartLineInput, NormalizedCart, NormalizedProduct, NormalizedProductVariant, NormalizedLineItem, UpdateCartLinesOptions, HasMetafieldsIdentifier, Media, NormalizedCollection, CollectionsConnection, NormalizedBlog, NormalizedArticle, NormalizedAttribute } from '@anker-in/shopify-sdk';
|
|
5
|
-
import { h as UseAddToCartOptions, g as AddToCartInput, A as AddToCartLineItem, G as GtmParams, C as BuyNowTrackConfig, e as UseScriptAutoFreeGiftResult, m as PlusMemberShippingMethodConfig, n as PlusMemberSettingsMetafields, D as DeliveryPlusType, o as SelectedPlusMemberVariant } from '../types-
|
|
6
|
-
export { p as DeliveryCustomData, P as PLUS_MEMBER_TYPE, j as PlusMemberMode, l as PlusMemberShippingMethodMetafields, S as ScriptAutoFreeGiftConfig, k as ShippingMethodMode, U as UseAutoRemoveFreeGiftsOptions, a as UseAutoRemoveFreeGiftsResult, d as isAnyGift, c as isBuyGetGift, i as isFunctionGift, b as isScriptGift, u as useAutoRemoveFreeGifts, f as useScriptAutoFreeGift } from '../types-
|
|
5
|
+
import { h as UseAddToCartOptions, g as AddToCartInput, A as AddToCartLineItem, G as GtmParams, C as BuyNowTrackConfig, e as UseScriptAutoFreeGiftResult, m as PlusMemberShippingMethodConfig, n as PlusMemberSettingsMetafields, D as DeliveryPlusType, o as SelectedPlusMemberVariant } from '../types-Bzg8_e4k.js';
|
|
6
|
+
export { p as DeliveryCustomData, P as PLUS_MEMBER_TYPE, j as PlusMemberMode, l as PlusMemberShippingMethodMetafields, S as ScriptAutoFreeGiftConfig, k as ShippingMethodMode, U as UseAutoRemoveFreeGiftsOptions, a as UseAutoRemoveFreeGiftsResult, d as isAnyGift, c as isBuyGetGift, i as isFunctionGift, b as isScriptGift, u as useAutoRemoveFreeGifts, f as useScriptAutoFreeGift } from '../types-Bzg8_e4k.js';
|
|
7
7
|
import * as swr from 'swr';
|
|
8
8
|
import swr__default, { SWRConfiguration } from 'swr';
|
|
9
9
|
import * as swr__internal from 'swr/_internal';
|
package/dist/hooks/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var useSWRMutation = require('swr/mutation');
|
|
|
5
5
|
var shopifySdk = require('@anker-in/shopify-sdk');
|
|
6
6
|
var Cookies5 = require('js-cookie');
|
|
7
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
-
var
|
|
8
|
+
var Decimal3 = require('decimal.js');
|
|
9
9
|
var shopifyCore = require('@anker-in/shopify-core');
|
|
10
10
|
var useSWR = require('swr');
|
|
11
11
|
var ahooks = require('ahooks');
|
|
@@ -14,7 +14,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
14
14
|
|
|
15
15
|
var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
|
|
16
16
|
var Cookies5__default = /*#__PURE__*/_interopDefault(Cookies5);
|
|
17
|
-
var
|
|
17
|
+
var Decimal3__default = /*#__PURE__*/_interopDefault(Decimal3);
|
|
18
18
|
var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
|
|
19
19
|
|
|
20
20
|
// src/hooks/cart/use-create-cart.ts
|
|
@@ -72,8 +72,6 @@ var CODE_AMOUNT_KEY = "_sku_code_money";
|
|
|
72
72
|
var SCRIPT_CODE_AMOUNT_KEY = "_code_money";
|
|
73
73
|
var MEMBER_PRICE_ATTRIBUTE_KEY = "_member_price";
|
|
74
74
|
var MAIN_PRODUCT_CODE = ["WS24", "WSTD", "WS7D", "WSCP", "WSPE", "WSPD"];
|
|
75
|
-
|
|
76
|
-
// src/hooks/cart/utils/normalize-add-to-cart-lines.ts
|
|
77
75
|
function normalizeAddToCartLines(lines) {
|
|
78
76
|
return lines.filter((line) => line.variant?.id).map((line, index) => {
|
|
79
77
|
const variant = line.variant;
|
|
@@ -81,8 +79,8 @@ function normalizeAddToCartLines(lines) {
|
|
|
81
79
|
const quantity = line.quantity || 1;
|
|
82
80
|
const originalPrice = variant.price?.amount ? Number(variant.price.amount) : 0;
|
|
83
81
|
const finalPrice = variant.finalPrice?.amount === void 0 ? originalPrice : Number(variant.finalPrice?.amount);
|
|
84
|
-
const subtotalAmount = originalPrice
|
|
85
|
-
const totalAmount = finalPrice
|
|
82
|
+
const subtotalAmount = new Decimal3__default.default(originalPrice).times(quantity).toNumber();
|
|
83
|
+
const totalAmount = new Decimal3__default.default(finalPrice).times(quantity).toNumber();
|
|
86
84
|
return {
|
|
87
85
|
id: `temp-line-${index}-${variant.id}`,
|
|
88
86
|
// Temporary ID for pre-cart lines
|
|
@@ -90,6 +88,7 @@ function normalizeAddToCartLines(lines) {
|
|
|
90
88
|
quantity,
|
|
91
89
|
variantId: variant.id,
|
|
92
90
|
productId: product?.id || variant.id.split("/").slice(0, -2).join("/"),
|
|
91
|
+
amountPerQuantity: finalPrice,
|
|
93
92
|
totalAmount,
|
|
94
93
|
subtotalAmount,
|
|
95
94
|
discountAllocations: [],
|
|
@@ -274,7 +273,7 @@ var formatScriptAutoFreeGift = ({
|
|
|
274
273
|
path: product?.handle || "",
|
|
275
274
|
variant,
|
|
276
275
|
totalAmount: 0,
|
|
277
|
-
subtotalAmount: new
|
|
276
|
+
subtotalAmount: new Decimal3__default.default(
|
|
278
277
|
typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
|
|
279
278
|
).toNumber(),
|
|
280
279
|
options: [],
|
|
@@ -334,7 +333,7 @@ var formatFunctionAutoFreeGift = ({
|
|
|
334
333
|
path: product?.handle || "",
|
|
335
334
|
variant,
|
|
336
335
|
totalAmount: 0,
|
|
337
|
-
subtotalAmount: new
|
|
336
|
+
subtotalAmount: new Decimal3__default.default(
|
|
338
337
|
typeof variant?.price === "object" ? variant?.price?.amount || 0 : variant?.price || 0
|
|
339
338
|
).toNumber(),
|
|
340
339
|
options: [],
|
|
@@ -564,7 +563,7 @@ var useScriptAutoFreeGift = ({
|
|
|
564
563
|
const breakpoints = react.useMemo(() => {
|
|
565
564
|
if (!isActivityAvailable) return [];
|
|
566
565
|
return (campaign?.breakpoints || []).map((item) => ({
|
|
567
|
-
breakpoint: new
|
|
566
|
+
breakpoint: new Decimal3__default.default(item.breakpoint).minus(new Decimal3__default.default(upgrade_value)).dividedBy(new Decimal3__default.default(upgrade_multiple)).toFixed(2, Decimal3__default.default.ROUND_DOWN),
|
|
568
567
|
giveawayProducts: item.giveawayProducts || []
|
|
569
568
|
}));
|
|
570
569
|
}, [campaign, upgrade_multiple, upgrade_value]);
|
|
@@ -599,11 +598,11 @@ var useScriptAutoFreeGift = ({
|
|
|
599
598
|
});
|
|
600
599
|
}, [effectiveCart?.lineItems, isActivityAvailable, _giveaway]);
|
|
601
600
|
const involvedSubTotal = react.useMemo(() => {
|
|
602
|
-
if (!isActivityAvailable) return new
|
|
601
|
+
if (!isActivityAvailable) return new Decimal3__default.default(0);
|
|
603
602
|
return involvedLines.reduce((prev, item) => {
|
|
604
603
|
const amount = campaign?.useTotalAmount ? item.totalAmount : item.subtotalAmount;
|
|
605
|
-
return new
|
|
606
|
-
}, new
|
|
604
|
+
return new Decimal3__default.default(prev).plus(new Decimal3__default.default(amount || 0));
|
|
605
|
+
}, new Decimal3__default.default(0));
|
|
607
606
|
}, [involvedLines, isActivityAvailable]);
|
|
608
607
|
const [freeGiftLevel, nextFreeGiftLevel] = react.useMemo(() => {
|
|
609
608
|
if (!isActivityAvailable) return [null, null];
|
|
@@ -611,7 +610,7 @@ var useScriptAutoFreeGift = ({
|
|
|
611
610
|
(a, b) => Number(b.breakpoint) - Number(a.breakpoint)
|
|
612
611
|
);
|
|
613
612
|
const levelIndex = sortedLevels.findIndex(
|
|
614
|
-
(level) => involvedSubTotal.gte(new
|
|
613
|
+
(level) => involvedSubTotal.gte(new Decimal3__default.default(level.breakpoint)) && involvedLines.length > 0
|
|
615
614
|
);
|
|
616
615
|
if (levelIndex === -1) {
|
|
617
616
|
return [
|
|
@@ -782,7 +781,7 @@ var trackAddToCartGA = ({
|
|
|
782
781
|
return;
|
|
783
782
|
}
|
|
784
783
|
const currencyCode = lineItems[0].product?.price?.currencyCode;
|
|
785
|
-
const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.
|
|
784
|
+
const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.totalAmount || 0), new Decimal3__default.default(0)).toNumber();
|
|
786
785
|
gaTrack({
|
|
787
786
|
event: "ga4Event",
|
|
788
787
|
event_name: "add_to_cart",
|
|
@@ -816,36 +815,30 @@ var trackBuyNowGA = ({
|
|
|
816
815
|
lineItems = [],
|
|
817
816
|
gtmParams = {}
|
|
818
817
|
}) => {
|
|
819
|
-
if (!lineItems.length
|
|
818
|
+
if (!lineItems.length) {
|
|
820
819
|
return;
|
|
821
820
|
}
|
|
822
|
-
const
|
|
823
|
-
const
|
|
824
|
-
const totalPrice = lineItems?.reduce(
|
|
825
|
-
(prev, { variant: variant2 }) => prev.plus(
|
|
826
|
-
variant2?.finalPrice?.amount === void 0 ? Number(variant2?.price?.amount) || 0 : Number(variant2?.finalPrice?.amount) || 0
|
|
827
|
-
),
|
|
828
|
-
new Decimal2__default.default(0)
|
|
829
|
-
).toNumber();
|
|
821
|
+
const currencyCode = lineItems[0].product?.price?.currencyCode;
|
|
822
|
+
const totalPrice = lineItems.reduce((prev, item) => prev.plus(item.totalAmount || 0), new Decimal3__default.default(0)).toNumber();
|
|
830
823
|
gaTrack({
|
|
831
824
|
event: "ga4Event",
|
|
832
825
|
event_name: "begin_checkout",
|
|
833
826
|
event_parameters: {
|
|
834
827
|
page_group: gtmParams?.pageGroup,
|
|
835
|
-
position: gtmParams?.position,
|
|
828
|
+
position: gtmParams?.position || "",
|
|
836
829
|
currency: currencyCode,
|
|
837
830
|
value: totalPrice,
|
|
838
831
|
items: lineItems.map((item) => {
|
|
839
|
-
const imageUrl = item.variant
|
|
832
|
+
const imageUrl = item.variant.image?.url || item.product?.images?.[0]?.url;
|
|
840
833
|
const itemCategoryId = item.gtmParams?.item_category_id;
|
|
841
|
-
const itemVariantId = item.variant
|
|
834
|
+
const itemVariantId = item.variant.id ? shopifyCore.atobID(item.variant.id) : void 0;
|
|
842
835
|
return {
|
|
843
|
-
item_id: item.variant
|
|
844
|
-
item_name: item.
|
|
836
|
+
item_id: item.variant.sku,
|
|
837
|
+
item_name: item.product?.title,
|
|
845
838
|
item_brand: gtmParams?.brand || "",
|
|
846
|
-
item_category: item.
|
|
847
|
-
item_variant: item.variant
|
|
848
|
-
price: item.variant
|
|
839
|
+
item_category: item.product?.productType || "",
|
|
840
|
+
item_variant: item.variant.name,
|
|
841
|
+
price: item.variant.listPrice ?? item.variant.price,
|
|
849
842
|
quantity: item.quantity || 1,
|
|
850
843
|
...imageUrl && { image_url: imageUrl },
|
|
851
844
|
...itemCategoryId !== void 0 && { item_category_id: itemCategoryId },
|
|
@@ -1044,7 +1037,7 @@ var initDiscountAttributes = ({ line }) => {
|
|
|
1044
1037
|
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
1045
1038
|
value: JSON.stringify({
|
|
1046
1039
|
is_gift: false,
|
|
1047
|
-
discounted_amount: new
|
|
1040
|
+
discounted_amount: new Decimal3__default.default(priceAmount).times(line.quantity || 1).toNumber()
|
|
1048
1041
|
})
|
|
1049
1042
|
}
|
|
1050
1043
|
]);
|
|
@@ -1068,11 +1061,11 @@ var initDiscountAttributes = ({ line }) => {
|
|
|
1068
1061
|
itemAttributes = itemAttributes.concat([
|
|
1069
1062
|
{
|
|
1070
1063
|
key: CODE_AMOUNT_KEY,
|
|
1071
|
-
value: new
|
|
1064
|
+
value: new Decimal3__default.default(coupon.amount).times(line.quantity || 1).toString()
|
|
1072
1065
|
},
|
|
1073
1066
|
{
|
|
1074
1067
|
key: SCRIPT_CODE_AMOUNT_KEY,
|
|
1075
|
-
value: new
|
|
1068
|
+
value: new Decimal3__default.default(coupon.amount).times(line.quantity || 1).toString()
|
|
1076
1069
|
}
|
|
1077
1070
|
]);
|
|
1078
1071
|
}
|
|
@@ -1530,8 +1523,8 @@ function getCartBasicAttributes({
|
|
|
1530
1523
|
{
|
|
1531
1524
|
key: "_weight",
|
|
1532
1525
|
value: cart?.lineItems?.reduce((acc, item) => {
|
|
1533
|
-
const itemWeight = new
|
|
1534
|
-
return new
|
|
1526
|
+
const itemWeight = new Decimal3__default.default(item.variant.weight ?? 0).times(item.quantity);
|
|
1527
|
+
return new Decimal3__default.default(acc).plus(itemWeight).toNumber();
|
|
1535
1528
|
}, 0).toString()
|
|
1536
1529
|
}
|
|
1537
1530
|
];
|
|
@@ -2556,7 +2549,16 @@ function useBuyNow({ withTrack = true } = {}, swrOptions) {
|
|
|
2556
2549
|
}
|
|
2557
2550
|
if (withTrack && resultCart.lineItems) {
|
|
2558
2551
|
trackBuyNowGA({
|
|
2559
|
-
lineItems
|
|
2552
|
+
lineItems: lineItems.map((item) => {
|
|
2553
|
+
const cartLine = resultCart.lineItems.find((line) => line.variant.id === item.variant?.id);
|
|
2554
|
+
if (!cartLine) {
|
|
2555
|
+
return null;
|
|
2556
|
+
}
|
|
2557
|
+
return {
|
|
2558
|
+
...cartLine,
|
|
2559
|
+
quantity: item.quantity
|
|
2560
|
+
};
|
|
2561
|
+
}).filter(Boolean),
|
|
2560
2562
|
gtmParams: { ...gtmParams, brand: config.getBrand() }
|
|
2561
2563
|
});
|
|
2562
2564
|
if (fbqTrackConfig) {
|