@artisan-commerce/analytics-web 0.2.0-canary.63 → 0.2.0-canary.65

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.
@@ -41,7 +41,7 @@
41
41
 
42
42
  var name = "@artisan-commerce/analytics-web";
43
43
  var description = "Artisn commerce analytics web library";
44
- var version = "0.2.0-canary.62";
44
+ var version = "0.2.0-canary.64";
45
45
  var main = "./dist/bundle.cjs.js";
46
46
  var module = "./dist/bundle.esm.js";
47
47
  var types = "./dist/bundle.d.ts";
@@ -82,9 +82,9 @@
82
82
  "snake-case": "^3.0.4"
83
83
  };
84
84
  var devDependencies = {
85
- "@artisan-commerce/products": "0.9.0-canary.40",
86
- "@artisan-commerce/shopping-cart": "0.12.0-canary.59",
87
- "@artisan-commerce/types": "0.14.0-canary.31"
85
+ "@artisan-commerce/products": "0.9.0-canary.41",
86
+ "@artisan-commerce/shopping-cart": "0.12.0-canary.61",
87
+ "@artisan-commerce/types": "0.14.0-canary.32"
88
88
  };
89
89
  var peerDependencies = {
90
90
  "@artisan-commerce/products": "*",
@@ -588,7 +588,7 @@ ${key}: ${value}`;
588
588
  setInitialState();
589
589
  const { initialized } = getState$1();
590
590
  if (initialized) {
591
- logMessage("initAnalytics has been called more than once. This behaviour will very likely result in unexpected outcomes so its call was skipped. Please make sure initAnalytics is only called once.", "warn");
591
+ logMessage("initAnalytics has been called more than once. This behaviour will very likely result in unexpected outcomes so its call was skipped. Please make sure initAnalytics is only called once.", "debug");
592
592
  return;
593
593
  }
594
594
  const { providers, shareArtisnAnalytics } = config;
@@ -929,18 +929,19 @@ ${key}: ${value}`;
929
929
  }
930
930
  return a;
931
931
  };
932
- const { DEFAULT_SHOPPING_CART_NAME: DEFAULT_SHOPPING_CART_NAME$3, DEFAULT_MAX_SHOPPING_CARTS } = CONSTANTS;
932
+ const { DEFAULT_SHOPPING_CART_NAME: DEFAULT_SHOPPING_CART_NAME$2, DEFAULT_MAX_SHOPPING_CARTS } = CONSTANTS;
933
933
  const initialState = {
934
934
  artisnApp: void 0,
935
935
  accountId: void 0,
936
936
  customerId: void 0,
937
- activeShoppingCart: DEFAULT_SHOPPING_CART_NAME$3,
937
+ activeShoppingCart: DEFAULT_SHOPPING_CART_NAME$2,
938
938
  maxShoppingCarts: DEFAULT_MAX_SHOPPING_CARTS,
939
939
  wallets: {},
940
940
  anonymous: false,
941
941
  initialized: false,
942
942
  queue: new ActionQueue(),
943
- eventLoop: new EventLoop()
943
+ eventLoop: new EventLoop(),
944
+ debug: false
944
945
  };
945
946
  Object.freeze(initialState);
946
947
  let state = __spreadValues$k$1({}, initialState);
@@ -1651,13 +1652,16 @@ ${key}: ${value}`;
1651
1652
  }
1652
1653
  const benefitsValues = Object.values(benefits);
1653
1654
  return benefitsValues.reduce((acc, benefit) => {
1654
- if (benefit.type === "DISCOUNT") {
1655
- return applyBenefitByDiscount(benefit, acc, additionalInfo);
1655
+ if (benefit.type === "DISCOUNT_PERCENTAGE" && benefit.discountPercentage) {
1656
+ return applyBenefitByDiscountPercentage(benefit, acc, additionalInfo);
1657
+ }
1658
+ if (benefit.type === "DISCOUNT_FIXED" && benefit.discountFixed) {
1659
+ return applyBenefitByDiscountFixed(benefit, acc, additionalInfo);
1656
1660
  }
1657
1661
  return acc;
1658
1662
  }, shoppingCartTotals);
1659
1663
  };
1660
- const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) => {
1664
+ const applyBenefitByDiscountPercentage = (benefit, shoppingCartTotals, additionalInfo) => {
1661
1665
  const { subtotal, total: prevTotal } = shoppingCartTotals;
1662
1666
  const { totalDiscounts: prevTotalDiscounts } = shoppingCartTotals;
1663
1667
  const discountPercentage = benefit.discountPercentage * 0.01;
@@ -1680,6 +1684,26 @@ ${key}: ${value}`;
1680
1684
  total: newTotal
1681
1685
  });
1682
1686
  };
1687
+ const applyBenefitByDiscountFixed = (benefit, shoppingCartTotals, additionalInfo) => {
1688
+ const { total: prevTotal } = shoppingCartTotals;
1689
+ const { totalDiscounts: prevTotalDiscounts } = shoppingCartTotals;
1690
+ const discountFixed = Number(benefit.discountFixed);
1691
+ if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
1692
+ const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
1693
+ const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + discountFixed : discountFixed;
1694
+ const newTotal2 = (copayment - discountFixed).toFixed(4);
1695
+ return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1696
+ totalDiscounts: newTotalDiscounts2,
1697
+ total: Number(newTotal2)
1698
+ });
1699
+ }
1700
+ const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + discountFixed : discountFixed;
1701
+ const newTotal = prevTotal - discountFixed;
1702
+ return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1703
+ totalDiscounts: newTotalDiscounts,
1704
+ total: newTotal
1705
+ });
1706
+ };
1683
1707
 
1684
1708
  const isBaseProduct = (product) => {
1685
1709
  const { attributes, description, name } = product;