@tapcart/mobile-components 0.8.51 → 0.8.52

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cart.util.d.ts","sourceRoot":"","sources":["../../lib/cart.util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,6BAA6B,EAE7B,cAAc,EACf,MAAM,kBAAkB,CAAA;AAGzB,eAAO,MAAM,eAAe;cAKhB,MAAM;aACP,cAAc;;0BAEH;YAChB,gBAAgB,CAAC,EAAE;gBACjB,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;YACD,KAAK,EAAE;gBACL,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;YACD,cAAc,CAAC,EAAE;gBACf,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;SACF,EAAE;;;;;;;CAgCN,CAAA;AA2CD,eAAO,MAAM,oBAAoB,SAAU,MAAM,QAAQ,YAAY,YAMpE,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU,MAAM,QAAQ,YAAY,YAMlE,CAAA;AAoHD,MAAM,MAAM,cAAc,GAAG;IAC3B,yBAAyB,EAAE,sBAAsB,EAAE,CAAA;IACnD,gBAAgB,EAAE,6BAA6B,EAAE,CAAA;IACjD,cAAc,EAAE,OAAO,CAAA;IACvB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,gBAAgB,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,cAUrC,CAAA;AAED,eAAO,MAAM,qBAAqB,SAAU,YAAY,K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,oBAAoB,EAAE,MAAM,CAAA;IAC5B,gBAAgB,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,cAUrC,CAAA;AAED,eAAO,MAAM,qBAAqB,SAAU,YAAY,KAAG,cA8B1D,CAAA;AAGD,eAAO,MAAM,mBAAmB;eACnB,MAAM;;;;;aAEG,MAAM;eAAS,MAAM;;;;oBAIN,MAAM;0BAAgB,MAAM;;;eAElD,MAAM;;;;;gBAML,MAAM;cACR,MAAM;;cAEN,MAAM;;;0BAIM;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE;oBAC9C,MAAM;;;;YAsCzB,CAAA"}
@@ -45,9 +45,7 @@ const getOrderLevelDiscounts = (cart) => {
45
45
  name: `Discount - ${code}`,
46
46
  type: "ORDER_LEVEL",
47
47
  }))
48
- .filter((discount) => cart.discounts
49
- .map((d) => d.toUpperCase())
50
- .includes(discount.id.toUpperCase()));
48
+ .filter((discount) => { var _a, _b; return (_b = (_a = cart.discounts) === null || _a === void 0 ? void 0 : _a.map((d) => d)) === null || _b === void 0 ? void 0 : _b.includes(discount === null || discount === void 0 ? void 0 : discount.id); });
51
49
  };
52
50
  const getShippingDiscounts = (cart) => {
53
51
  var _a;
@@ -72,11 +70,14 @@ export const isLineItemDiscount = (code, cart) => {
72
70
  };
73
71
  const getAppliedGiftCards = (cart) => {
74
72
  var _a;
75
- return (_a = cart.appliedGiftCards) === null || _a === void 0 ? void 0 : _a.map((giftCard) => ({
76
- id: giftCard.id,
77
- amount: +giftCard.amountUsed.amount,
78
- name: `Gift Card - ${giftCard.lastCharacters}`,
79
- }));
73
+ return (_a = cart.appliedGiftCards) === null || _a === void 0 ? void 0 : _a.map((giftCard) => {
74
+ var _a;
75
+ return ({
76
+ id: giftCard === null || giftCard === void 0 ? void 0 : giftCard.id,
77
+ amount: +((_a = giftCard === null || giftCard === void 0 ? void 0 : giftCard.amountUsed) === null || _a === void 0 ? void 0 : _a.amount) || 0,
78
+ name: `Gift Card - ${giftCard === null || giftCard === void 0 ? void 0 : giftCard.lastCharacters}`,
79
+ });
80
+ });
80
81
  };
81
82
  const getSalesAmount = (cart) => {
82
83
  var _a;
@@ -93,8 +94,8 @@ const getSalesAmount = (cart) => {
93
94
  }, 0);
94
95
  };
95
96
  const getLineItemDiscounts = (cart) => {
96
- var _a, _b;
97
- const discountMap = (_a = cart.items) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => {
97
+ var _a;
98
+ const discountMap = ((cart === null || cart === void 0 ? void 0 : cart.items) || []).reduce((acc, item) => {
98
99
  var _a;
99
100
  (_a = item === null || item === void 0 ? void 0 : item.discounts) === null || _a === void 0 ? void 0 : _a.forEach((discount) => {
100
101
  const code = discount === null || discount === void 0 ? void 0 : discount.code;
@@ -113,7 +114,7 @@ const getLineItemDiscounts = (cart) => {
113
114
  }, {});
114
115
  if (!discountMap)
115
116
  return [];
116
- return (_b = Object.entries(discountMap)) === null || _b === void 0 ? void 0 : _b.map(([code, { amount, type, readOnly }]) => ({
117
+ return (_a = Object.entries(discountMap)) === null || _a === void 0 ? void 0 : _a.map(([code, { amount, type, readOnly }]) => ({
117
118
  id: code,
118
119
  name: `Discount - ${code}`,
119
120
  amount,
@@ -145,7 +145,7 @@ describe("cart-provider.util", () => {
145
145
  ], deliveryGroups: [] });
146
146
  const result = getCalculatedCartData(mockCart);
147
147
  // 100 (compare) - 10 (discount) - 20 (sale) - 5 (gift card) = 65
148
- expect(result.totalDiscountedPrice).toBe(125);
148
+ expect(result.totalDiscountedPrice).toBe(135);
149
149
  });
150
150
  it("should never return negative or NaN values for totalDiscountedPrice", () => {
151
151
  // Test case 1: Normal case with valid data
@@ -1 +1 @@
1
- {"version":3,"file":"variablesCart.util.d.ts","sourceRoot":"","sources":["../../lib/variablesCart.util.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,sBAAsB,EACtB,6BAA6B,EAO9B,MAAM,kBAAkB,CAAA;AA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AAS,YAOhB,CAAA;AAED,eAAO,MAAM,2BAA2B,SAAU,MAAM,QAAQ,SAAS,YAMxE,CAAA;AA0JD,MAAM,MAAM,uBAAuB,GAAG;IACpC,yBAAyB,EAAE,sBAAsB,EAAE,CAAA;IACnD,gBAAgB,EAAE,6BAA6B,EAAE,CAAA;IACjD,cAAc,EAAE,OAAO,CAAA;IACvB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,gBAAgB,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,iCAAiC,EAAE,uBAU/C,CAAA;AAED,eAAO,MAAM,8BAA8B,SACnC,SAAS,KACd,uBA8BF,CAAA"}
@@ -33,21 +33,21 @@ const getOrderLevelDiscounts = (cart) => {
33
33
  const discountMap = discountAllocations
34
34
  .filter((discount) => discount.targetType !== DiscountApplicationTargetType.ShippingLine)
35
35
  .reduce((acc, discount) => {
36
- var _a, _b, _c;
36
+ var _a, _b, _c, _d, _e, _f;
37
37
  // Handle both traditional format and new format with kind.manual.code
38
38
  let code = "unknown";
39
39
  if (discount.code) {
40
- code = discount.code.toUpperCase();
40
+ code = ((discount === null || discount === void 0 ? void 0 : discount.code) || "").toUpperCase();
41
41
  }
42
42
  else if ((_b = (_a = discount.kind) === null || _a === void 0 ? void 0 : _a.manual) === null || _b === void 0 ? void 0 : _b.code) {
43
- code = discount.kind.manual.code.toUpperCase();
43
+ code = (((_d = (_c = discount === null || discount === void 0 ? void 0 : discount.kind) === null || _c === void 0 ? void 0 : _c.manual) === null || _d === void 0 ? void 0 : _d.code) || "").toUpperCase();
44
44
  }
45
45
  if (!acc[code]) {
46
46
  acc[code] = 0;
47
47
  }
48
48
  // Handle both formats for amount
49
- if ((_c = discount.discountedAmount) === null || _c === void 0 ? void 0 : _c.amount) {
50
- acc[code] += parseFloat(discount.discountedAmount.amount || "0");
49
+ if ((_e = discount.discountedAmount) === null || _e === void 0 ? void 0 : _e.amount) {
50
+ acc[code] += parseFloat(((_f = discount === null || discount === void 0 ? void 0 : discount.discountedAmount) === null || _f === void 0 ? void 0 : _f.amount) || "0");
51
51
  }
52
52
  else if (discount.amount) {
53
53
  acc[code] += parseFloat(String(discount.amount));
@@ -56,16 +56,12 @@ const getOrderLevelDiscounts = (cart) => {
56
56
  }, {});
57
57
  if (!discountMap)
58
58
  return [];
59
- return Object.entries(discountMap)
60
- .map(([code, amount]) => ({
59
+ return Object.entries(discountMap).map(([code, amount]) => ({
61
60
  id: code,
62
61
  amount: amount,
63
62
  name: `Discount - ${code}`,
64
63
  type: "ORDER_LEVEL",
65
- }))
66
- .filter((discount) => cart.discounts
67
- .map((d) => d.toUpperCase())
68
- .includes(discount.id.toUpperCase()));
64
+ }));
69
65
  };
70
66
  const getShippingDiscounts = (cart) => {
71
67
  // CartState doesn't have discountAllocations directly
@@ -98,22 +94,27 @@ const getAppliedGiftCards = (cart) => {
98
94
  !Array.isArray(appliedGiftCards) ||
99
95
  appliedGiftCards.length === 0)
100
96
  return [];
101
- return appliedGiftCards.map((giftCard) => ({
102
- id: giftCard.id,
103
- amount: +giftCard.amountUsed.amount,
104
- name: `Gift Card - ${giftCard.lastCharacters}`,
105
- }));
97
+ return appliedGiftCards.map((giftCard) => {
98
+ var _a, _b, _c;
99
+ return ({
100
+ id: giftCard === null || giftCard === void 0 ? void 0 : giftCard.id,
101
+ amount: (_b = +((_a = giftCard === null || giftCard === void 0 ? void 0 : giftCard.amountUsed) === null || _a === void 0 ? void 0 : _a.amount)) !== null && _b !== void 0 ? _b : 0,
102
+ name: `Gift Card - ${(_c = giftCard === null || giftCard === void 0 ? void 0 : giftCard.lastCharacters) !== null && _c !== void 0 ? _c : "xxxx"}`,
103
+ });
104
+ });
106
105
  };
107
106
  const getSalesAmount = (cart) => {
108
- return cart.items.reduce((acc, item) => {
107
+ var _a;
108
+ return (_a = cart === null || cart === void 0 ? void 0 : cart.items) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => {
109
+ var _a, _b;
109
110
  // Get price and compareAtPrice directly from the CartItem
110
- const itemPrice = parseFloat((item.price || 0).toString());
111
- const itemCompareAtPrice = parseFloat((item.compareAtPrice || 0).toString());
111
+ const itemPrice = parseFloat(((item === null || item === void 0 ? void 0 : item.price) || 0).toString());
112
+ const itemCompareAtPrice = parseFloat(((item === null || item === void 0 ? void 0 : item.compareAtPrice) || 0).toString());
112
113
  // Create a custom sellingPlanAllocation if the item has one
113
114
  let customSellingPlanAllocation;
114
- if (item.sellingPlanAllocation) {
115
+ if (item === null || item === void 0 ? void 0 : item.sellingPlanAllocation) {
115
116
  customSellingPlanAllocation = {
116
- priceAdjustments: item.sellingPlanAllocation.priceAdjustments.map((adj) => ({
117
+ priceAdjustments: (_b = (_a = item === null || item === void 0 ? void 0 : item.sellingPlanAllocation) === null || _a === void 0 ? void 0 : _a.priceAdjustments) === null || _b === void 0 ? void 0 : _b.map((adj) => ({
117
118
  price: parseFloat(adj.price.amount),
118
119
  compareAtPrice: adj.compareAtPrice
119
120
  ? parseFloat(adj.compareAtPrice.amount)
@@ -125,10 +126,10 @@ const getSalesAmount = (cart) => {
125
126
  };
126
127
  }
127
128
  const { compareAtPrice, price } = getVariablesVariantPrice({
128
- quantity: item.quantity || 1,
129
+ quantity: (item === null || item === void 0 ? void 0 : item.quantity) || 1,
129
130
  variantPrice: itemPrice,
130
131
  variantCompareAtPrice: itemCompareAtPrice,
131
- currencyCode: item.currencyCode || "USD",
132
+ currencyCode: (item === null || item === void 0 ? void 0 : item.currencyCode) || "USD",
132
133
  sellingPlanAllocation: customSellingPlanAllocation,
133
134
  });
134
135
  if (compareAtPrice && compareAtPrice > price) {
@@ -139,7 +140,7 @@ const getSalesAmount = (cart) => {
139
140
  };
140
141
  const getLineItemDiscounts = (cart) => {
141
142
  var _a;
142
- const discountMap = cart.items.reduce((acc, item) => {
143
+ const discountMap = ((cart === null || cart === void 0 ? void 0 : cart.items) || []).reduce((acc, item) => {
143
144
  var _a;
144
145
  (_a = item === null || item === void 0 ? void 0 : item.discounts) === null || _a === void 0 ? void 0 : _a.forEach((discount) => {
145
146
  const code = discount === null || discount === void 0 ? void 0 : discount.code;
@@ -173,7 +174,7 @@ const getGiftCardsTotalAmount = (appliedGiftCards) => {
173
174
  return appliedGiftCards === null || appliedGiftCards === void 0 ? void 0 : appliedGiftCards.reduce((acc, giftCard) => acc + +giftCard.amount, 0);
174
175
  };
175
176
  const getTotalCompareAtPrice = (cart) => {
176
- return cart.items.reduce((acc, item) => {
177
+ return cart === null || cart === void 0 ? void 0 : cart.items.reduce((acc, item) => {
177
178
  // Get compareAtPrice directly from the CartItem
178
179
  const itemCompareAtPrice = item.compareAtPrice ||
179
180
  (item.price ? parseFloat(item.price.toString()) : 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapcart/mobile-components",
3
- "version": "0.8.51",
3
+ "version": "0.8.52",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/styles.css",