fontdue-js 2.18.4 → 2.19.1
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 +16 -0
- package/dist/__generated__/AddToCartBannerQuery.graphql.d.ts +1 -1
- package/dist/__generated__/AddToCartBannerQuery.graphql.js +22 -7
- package/dist/__generated__/AddToCartBanner_item.graphql.d.ts +10 -1
- package/dist/__generated__/AddToCartBanner_item.graphql.js +19 -4
- package/dist/__generated__/AddToCartBanner_order.graphql.d.ts +10 -1
- package/dist/__generated__/AddToCartBanner_order.graphql.js +18 -3
- package/dist/__generated__/CartItemProduct_product.graphql.d.ts +4 -1
- package/dist/__generated__/CartItemProduct_product.graphql.js +15 -5
- package/dist/__generated__/CartOrderCompleteOrderMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CartOrderCompleteOrderMutation.graphql.js +27 -5
- package/dist/__generated__/CartOrderRemoveDiscountMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CartOrderRemoveDiscountMutation.graphql.js +27 -5
- package/dist/__generated__/CartOrderUpdateMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CartOrderUpdateMutation.graphql.js +27 -5
- package/dist/__generated__/CartQuery.graphql.d.ts +1 -1
- package/dist/__generated__/CartQuery.graphql.js +27 -5
- package/dist/__generated__/CartStateRemoveDiscountMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CartStateRemoveDiscountMutation.graphql.js +15 -3
- package/dist/__generated__/CartStateUpdateMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CartStateUpdateMutation.graphql.js +27 -5
- package/dist/__generated__/CartTotals_order.graphql.d.ts +3 -1
- package/dist/__generated__/CartTotals_order.graphql.js +14 -2
- package/dist/__generated__/CheckoutUpdateCustomerMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CheckoutUpdateCustomerMutation.graphql.js +27 -5
- package/dist/__generated__/CheckoutUpdateOrderMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CheckoutUpdateOrderMutation.graphql.js +27 -5
- package/dist/__generated__/CouponCodeInputApplyCouponMutation.graphql.d.ts +1 -1
- package/dist/__generated__/CouponCodeInputApplyCouponMutation.graphql.js +15 -3
- package/dist/__generated__/PrecartAddToCartMutation.graphql.d.ts +1 -1
- package/dist/__generated__/PrecartAddToCartMutation.graphql.js +32 -10
- package/dist/__generated__/StoreModalCartQuery.graphql.d.ts +1 -1
- package/dist/__generated__/StoreModalCartQuery.graphql.js +38 -16
- package/dist/__generated__/StoreModalFamily_collection.graphql.d.ts +2 -1
- package/dist/__generated__/StoreModalFamily_collection.graphql.js +9 -3
- package/dist/__generated__/StoreModalProductQuery.graphql.d.ts +1 -1
- package/dist/__generated__/StoreModalProductQuery.graphql.js +10 -4
- package/dist/__generated__/StoreModalProductRefetchQuery.graphql.d.ts +1 -1
- package/dist/__generated__/StoreModalProductRefetchQuery.graphql.js +10 -4
- package/dist/__generated__/StoreModalUnifiedCheckoutUpdateOrderMutation.graphql.d.ts +1 -1
- package/dist/__generated__/StoreModalUnifiedCheckoutUpdateOrderMutation.graphql.js +15 -3
- package/dist/__generated__/TestFontsFormUpdateCustomerMutation.graphql.d.ts +1 -1
- package/dist/__generated__/TestFontsFormUpdateCustomerMutation.graphql.js +27 -5
- package/dist/__tests__/collectionBundleSelection.test.d.ts +1 -0
- package/dist/__tests__/collectionBundleSelection.test.js +1181 -0
- package/dist/components/AddToCartBanner/index.js +7 -1
- package/dist/components/Cart/CartItem/CartItemProduct.js +3 -2
- package/dist/components/Cart/CartTotals.js +7 -7
- package/dist/components/CharacterViewer/index.js +53 -37
- package/dist/components/CorsErrorModal.d.ts +1 -0
- package/dist/components/CorsErrorModal.js +99 -0
- package/dist/components/OrderVariableSelection/OrderVariableSelectionRedux.js +2 -1
- package/dist/components/StoreModal/StoreModalFamily.js +2 -2
- package/dist/corsError.d.ts +5 -0
- package/dist/corsError.js +55 -0
- package/dist/fontdue.css +194 -126
- package/dist/reducer.js +4 -0
- package/dist/relay/environment.js +33 -19
- package/dist/utils.js +2 -2
- package/package.json +5 -2
- package/vitest.config.ts +10 -0
package/dist/reducer.js
CHANGED
|
@@ -82,6 +82,10 @@ const collectionSkuIdWithDiscount = (state, skuId) => {
|
|
|
82
82
|
const differences = (0, _utils.collectionSkuIdsDifferences)(state, skuId);
|
|
83
83
|
const collectionId = Object.keys(differences).filter(collSkuId => differences[collSkuId] <= state.skuPrices[skuId]).reduce((smallest, key) => {
|
|
84
84
|
if (!smallest || differences[key] < differences[smallest]) return key;
|
|
85
|
+
// When differences are equal, prefer a collection that is not the
|
|
86
|
+
// SKU being selected — this ensures collection bundles are preferred
|
|
87
|
+
// over selecting the family itself at the same price
|
|
88
|
+
if (differences[key] === differences[smallest] && smallest === skuId && key !== skuId) return key;
|
|
85
89
|
return smallest;
|
|
86
90
|
}, null);
|
|
87
91
|
if (collectionId) return [collectionId, differences[collectionId]];
|
|
@@ -8,6 +8,7 @@ exports.responseCache = exports.networkFetch = void 0;
|
|
|
8
8
|
exports.useCurrentEnvironment = useCurrentEnvironment;
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _relayRuntime = require("relay-runtime");
|
|
11
|
+
var _corsError = require("../corsError");
|
|
11
12
|
var _package = require("../../package.json");
|
|
12
13
|
// @ts-ignore - JSON import
|
|
13
14
|
|
|
@@ -22,35 +23,48 @@ const CACHE_TTL = 10 * 1000; // 10 seconds, to resolve preloaded results
|
|
|
22
23
|
function createNetworkFetch(options) {
|
|
23
24
|
return async function networkFetch(request, variables) {
|
|
24
25
|
const url = (FONTDUE_URL && `${FONTDUE_URL}/graphql`) ?? ((options === null || options === void 0 ? void 0 : options.url) ?? '') + '/graphql';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
let resp;
|
|
27
|
+
try {
|
|
28
|
+
resp = await fetch(url + `?queryName=${request.name}`, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
credentials: 'include',
|
|
31
|
+
headers: {
|
|
32
|
+
Accept: 'application/json',
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
'fontdue-stripe-integration': STRIPE_INTEGRATION ?? ((options === null || options === void 0 ? void 0 : options.stripeIntegration) || 'dynamic'),
|
|
35
|
+
'fontdue-client-version': _package.version
|
|
36
|
+
},
|
|
37
|
+
body: JSON.stringify({
|
|
38
|
+
query: request.text,
|
|
39
|
+
variables
|
|
40
|
+
}),
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
next: {
|
|
43
|
+
tags: ['graphql', `operation:${request.name}`]
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if ((0, _corsError.handlePossibleCorsError)(error, url)) {
|
|
48
|
+
return {
|
|
49
|
+
data: undefined,
|
|
50
|
+
errors: [{
|
|
51
|
+
message: 'Cross-origin request blocked'
|
|
52
|
+
}]
|
|
53
|
+
};
|
|
41
54
|
}
|
|
42
|
-
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
43
57
|
const json = await resp.json();
|
|
44
58
|
|
|
45
59
|
// GraphQL returns exceptions (for example, a missing required variable) in the "errors"
|
|
46
60
|
// property of the response. If any exceptions occurred when processing the request,
|
|
47
61
|
// throw an error to indicate to the developer what went wrong.
|
|
48
62
|
if (Array.isArray(json.errors)) {
|
|
49
|
-
var _json$errors;
|
|
63
|
+
var _json$errors, _error$extensions;
|
|
50
64
|
const error = (_json$errors = json.errors) === null || _json$errors === void 0 ? void 0 : _json$errors[0];
|
|
51
65
|
console.error('GraphQL Error:', {
|
|
52
66
|
message: error.message,
|
|
53
|
-
code: error.code,
|
|
67
|
+
code: (_error$extensions = error.extensions) === null || _error$extensions === void 0 ? void 0 : _error$extensions.code,
|
|
54
68
|
path: error.path
|
|
55
69
|
});
|
|
56
70
|
}
|
package/dist/utils.js
CHANGED
|
@@ -47,8 +47,8 @@ const collectionSkuIdsDifferences = (state, skuId) => Object.keys(state.collecti
|
|
|
47
47
|
}).reduce((acc, collectionSkuId) => {
|
|
48
48
|
const coll = state.collectionStyleSkus[collectionSkuId];
|
|
49
49
|
const selectedSkuIdsInColl = Object.keys(state.selectedSkuIds).filter(selectedSkuId => state.selectedSkuIds[selectedSkuId] === true && collContainsSkuId(coll, selectedSkuId));
|
|
50
|
-
const sumOfSelectedSkuIdsInColl = selectedSkuIdsInColl.map(selectedSkuId => state.skuPrices[selectedSkuId]).reduce((acc, price) => acc + price, 0);
|
|
51
|
-
acc[collectionSkuId] = state.skuPrices[collectionSkuId] - sumOfSelectedSkuIdsInColl;
|
|
50
|
+
const sumOfSelectedSkuIdsInColl = selectedSkuIdsInColl.map(selectedSkuId => state.skuPrices[selectedSkuId] ?? 0).reduce((acc, price) => acc + price, 0);
|
|
51
|
+
acc[collectionSkuId] = (state.skuPrices[collectionSkuId] ?? 0) - sumOfSelectedSkuIdsInColl;
|
|
52
52
|
return acc;
|
|
53
53
|
}, {});
|
|
54
54
|
exports.collectionSkuIdsDifferences = collectionSkuIdsDifferences;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fontdue-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "npm run relay && run-p build-js build-css build-ts",
|
|
6
6
|
"build-js": "babel src --out-dir dist --extensions .ts,.tsx,.js,.jsx",
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
"build-css": "sass --load-path=node_modules --no-source-map src/index.scss dist/fontdue.css",
|
|
9
9
|
"relay": "relay-compiler",
|
|
10
10
|
"update-unicode-data": "node src/scripts/updateUnicodeData.js",
|
|
11
|
+
"test": "vitest run",
|
|
12
|
+
"test:watch": "vitest",
|
|
11
13
|
"prepublishOnly": "npm run build"
|
|
12
14
|
},
|
|
13
15
|
"author": "Fontdue",
|
|
@@ -60,7 +62,8 @@
|
|
|
60
62
|
"react-dom": "^19.0.0",
|
|
61
63
|
"relay-compiler": "^18.0.0",
|
|
62
64
|
"sass": "^1.62",
|
|
63
|
-
"typescript": "^5.9"
|
|
65
|
+
"typescript": "^5.9",
|
|
66
|
+
"vitest": "^4.1.1"
|
|
64
67
|
},
|
|
65
68
|
"relay": {
|
|
66
69
|
"src": "./src",
|