@artisan-commerce/analytics-rn 0.3.0-canary.57 → 0.3.0-canary.58

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/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.3.0-canary.58](https://bitbucket.org/tradesystem/artisn_sdk/compare/@artisan-commerce/analytics-rn@0.3.0-canary.57...@artisan-commerce/analytics-rn@0.3.0-canary.58) (2021-12-16)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **artisn:** fix ShoppingCartTotals ([412b147](https://bitbucket.org/tradesystem/artisn_sdk/commit/412b147e7e402aef26eb24c4ca7d987e7be9473b))
12
+
13
+
14
+
6
15
  ## [0.3.0-canary.57](https://bitbucket.org/tradesystem/artisn_sdk/compare/@artisan-commerce/analytics-rn@0.3.0-canary.56...@artisan-commerce/analytics-rn@0.3.0-canary.57) (2021-12-15)
7
16
 
8
17
  **Note:** Version bump only for package @artisan-commerce/analytics-rn
@@ -49,7 +49,7 @@ const getState$1 = () => {
49
49
 
50
50
  var name = "@artisan-commerce/analytics-rn";
51
51
  var description = "Artisn commerce analytics react native library";
52
- var version = "0.3.0-canary.57";
52
+ var version = "0.3.0-canary.58";
53
53
  var main = "./dist/bundle.esm.js";
54
54
  var module$1 = "./dist/bundle.esm.js";
55
55
  var types = "./dist/bundle.d.ts";
@@ -91,8 +91,8 @@ var dependencies = {
91
91
  "snake-case": "^3.0.4"
92
92
  };
93
93
  var devDependencies = {
94
- "@artisan-commerce/products": "0.9.0-canary.36",
95
- "@artisan-commerce/shopping-cart": "0.12.0-canary.53",
94
+ "@artisan-commerce/products": "0.9.0-canary.37",
95
+ "@artisan-commerce/shopping-cart": "0.12.0-canary.54",
96
96
  "@artisan-commerce/types": "0.14.0-canary.28",
97
97
  "@babel/core": "^7.13.15",
98
98
  "@babel/preset-env": "^7.10.4",
@@ -112,7 +112,7 @@ var peerDependencies = {
112
112
  react: ">=16.8.6",
113
113
  "react-native-fbsdk-next": "*"
114
114
  };
115
- var gitHead = "41494d0ea43f17af10489d8ef47f4d4ad014a951";
115
+ var gitHead = "0427e4882a041437b9020e86646d0dff83dbda9e";
116
116
  var packageJSON = {
117
117
  name: name,
118
118
  description: description,
@@ -1336,6 +1336,9 @@ const getProductTotalTaxes$1 = (product, setAmount) => {
1336
1336
  const { taxes, grossPrice } = prices[priceCategory];
1337
1337
  const taxTotal = getTaxTotal$1(taxes, grossPrice);
1338
1338
  const questionsSum = getModifiersTotalTaxes$1(cartProduct, setAmount);
1339
+ if (taxTotal === null || questionsSum === null) {
1340
+ return null;
1341
+ }
1339
1342
  return questionsSum + taxTotal * amount;
1340
1343
  };
1341
1344
  const getModifiersTotalTaxes$1 = (product, setAmount) => {
@@ -1346,7 +1349,7 @@ const getModifiersTotalTaxes$1 = (product, setAmount) => {
1346
1349
  const { taxes, grossPrice } = prices[priceCategory];
1347
1350
  const taxTotal = getTaxTotal$1(taxes, grossPrice);
1348
1351
  const childrenTotal = getModifiersTotalTaxes$1(answer, setAmount);
1349
- return acc2 + amount * (taxTotal + childrenTotal);
1352
+ return acc2 + amount * (Number(taxTotal) + childrenTotal);
1350
1353
  }, 0);
1351
1354
  return acc + answersSum * setAmount;
1352
1355
  }, 0)) != null ? _b : 0;
@@ -1355,7 +1358,7 @@ const getProductGrossPrice$1 = (product, setAmount) => {
1355
1358
  return getProductFieldPrice$1(product, "grossPrice", setAmount);
1356
1359
  };
1357
1360
  const getProductTotalDiscounts$1 = (product, setAmount) => {
1358
- return 0;
1361
+ return null;
1359
1362
  };
1360
1363
  const getProductNetPrice$1 = (product, setAmount) => {
1361
1364
  return getProductFieldPrice$1(product, "netPrice", setAmount);
@@ -1380,6 +1383,9 @@ const getModifiersFieldTotal$1 = (product, field) => {
1380
1383
  }, 0)) != null ? _b : 0;
1381
1384
  };
1382
1385
  const getTaxTotal$1 = (taxes, grossPrice) => {
1386
+ if (!taxes.length) {
1387
+ return null;
1388
+ }
1383
1389
  return taxes.reduce((acc, tax) => {
1384
1390
  return acc + tax.percentage / 100 * grossPrice;
1385
1391
  }, 0);
@@ -1407,12 +1413,15 @@ const { toCartProduct: toCartProduct$4 } = transformers_utils;
1407
1413
  const getShoppingCartTotal = (shoppingCart, config = {}) => {
1408
1414
  const initialValue = {
1409
1415
  subtotal: 0,
1410
- totalDiscounts: 0,
1411
- totalTaxes: 0,
1412
- totalPoints: 0,
1416
+ totalDiscounts: null,
1417
+ shippingCost: null,
1418
+ totalTaxes: null,
1419
+ totalPoints: null,
1413
1420
  total: 0
1414
1421
  };
1415
1422
  const products = getShoppingCartProducts(shoppingCart);
1423
+ if (!products.length)
1424
+ return initialValue;
1416
1425
  const totals = products.reduce((acc, product) => {
1417
1426
  const cartProduct = toCartProduct$4(product);
1418
1427
  const { priceCategory } = cartProduct;
@@ -1423,9 +1432,10 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
1423
1432
  const subtotalNormal = !isPoints ? productTotal.grossPrice : 0;
1424
1433
  return {
1425
1434
  subtotal: acc.subtotal + subtotalNormal,
1426
- totalDiscounts: acc.totalDiscounts + productTotal.totalDiscounts,
1427
- totalTaxes: acc.totalTaxes + productTotal.totalTaxes,
1428
- totalPoints: acc.totalPoints + points,
1435
+ totalDiscounts: productTotal.totalDiscounts !== null ? Number(acc.totalDiscounts) + productTotal.totalDiscounts : null,
1436
+ totalTaxes: productTotal.totalTaxes !== null ? Number(acc.totalTaxes) + productTotal.totalTaxes : null,
1437
+ shippingCost: null,
1438
+ totalPoints: points !== null ? Number(acc.totalPoints) + points : null,
1429
1439
  total: acc.total + normal
1430
1440
  };
1431
1441
  }, initialValue);
@@ -1437,8 +1447,8 @@ const getShoppingCartTotal = (shoppingCart, config = {}) => {
1437
1447
  const { grossPrice, netPrice, taxTotal, discountTotal } = shippingCost;
1438
1448
  const totalsWithShippingCost = {
1439
1449
  subtotal: totalsWithBenefits.subtotal + grossPrice,
1440
- totalDiscounts: totalsWithBenefits.totalDiscounts + discountTotal,
1441
- totalTaxes: totalsWithBenefits.totalTaxes + taxTotal,
1450
+ totalDiscounts: totalsWithBenefits.totalDiscounts !== null ? totalsWithBenefits.totalDiscounts + discountTotal : discountTotal,
1451
+ totalTaxes: totalsWithBenefits.totalTaxes !== null ? totalsWithBenefits.totalTaxes + taxTotal : taxTotal,
1442
1452
  shippingCost: netPrice,
1443
1453
  totalPoints: totalsWithBenefits.totalPoints,
1444
1454
  total: totalsWithBenefits.total + netPrice
@@ -1478,7 +1488,7 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
1478
1488
  if (typeof (additionalInfo == null ? void 0 : additionalInfo.copayment) !== "undefined") {
1479
1489
  const copayment = additionalInfo == null ? void 0 : additionalInfo.copayment;
1480
1490
  const totalDiscount2 = copayment * discountPercentage;
1481
- const newTotalDiscounts2 = prevTotalDiscounts + totalDiscount2;
1491
+ const newTotalDiscounts2 = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount2 : totalDiscount2;
1482
1492
  const newTotal2 = (copayment - totalDiscount2).toFixed(4);
1483
1493
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1484
1494
  totalDiscounts: newTotalDiscounts2,
@@ -1487,7 +1497,7 @@ const applyBenefitByDiscount = (benefit, shoppingCartTotals, additionalInfo) =>
1487
1497
  }
1488
1498
  const newSubtotal = subtotal * discountPercentage;
1489
1499
  const totalDiscount = newSubtotal;
1490
- const newTotalDiscounts = prevTotalDiscounts + totalDiscount;
1500
+ const newTotalDiscounts = prevTotalDiscounts !== null ? prevTotalDiscounts + totalDiscount : totalDiscount;
1491
1501
  const newTotal = prevTotal - totalDiscount;
1492
1502
  return __spreadProps$c$1(__spreadValues$g$1({}, shoppingCartTotals), {
1493
1503
  totalDiscounts: newTotalDiscounts,
@@ -1677,6 +1687,9 @@ const getProductTotalTaxes = (product, setAmount) => {
1677
1687
  const { taxes, grossPrice } = prices[priceCategory];
1678
1688
  const taxTotal = getTaxTotal(taxes, grossPrice);
1679
1689
  const questionsSum = getModifiersTotalTaxes(cartProduct, setAmount);
1690
+ if (taxTotal === null || questionsSum === null) {
1691
+ return null;
1692
+ }
1680
1693
  return questionsSum + taxTotal * amount;
1681
1694
  };
1682
1695
  const getModifiersTotalTaxes = (product, setAmount) => {
@@ -1687,7 +1700,7 @@ const getModifiersTotalTaxes = (product, setAmount) => {
1687
1700
  const { taxes, grossPrice } = prices[priceCategory];
1688
1701
  const taxTotal = getTaxTotal(taxes, grossPrice);
1689
1702
  const childrenTotal = getModifiersTotalTaxes(answer, setAmount);
1690
- return acc2 + amount * (taxTotal + childrenTotal);
1703
+ return acc2 + amount * (Number(taxTotal) + childrenTotal);
1691
1704
  }, 0);
1692
1705
  return acc + answersSum * setAmount;
1693
1706
  }, 0)) != null ? _b : 0;
@@ -1696,7 +1709,7 @@ const getProductGrossPrice = (product, setAmount) => {
1696
1709
  return getProductFieldPrice(product, "grossPrice", setAmount);
1697
1710
  };
1698
1711
  const getProductTotalDiscounts = (product, setAmount) => {
1699
- return 0;
1712
+ return null;
1700
1713
  };
1701
1714
  const getProductNetPrice = (product, setAmount) => {
1702
1715
  return getProductFieldPrice(product, "netPrice", setAmount);
@@ -1721,6 +1734,9 @@ const getModifiersFieldTotal = (product, field) => {
1721
1734
  }, 0)) != null ? _b : 0;
1722
1735
  };
1723
1736
  const getTaxTotal = (taxes, grossPrice) => {
1737
+ if (!taxes.length) {
1738
+ return null;
1739
+ }
1724
1740
  return taxes.reduce((acc, tax) => {
1725
1741
  return acc + tax.percentage / 100 * grossPrice;
1726
1742
  }, 0);
@@ -4164,7 +4180,7 @@ const initiateCheckout$2 = (provider, params) => {
4164
4180
  analytics__default$1["default"]().logEvent("begin_checkout", __spreadValues$33(__spreadValues$33({
4165
4181
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
4166
4182
  value: total,
4167
- points: totalPoints
4183
+ points: totalPoints != null ? totalPoints : 0
4168
4184
  }, transformedParams), transformedMeta));
4169
4185
  };
4170
4186
 
@@ -4214,11 +4230,11 @@ const initiateCheckout$1 = (provider, params) => {
4214
4230
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
4215
4231
  analytics__default["default"].track("Initiate Checkout", __spreadValues$32(__spreadValues$32({
4216
4232
  total,
4217
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
4218
- shipping: shippingCost,
4219
- tax: totalTaxes,
4233
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
4234
+ shipping: shippingCost != null ? shippingCost : 0,
4235
+ tax: totalTaxes != null ? totalTaxes : 0,
4220
4236
  products: mapProductsToSegmentProducts(products),
4221
- points: totalPoints
4237
+ points: totalPoints != null ? totalPoints : 0
4222
4238
  }, transformedParams), transformedMeta));
4223
4239
  };
4224
4240
 
@@ -4268,7 +4284,7 @@ const initiateCheckout = (provider, params) => {
4268
4284
  fb_num_items: productsIds.length,
4269
4285
  fb_currency: selectedCurrency,
4270
4286
  fb_content_type: contentType,
4271
- points: totalPoints
4287
+ points: totalPoints != null ? totalPoints : 0
4272
4288
  }, transformedParams), transformedMeta));
4273
4289
  };
4274
4290
 
@@ -9831,7 +9847,7 @@ const purchaseAttempt$2 = (provider, params) => {
9831
9847
  analytics__default$1["default"]().logEvent("purchase_attempt", __spreadValues$18(__spreadValues$18({
9832
9848
  products: transformArrayParam(productContents),
9833
9849
  value: total,
9834
- points: totalPoints
9850
+ points: totalPoints != null ? totalPoints : 0
9835
9851
  }, transformedParams), transformedMeta));
9836
9852
  };
9837
9853
 
@@ -9881,11 +9897,11 @@ const purchaseAttempt$1 = (provider, params) => {
9881
9897
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
9882
9898
  analytics__default["default"].track("Purchase Attempt", __spreadValues$17(__spreadValues$17({
9883
9899
  total,
9884
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
9885
- shipping: shippingCost,
9886
- tax: totalTaxes,
9900
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
9901
+ shipping: shippingCost != null ? shippingCost : 0,
9902
+ tax: totalTaxes != null ? totalTaxes : 0,
9887
9903
  products: mapProductsToSegmentProducts(products),
9888
- points: totalPoints
9904
+ points: totalPoints != null ? totalPoints : 0
9889
9905
  }, transformedParams), transformedMeta));
9890
9906
  };
9891
9907
 
@@ -9935,7 +9951,7 @@ const purchaseAttempt = (provider, params) => {
9935
9951
  fb_num_items: productsIds.length,
9936
9952
  fb_content_type: contentType,
9937
9953
  fb_currency: selectedCurrency,
9938
- points: totalPoints
9954
+ points: totalPoints != null ? totalPoints : 0
9939
9955
  }, transformedParams), transformedMeta));
9940
9956
  };
9941
9957
 
@@ -9996,7 +10012,7 @@ const purchaseFail$2 = (provider, params) => {
9996
10012
  analytics__default$1["default"]().logEvent("purchase_fail", __spreadValues$15(__spreadValues$15({
9997
10013
  products: transformArrayParam(productContents),
9998
10014
  value: total,
9999
- points: totalPoints
10015
+ points: totalPoints != null ? totalPoints : 0
10000
10016
  }, transformedParams), transformedMeta));
10001
10017
  };
10002
10018
 
@@ -10046,11 +10062,11 @@ const purchaseFail$1 = (provider, params) => {
10046
10062
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10047
10063
  analytics__default["default"].track("Purchase Fail", __spreadValues$14(__spreadValues$14({
10048
10064
  total,
10049
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10050
- shipping: shippingCost,
10051
- tax: totalTaxes,
10065
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10066
+ shipping: shippingCost != null ? shippingCost : 0,
10067
+ tax: totalTaxes != null ? totalTaxes : 0,
10052
10068
  products: mapProductsToSegmentProducts(products),
10053
- points: totalPoints
10069
+ points: totalPoints != null ? totalPoints : 0
10054
10070
  }, transformedParams), transformedMeta));
10055
10071
  };
10056
10072
 
@@ -10100,7 +10116,7 @@ const purchaseFail = (provider, params) => {
10100
10116
  fb_num_items: productsIds.length,
10101
10117
  fb_content_type: contentType,
10102
10118
  fb_currency: selectedCurrency,
10103
- points: totalPoints
10119
+ points: totalPoints != null ? totalPoints : 0
10104
10120
  }, transformedParams), transformedMeta));
10105
10121
  };
10106
10122
 
@@ -10160,10 +10176,10 @@ const purchaseSuccess$2 = (provider, params) => {
10160
10176
  analytics__default$1["default"]().logEvent("purchase", __spreadValues$12(__spreadValues$12({
10161
10177
  items: mapProductsToGoogleItems(shoppingCart, selectedCurrency),
10162
10178
  value: total,
10163
- points: totalPoints,
10179
+ points: totalPoints != null ? totalPoints : 0,
10164
10180
  transaction_id: orderId,
10165
- shipping: shippingCost,
10166
- tax: totalTaxes
10181
+ shipping: shippingCost != null ? shippingCost : 0,
10182
+ tax: totalTaxes != null ? totalTaxes : 0
10167
10183
  }, transformedParams), transformedMeta));
10168
10184
  };
10169
10185
 
@@ -10213,11 +10229,11 @@ const purchaseSuccess$1 = (provider, params) => {
10213
10229
  const { total, totalTaxes, shippingCost, totalPoints } = getShoppingCartTotal(shoppingCart);
10214
10230
  analytics__default["default"].track("Order Completed", __spreadValues$11(__spreadValues$11({
10215
10231
  total,
10216
- revenue: total - totalTaxes - (shippingCost != null ? shippingCost : 0),
10217
- shipping: shippingCost,
10218
- tax: totalTaxes,
10232
+ revenue: total - (totalTaxes != null ? totalTaxes : 0) - (shippingCost != null ? shippingCost : 0),
10233
+ shipping: shippingCost != null ? shippingCost : 0,
10234
+ tax: totalTaxes != null ? totalTaxes : 0,
10219
10235
  products: mapProductsToSegmentProducts(products),
10220
- points: totalPoints
10236
+ points: totalPoints != null ? totalPoints : 0
10221
10237
  }, transformedParams), transformedMeta));
10222
10238
  };
10223
10239
 
@@ -10267,7 +10283,7 @@ const purchaseSuccess = (provider, params) => {
10267
10283
  fb_contents: transformArrayParam(productContents),
10268
10284
  fb_num_items: productsIds.length,
10269
10285
  fb_content_type: contentType,
10270
- points: totalPoints
10286
+ points: totalPoints != null ? totalPoints : 0
10271
10287
  }, transformedParams), transformedMeta));
10272
10288
  };
10273
10289