@tapcart/mobile-components 0.8.41 → 0.8.43
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/components/ui/tap.js +1 -1
- package/dist/lib/cart.util.d.ts +35 -6
- package/dist/lib/cart.util.d.ts.map +1 -1
- package/dist/lib/cart.util.js +32 -11
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import React, { useState, useEffect, useCallback, useRef, } from "react";
|
|
4
4
|
// @ts-ignore -- webbridge-react is not typed (yet)
|
|
5
|
-
import { useActions } from "@tapcart/
|
|
5
|
+
import { useActions } from "@tapcart/app-studio-sdk";
|
|
6
6
|
// Shared manager for all instances of the hook
|
|
7
7
|
const tapManager = (() => {
|
|
8
8
|
const elements = new Map();
|
package/dist/lib/cart.util.d.ts
CHANGED
|
@@ -39,10 +39,39 @@ export type CalculatedData = {
|
|
|
39
39
|
};
|
|
40
40
|
export declare const DEFAULT_CALCULATED_DATA: CalculatedData;
|
|
41
41
|
export declare const getCalculatedCartData: (cart: EnrichedCart) => CalculatedData;
|
|
42
|
-
export declare const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
42
|
+
export declare const getUniqueCartItemID: (options: {
|
|
43
|
+
variantId: string;
|
|
44
|
+
sellingPlanId?: string | undefined;
|
|
45
|
+
attributes?: {
|
|
46
|
+
[key: string]: string;
|
|
47
|
+
} | {
|
|
48
|
+
key: string;
|
|
49
|
+
value: string;
|
|
50
|
+
}[] | undefined;
|
|
51
|
+
discounts?: string[] | {
|
|
52
|
+
discountedAmount?: {
|
|
53
|
+
amount: string;
|
|
54
|
+
currencyCode: string;
|
|
55
|
+
} | undefined;
|
|
56
|
+
amount?: number | undefined;
|
|
57
|
+
title: string;
|
|
58
|
+
targetType?: string | undefined;
|
|
59
|
+
type?: string | undefined;
|
|
60
|
+
code?: string | undefined;
|
|
61
|
+
}[] | {
|
|
62
|
+
amount: number;
|
|
63
|
+
code: string;
|
|
64
|
+
title?: string | undefined;
|
|
65
|
+
type: string;
|
|
66
|
+
readOnly?: boolean | undefined;
|
|
67
|
+
}[] | {
|
|
68
|
+
discountedAmount: {
|
|
69
|
+
amount: string;
|
|
70
|
+
currencyCode: string;
|
|
71
|
+
};
|
|
72
|
+
targetType: string;
|
|
73
|
+
code?: string | undefined;
|
|
74
|
+
title?: string | undefined;
|
|
75
|
+
}[] | undefined;
|
|
76
|
+
}) => string;
|
|
48
77
|
//# sourceMappingURL=cart.util.d.ts.map
|
|
@@ -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,O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M,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,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"}
|
package/dist/lib/cart.util.js
CHANGED
|
@@ -28,12 +28,12 @@ export const getVariantPrice = ({ quantity, variant, sellingPlanAllocation = { p
|
|
|
28
28
|
const getOrderLevelDiscounts = (cart) => {
|
|
29
29
|
var _a;
|
|
30
30
|
const discountMap = (_a = cart.discountAllocations) === null || _a === void 0 ? void 0 : _a.filter((discount) => discount.targetType !== "SHIPPING_LINE").reduce((acc, discount) => {
|
|
31
|
-
var _a;
|
|
31
|
+
var _a, _b;
|
|
32
32
|
const code = ((_a = discount.code) !== null && _a !== void 0 ? _a : "unknown").toUpperCase();
|
|
33
33
|
if (!acc[code]) {
|
|
34
34
|
acc[code] = 0;
|
|
35
35
|
}
|
|
36
|
-
acc[code] += parseFloat(discount.discountedAmount.amount);
|
|
36
|
+
acc[code] += parseFloat(((_b = discount === null || discount === void 0 ? void 0 : discount.discountedAmount) === null || _b === void 0 ? void 0 : _b.amount) || "0");
|
|
37
37
|
return acc;
|
|
38
38
|
}, {});
|
|
39
39
|
if (!discountMap)
|
|
@@ -53,11 +53,14 @@ const getShippingDiscounts = (cart) => {
|
|
|
53
53
|
var _a;
|
|
54
54
|
if (!(cart === null || cart === void 0 ? void 0 : cart.discountAllocations))
|
|
55
55
|
return [];
|
|
56
|
-
return (_a = cart.discountAllocations) === null || _a === void 0 ? void 0 : _a.filter((discount) => discount.targetType === "SHIPPING_LINE").map((discount) =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
return (_a = cart.discountAllocations) === null || _a === void 0 ? void 0 : _a.filter((discount) => discount.targetType === "SHIPPING_LINE").map((discount) => {
|
|
57
|
+
var _a;
|
|
58
|
+
return ({
|
|
59
|
+
amount: (_a = discount === null || discount === void 0 ? void 0 : discount.discountedAmount) === null || _a === void 0 ? void 0 : _a.amount,
|
|
60
|
+
code: discount === null || discount === void 0 ? void 0 : discount.code,
|
|
61
|
+
type: discount === null || discount === void 0 ? void 0 : discount.targetType,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
61
64
|
};
|
|
62
65
|
export const isOrderLevelDiscount = (code, cart) => {
|
|
63
66
|
const orderLevelDiscounts = getOrderLevelDiscounts(cart);
|
|
@@ -187,11 +190,29 @@ export const getCalculatedCartData = (cart) => {
|
|
|
187
190
|
totalSavedAmount,
|
|
188
191
|
};
|
|
189
192
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
+
// Until the actual CartItem ID is available via webbridge, we use this unique identifier
|
|
194
|
+
export const getUniqueCartItemID = (options) => {
|
|
195
|
+
const { variantId, sellingPlanId, attributes, discounts } = options;
|
|
196
|
+
const attributesString = Array.isArray(attributes)
|
|
197
|
+
? attributes === null || attributes === void 0 ? void 0 : attributes.map((attr) => `${attr.key}-${attr.value}`).sort().reverse().join("-")
|
|
193
198
|
: Object.entries(attributes || {})
|
|
199
|
+
.sort()
|
|
200
|
+
.reverse()
|
|
194
201
|
.map(([key, value]) => `${key}-${value}`)
|
|
195
|
-
.join("-")
|
|
202
|
+
.join("-");
|
|
203
|
+
const discountsString = discounts
|
|
204
|
+
? Array.isArray(discounts) && typeof discounts[0] === "string"
|
|
205
|
+
? discounts.join("-")
|
|
206
|
+
: discounts
|
|
207
|
+
.map((discount) => {
|
|
208
|
+
var _a;
|
|
209
|
+
const amount = parseFloat(((_a = discount.discountedAmount) === null || _a === void 0 ? void 0 : _a.amount) || discount.amount || "0");
|
|
210
|
+
const title = discount.title || "";
|
|
211
|
+
const code = discount.code || "";
|
|
212
|
+
return `${amount}-${title || code}`;
|
|
213
|
+
})
|
|
214
|
+
.join("-")
|
|
215
|
+
: "";
|
|
216
|
+
const key = `${getIdFromGid(variantId)}~~~~${sellingPlanId ? getIdFromGid(sellingPlanId) : "no-plan"}~~~~${attributesString}${discountsString ? "~~~~" + discountsString : ""}`;
|
|
196
217
|
return key;
|
|
197
218
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tapcart/mobile-components",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.43",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"style": "dist/styles.css",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@radix-ui/react-toggle-group": "^1.0.4",
|
|
73
73
|
"@tabler/icons-react": "^3.2.0",
|
|
74
74
|
"@tanstack/react-virtual": "^3.13.6",
|
|
75
|
-
"@tapcart/
|
|
75
|
+
"@tapcart/app-studio-sdk": "^2.0.0",
|
|
76
76
|
"apple-pay-button": "^1.1.7",
|
|
77
77
|
"class-variance-authority": "^0.6.0",
|
|
78
78
|
"clsx": "^1.2.1",
|