@ubnt/store.core 9.27.0-beta.1 → 9.27.0
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 +3 -27
- package/lib/_virtual/_virtual_multi-entry.js +2 -15
- package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
- package/lib/_virtual/_virtual_multi-entry.mjs +0 -2
- package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
- package/lib/assets/udmPro.jpg +0 -0
- package/lib/assets/udmPro2.jpg +0 -0
- package/lib/assets/udmProSpecial.jpg +0 -0
- package/lib/assets/udmProSpecial2.jpg +0 -0
- package/lib/components/Button/CartButton.d.ts +11 -1
- package/lib/components/Button/CartButton.js +43 -5
- package/lib/components/Button/CartButton.js.map +1 -1
- package/lib/components/Button/CartButton.mjs +43 -5
- package/lib/components/Button/CartButton.mjs.map +1 -1
- package/lib/components/Header/CartModalV2/Item/Item.styles.d.ts +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmPro.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.js +5 -5
- package/lib/components/ModelCompareV3/assets/Consoles/bigCompare/udmProSpecial.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/udmPro.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.js +1 -1
- package/lib/components/ModelCompareV3/assets/Consoles/udmProSpecial.jpg.mjs +2 -2
- package/lib/components/ModelCompareV3/data/CloudGateways.js +6 -6
- package/lib/components/ModelCompareV3/data/CloudGateways.mjs +4 -4
- package/lib/components/ModelCompareV3/data/products/udmPro.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udmPro.mjs +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProSpecial.js +1 -1
- package/lib/components/ModelCompareV3/data/products/udmProSpecial.mjs +1 -1
- package/lib/constants/proStoreCategories/mapping/index.d.ts +0 -2
- package/lib/constants/proStoreCategories/mapping/index.js +54 -48
- package/lib/constants/proStoreCategories/mapping/index.js.map +1 -1
- package/lib/constants/proStoreCategories/mapping/index.mjs +54 -48
- package/lib/constants/proStoreCategories/mapping/index.mjs.map +1 -1
- package/lib/constants/proStoreCategories/mapping/redirects.js +1 -9
- package/lib/constants/proStoreCategories/mapping/redirects.js.map +1 -1
- package/lib/constants/proStoreCategories/mapping/redirects.mjs +1 -9
- package/lib/constants/proStoreCategories/mapping/redirects.mjs.map +1 -1
- package/lib/constants/proStoreCategories/mapping/unifi.d.ts +4 -4
- package/lib/constants/proStoreCategories/mapping/unifi.js +3 -3
- package/lib/constants/proStoreCategories/mapping/unifi.js.map +1 -1
- package/lib/constants/proStoreCategories/mapping/unifi.mjs +3 -3
- package/lib/constants/proStoreCategories/mapping/unifi.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/ar.json.js +1 -2
- package/lib/constants/proStoreCategories/translations/ar.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/ar.json.mjs +1 -2
- package/lib/constants/proStoreCategories/translations/ar.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/de.json.js +1 -2
- package/lib/constants/proStoreCategories/translations/de.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/de.json.mjs +1 -2
- package/lib/constants/proStoreCategories/translations/de.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/el.json.js +1 -2
- package/lib/constants/proStoreCategories/translations/el.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/el.json.mjs +1 -2
- package/lib/constants/proStoreCategories/translations/el.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/en.json.js +0 -4
- package/lib/constants/proStoreCategories/translations/en.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/en.json.mjs +1 -4
- package/lib/constants/proStoreCategories/translations/en.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/es.json.js +1 -2
- package/lib/constants/proStoreCategories/translations/es.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/es.json.mjs +1 -2
- package/lib/constants/proStoreCategories/translations/es.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/fr.json.js +2 -3
- package/lib/constants/proStoreCategories/translations/fr.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/fr.json.mjs +2 -3
- package/lib/constants/proStoreCategories/translations/fr.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/it.json.js +1 -2
- package/lib/constants/proStoreCategories/translations/it.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/it.json.mjs +1 -2
- package/lib/constants/proStoreCategories/translations/it.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/ja.json.js +1 -2
- package/lib/constants/proStoreCategories/translations/ja.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/ja.json.mjs +1 -2
- package/lib/constants/proStoreCategories/translations/ja.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/pt-BR.json.js +1 -2
- package/lib/constants/proStoreCategories/translations/pt-BR.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs +1 -2
- package/lib/constants/proStoreCategories/translations/pt-BR.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hans.json.js +2 -3
- package/lib/constants/proStoreCategories/translations/zh-Hans.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs +2 -3
- package/lib/constants/proStoreCategories/translations/zh-Hans.json.mjs.map +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js +2 -3
- package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.js.map +1 -1
- package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs +2 -3
- package/lib/constants/proStoreCategories/translations/zh-Hant-TW.json.mjs.map +1 -1
- package/lib/helpers/index.d.ts +0 -1
- package/lib/helpers/index.js +0 -11
- package/lib/helpers/index.js.map +1 -1
- package/lib/helpers/index.mjs +0 -1
- package/lib/helpers/index.mjs.map +1 -1
- package/lib/types/index.d.ts +0 -1
- package/lib/types/index.js +0 -2
- package/lib/types/index.js.map +1 -1
- package/lib/types/index.mjs +0 -1
- package/lib/types/index.mjs.map +1 -1
- package/lib/utils/array.d.ts +0 -4
- package/lib/utils/array.js +0 -10
- package/lib/utils/array.js.map +1 -1
- package/lib/utils/array.mjs +1 -10
- package/lib/utils/array.mjs.map +1 -1
- package/lib/utils/money/constants.d.ts +0 -7
- package/lib/utils/money/constants.js +1 -9
- package/lib/utils/money/constants.js.map +1 -1
- package/lib/utils/money/constants.mjs +2 -10
- package/lib/utils/money/constants.mjs.map +1 -1
- package/lib/utils/money/tax.private.d.ts +8 -0
- package/lib/utils/money/tax.private.js +14 -5
- package/lib/utils/money/tax.private.js.map +1 -1
- package/lib/utils/money/tax.private.mjs +16 -8
- package/lib/utils/money/tax.private.mjs.map +1 -1
- package/package.json +51 -51
- package/lib/helpers/product.d.ts +0 -87
- package/lib/helpers/product.js +0 -346
- package/lib/helpers/product.js.map +0 -1
- package/lib/helpers/product.mjs +0 -335
- package/lib/helpers/product.mjs.map +0 -1
- package/lib/helpers/product.test.d.ts +0 -1
- package/lib/types/product.d.ts +0 -87
- package/lib/types/product.js +0 -14
- package/lib/types/product.js.map +0 -1
- package/lib/types/product.mjs +0 -13
- package/lib/types/product.mjs.map +0 -1
- package/lib/utils/productSort.d.ts +0 -41
- package/lib/utils/productSort.js +0 -67
- package/lib/utils/productSort.js.map +0 -1
- package/lib/utils/productSort.mjs +0 -60
- package/lib/utils/productSort.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"product.mjs","sources":["../../src/types/product.ts"],"sourcesContent":["import type { Currency } from \"../types\";\n\nexport enum DisplayProductStatus {\n Available = \"Available\",\n Backorder = \"Backorder\",\n ComingSoon = \"ComingSoon\",\n RegionNotAvailable = \"RegionNotAvailable\",\n SoldOut = \"SoldOut\",\n Unavailable = \"Unavailable\",\n}\n\nexport type CollectionSection = {\n id: string;\n productTags: Array<string>;\n title: string;\n};\n\nexport interface Section extends CollectionSection {\n items: Section[];\n}\n\nexport type ProductTagFragment = { __typename?: \"ProductTag\"; name: string };\n\nexport interface MappedProductSection<T> extends Section {\n items: MappedProductSection<T>[];\n products: T[];\n /**\n * States which is conditionally calculated based on the need.\n * E.g. if it is an optical collection where collection sections\n * are rendered inside the VariantSelector items, we need to\n * know which section does not contain products that are in stock.\n * If all products in the section are out of stock, we need to\n * apply grayed out style to the section button.\n */\n isDisabled?: boolean;\n}\n\nexport interface StorefrontProduct {\n id: string;\n slug: string;\n title: string;\n shortTitle?: string | null;\n collectionSlug?: string | null;\n organizationalCollectionSlug?: string | null;\n proCollectionSlug?: string | null;\n status: DisplayProductStatus;\n options: Array<{\n __typename?: \"StorefrontOption\";\n id: string;\n title: string;\n slug: string;\n values: Array<{\n __typename?: \"StorefrontOptionValue\";\n id: string;\n title: string;\n slug: string;\n }>;\n }>;\n tags: Array<{ __typename?: \"ProductTag\"; name: string }>;\n minDisplayPrice: { __typename?: \"Money\"; amount: number; currency: Currency };\n variants: Array<{\n __typename?: \"StorefrontProductVariant\";\n id: string;\n status: DisplayProductStatus;\n availableInOtherStores: Array<{\n __typename: \"StorefrontProductVariantAlternativeStore\";\n }>;\n optionValueIds?: Array<string> | null;\n }>;\n}\n\nexport type StorefrontOptionValue = {\n __typename?: \"StorefrontOptionValue\";\n id: string;\n slug: string;\n title: string;\n};\n\nexport type StorefrontOption = {\n __typename?: \"StorefrontOption\";\n id: string;\n slug: string;\n title: string;\n values: Array<StorefrontOptionValue>;\n};\n"],"names":["DisplayProductStatus"],"mappings":";;AAEY,IAAAA,oBAAA,GAAA,gBAAAA,qBAAL,IAAA;EACLA,sBAAA,WAAY,CAAA,GAAA,WAAA;EACZA,sBAAA,WAAY,CAAA,GAAA,WAAA;EACZA,sBAAA,YAAa,CAAA,GAAA,YAAA;EACbA,sBAAA,oBAAqB,CAAA,GAAA,oBAAA;EACrBA,sBAAA,SAAU,CAAA,GAAA,SAAA;EACVA,sBAAA,aAAc,CAAA,GAAA,aAAA;EANJA,OAAAA,qBAAAA;AAAA,CAAA,EAAAA,oBAAA,IAAA,CAAA,CAAA,CAAA;"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Nullish, StorefrontProduct, StoreId, UnionToAllPossibleTuples } from "../types";
|
|
2
|
-
import { DisplayProductStatus } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* Narrow MinimalProProductFragment type even more to the union of fields that are needed to sort product
|
|
5
|
-
*/
|
|
6
|
-
type ProductMinFieldsForSorting = Pick<StorefrontProduct, "status" | "tags" | "minDisplayPrice"> & {
|
|
7
|
-
variants: {
|
|
8
|
-
availableInOtherStores: Array<{
|
|
9
|
-
__typename: string;
|
|
10
|
-
}>;
|
|
11
|
-
}[];
|
|
12
|
-
linkedProducts?: {
|
|
13
|
-
status: StorefrontProduct["status"];
|
|
14
|
-
}[];
|
|
15
|
-
};
|
|
16
|
-
export declare enum Sort {
|
|
17
|
-
HighestPrice = "highest-price",
|
|
18
|
-
LowestPrice = "lowest-price",
|
|
19
|
-
Availability = "availability"
|
|
20
|
-
}
|
|
21
|
-
export declare enum SortOrder {
|
|
22
|
-
Asc = "Asc",
|
|
23
|
-
Desc = "Desc"
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Variants statuses sorted in ascending order from least preferable to most, so if some new status comes in, then the
|
|
27
|
-
* lookup for `.indexOf()` would return `-1`, thus being "worse" then DisplayProductStatus.SoldOut and moved to the very
|
|
28
|
-
* back of list
|
|
29
|
-
*/
|
|
30
|
-
export declare const sortedStatusesByPriorityAsc: UnionToAllPossibleTuples<DisplayProductStatus>;
|
|
31
|
-
export declare const sortByAvailabilityDesc: (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => number;
|
|
32
|
-
export declare const sortByPrice: (order: SortOrder) => (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => number;
|
|
33
|
-
/**
|
|
34
|
-
* Sorts products based on the given sort type.
|
|
35
|
-
* @param currentSort - sort type
|
|
36
|
-
* @param sortByWeightTag - if false, then sort by weight tag is
|
|
37
|
-
* ignored (e.g. for `Related Add-ons` where
|
|
38
|
-
* we don't want to sort by weight tag)
|
|
39
|
-
*/
|
|
40
|
-
export declare const sortProducts: (currentSort: Nullish<string | Sort>, storeId?: StoreId, sortByWeightTag?: boolean) => (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => number;
|
|
41
|
-
export {};
|
package/lib/utils/productSort.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
require('../types/index.js');
|
|
4
|
-
var array = require('./array.js');
|
|
5
|
-
var product$1 = require('./product.js');
|
|
6
|
-
var product = require('../types/product.js');
|
|
7
|
-
"use strict";
|
|
8
|
-
var Sort = /* @__PURE__ */(Sort2 => {
|
|
9
|
-
Sort2["HighestPrice"] = "highest-price";
|
|
10
|
-
Sort2["LowestPrice"] = "lowest-price";
|
|
11
|
-
Sort2["Availability"] = "availability";
|
|
12
|
-
return Sort2;
|
|
13
|
-
})(Sort || {});
|
|
14
|
-
var SortOrder = /* @__PURE__ */(SortOrder2 => {
|
|
15
|
-
SortOrder2["Asc"] = "Asc";
|
|
16
|
-
SortOrder2["Desc"] = "Desc";
|
|
17
|
-
return SortOrder2;
|
|
18
|
-
})(SortOrder || {});
|
|
19
|
-
const sortedStatusesByPriorityAsc = [product.DisplayProductStatus.Unavailable, product.DisplayProductStatus.ComingSoon, product.DisplayProductStatus.SoldOut, product.DisplayProductStatus.RegionNotAvailable, product.DisplayProductStatus.Backorder, product.DisplayProductStatus.Available];
|
|
20
|
-
const getProductStatusPriority = product$1 => {
|
|
21
|
-
let sortStatus = product$1.status;
|
|
22
|
-
if (product$1.variants.some(variant => variant.availableInOtherStores.length) || product$1.linkedProducts && product$1.linkedProducts.some(linkedProduct => linkedProduct.status === product.DisplayProductStatus.Available)) {
|
|
23
|
-
sortStatus = product.DisplayProductStatus.Available;
|
|
24
|
-
}
|
|
25
|
-
return sortedStatusesByPriorityAsc.indexOf(sortStatus);
|
|
26
|
-
};
|
|
27
|
-
const sortByAvailabilityDesc = (current, next) => {
|
|
28
|
-
return array.normalizeSortResult(getProductStatusPriority(next) - getProductStatusPriority(current));
|
|
29
|
-
};
|
|
30
|
-
const sortByPrice = order => (current, next) => {
|
|
31
|
-
const currentProductPrice = current.minDisplayPrice.amount;
|
|
32
|
-
const nextProductPrice = next.minDisplayPrice.amount;
|
|
33
|
-
if (order === "Desc" /* Desc */) {
|
|
34
|
-
return nextProductPrice - currentProductPrice;
|
|
35
|
-
} else {
|
|
36
|
-
return currentProductPrice - nextProductPrice;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const sortProducts = (currentSort, storeId, sortByWeightTag = true) => (current, next) => {
|
|
40
|
-
switch (currentSort) {
|
|
41
|
-
// Sort by price
|
|
42
|
-
case "highest-price" /* HighestPrice */:
|
|
43
|
-
case "lowest-price" /* LowestPrice */:
|
|
44
|
-
{
|
|
45
|
-
return sortByPrice(currentSort === "highest-price" /* HighestPrice */ ? "Desc" /* Desc */ : "Asc" /* Asc */)(current, next);
|
|
46
|
-
}
|
|
47
|
-
case "availability" /* Availability */:
|
|
48
|
-
{
|
|
49
|
-
return sortByAvailabilityDesc(current, next);
|
|
50
|
-
}
|
|
51
|
-
default:
|
|
52
|
-
{
|
|
53
|
-
const sorts = [sortByAvailabilityDesc];
|
|
54
|
-
if (sortByWeightTag) {
|
|
55
|
-
sorts.push(product$1.sortByTagWeight(product$1.SortSiteId.Store, storeId));
|
|
56
|
-
}
|
|
57
|
-
return array.combineSorts(sorts)(current, next);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
exports.Sort = Sort;
|
|
62
|
-
exports.SortOrder = SortOrder;
|
|
63
|
-
exports.sortByAvailabilityDesc = sortByAvailabilityDesc;
|
|
64
|
-
exports.sortByPrice = sortByPrice;
|
|
65
|
-
exports.sortProducts = sortProducts;
|
|
66
|
-
exports.sortedStatusesByPriorityAsc = sortedStatusesByPriorityAsc;
|
|
67
|
-
//# sourceMappingURL=productSort.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"productSort.js","sources":["../../src/utils/productSort.ts"],"sourcesContent":["import type {\n Nullish,\n StorefrontProduct,\n StoreId,\n UnionToAllPossibleTuples,\n} from \"../types\";\nimport { DisplayProductStatus } from \"../types\";\nimport { combineSorts, normalizeSortResult } from \"./array\";\nimport { sortByTagWeight, SortSiteId } from \"./product\";\n\n/**\n * Narrow MinimalProProductFragment type even more to the union of fields that are needed to sort product\n */\ntype ProductMinFieldsForSorting = Pick<\n StorefrontProduct,\n \"status\" | \"tags\" | \"minDisplayPrice\"\n> & {\n variants: {\n // We only need bare minimum from array to compare array length\n // FIXME: move it to backend as a boolean field so we don't need to fetch entire array to reduce it to a boolean ourselves\n availableInOtherStores: Array<{ __typename: string }>;\n }[];\n linkedProducts?: {\n status: StorefrontProduct[\"status\"];\n }[];\n};\n\nexport enum Sort {\n HighestPrice = \"highest-price\",\n LowestPrice = \"lowest-price\",\n Availability = \"availability\",\n}\n\nexport enum SortOrder {\n Asc = \"Asc\",\n Desc = \"Desc\",\n}\n\n/**\n * Variants statuses sorted in ascending order from least preferable to most, so if some new status comes in, then the\n * lookup for `.indexOf()` would return `-1`, thus being \"worse\" then DisplayProductStatus.SoldOut and moved to the very\n * back of list\n */\nexport const sortedStatusesByPriorityAsc: UnionToAllPossibleTuples<DisplayProductStatus> =\n [\n DisplayProductStatus.Unavailable,\n DisplayProductStatus.ComingSoon,\n DisplayProductStatus.SoldOut,\n DisplayProductStatus.RegionNotAvailable,\n DisplayProductStatus.Backorder,\n DisplayProductStatus.Available,\n ];\n/**\n * Due to currently variant status being nullable for historical reasons we need to have a fallback state\n * TODO: remove once display status is StorefrontProductVariant.status is non-nullable\n */\nconst getProductStatusPriority = (\n product: ProductMinFieldsForSorting,\n): number => {\n let sortStatus = product.status;\n\n // Virtually set sort status as available if it has alternative stores\n if (\n product.variants.some((variant) => variant.availableInOtherStores.length) ||\n (product.linkedProducts &&\n product.linkedProducts.some(\n (linkedProduct) =>\n linkedProduct.status === DisplayProductStatus.Available,\n ))\n ) {\n sortStatus = DisplayProductStatus.Available;\n }\n\n return sortedStatusesByPriorityAsc.indexOf(sortStatus);\n};\n\nexport const sortByAvailabilityDesc = (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n): number => {\n return normalizeSortResult(\n getProductStatusPriority(next) - getProductStatusPriority(current),\n );\n};\n\nexport const sortByPrice =\n (order: SortOrder) =>\n (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n ): number => {\n const currentProductPrice = current.minDisplayPrice.amount;\n\n const nextProductPrice = next.minDisplayPrice.amount;\n\n if (order === SortOrder.Desc) {\n return nextProductPrice - currentProductPrice;\n } else {\n return currentProductPrice - nextProductPrice;\n }\n };\n\n/**\n * Sorts products based on the given sort type.\n * @param currentSort - sort type\n * @param sortByWeightTag - if false, then sort by weight tag is\n * ignored (e.g. for `Related Add-ons` where\n * we don't want to sort by weight tag)\n */\nexport const sortProducts =\n (\n currentSort: Nullish<string | Sort>,\n storeId?: StoreId,\n sortByWeightTag = true,\n ) =>\n (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => {\n switch (currentSort) {\n // Sort by price\n case Sort.HighestPrice:\n case Sort.LowestPrice: {\n return sortByPrice(\n currentSort === Sort.HighestPrice ? SortOrder.Desc : SortOrder.Asc,\n )(current, next);\n }\n\n case Sort.Availability: {\n return sortByAvailabilityDesc(current, next);\n }\n\n default: {\n const sorts = [sortByAvailabilityDesc];\n\n // Add sorting by tag weight\n if (sortByWeightTag) {\n sorts.push(sortByTagWeight(SortSiteId.Store, storeId));\n }\n\n // Do additional sorting by tag weight only after initial sorting resulting in \"same group\"\n return combineSorts(sorts)(current, next);\n }\n }\n };\n"],"names":["Sort","SortOrder","sortedStatusesByPriorityAsc","DisplayProductStatus","Unavailable","ComingSoon","SoldOut","RegionNotAvailable","Backorder","Available","getProductStatusPriority","product","sortStatus","status","variants","some","variant","availableInOtherStores","length","linkedProducts","linkedProduct","indexOf","sortByAvailabilityDesc","current","next","normalizeSortResult","sortByPrice","order","currentProductPrice","minDisplayPrice","amount","nextProductPrice","sortProducts","currentSort","storeId","sortByWeightTag","sorts","push","sortByTagWeight","SortSiteId","Store","combineSorts"],"mappings":";;;;;;;AA2BY,IAAAA,IAAA,GAAA,gBAAAA,KAAL,IAAA;EACLA,MAAA,cAAe,CAAA,GAAA,eAAA;EACfA,MAAA,aAAc,CAAA,GAAA,cAAA;EACdA,MAAA,cAAe,CAAA,GAAA,cAAA;EAHLA,OAAAA,KAAAA;AAAA,CAAA,EAAAA,IAAA,IAAA,CAAA,CAAA,CAAA;AAMA,IAAAC,SAAA,GAAA,gBAAAA,UAAL,IAAA;EACLA,WAAA,KAAM,CAAA,GAAA,KAAA;EACNA,WAAA,MAAO,CAAA,GAAA,MAAA;EAFGA,OAAAA,UAAAA;AAAA,CAAA,EAAAA,SAAA,IAAA,CAAA,CAAA,CAAA;AAUL,MAAMC,2BACX,GAAA,CACEC,OAAAA,CAAAA,oBAAqB,CAAAC,WAAA,EACrBD,OAAAA,CAAAA,oBAAqB,CAAAE,UAAA,EACrBF,OAAAA,CAAAA,oBAAqB,CAAAG,OAAA,EACrBH,OAAAA,CAAAA,oBAAqB,CAAAI,kBAAA,EACrBJ,OAAAA,CAAAA,oBAAqB,CAAAK,SAAA,EACrBL,OAAAA,CAAAA,oBAAqB,CAAAM,SAAA,CACvB;AAKF,MAAMC,wBAAA,GACJC,SACW,IAAA;EACX,IAAIC,aAAaD,SAAQ,CAAAE,MAAA;EAGzB,IACEF,SAAQ,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,SAASC,IAAI,CAAA;MAC7C;IAEA;MAAS;QACD,MAAAY,KAAA,GAAQ,CAACd,sBAAsB,CAAA;QAGrC,IAAIa,eAAiB,EAAA;UACnBC,KAAA,CAAMC,IAAK,CAAAC,SAAA,CAAAA,eAAA,CAAgBC,SAAW,CAAAA,UAAA,CAAAC,KAAA,EAAON,OAAO,CAAC,CAAA;QACvD;QAGA,OAAOO,KAAa,CAAAA,YAAA,CAAAL,KAAK,CAAE,CAAAb,OAAA,EAASC,IAAI,CAAA;MAC1C;EACF;AACF,CAAA;;;;;;"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import '../types/index.mjs';
|
|
2
|
-
import { normalizeSortResult, combineSorts } from './array.mjs';
|
|
3
|
-
import { sortByTagWeight, SortSiteId } from './product.mjs';
|
|
4
|
-
import { DisplayProductStatus } from '../types/product.mjs';
|
|
5
|
-
"use strict";
|
|
6
|
-
var Sort = /* @__PURE__ */(Sort2 => {
|
|
7
|
-
Sort2["HighestPrice"] = "highest-price";
|
|
8
|
-
Sort2["LowestPrice"] = "lowest-price";
|
|
9
|
-
Sort2["Availability"] = "availability";
|
|
10
|
-
return Sort2;
|
|
11
|
-
})(Sort || {});
|
|
12
|
-
var SortOrder = /* @__PURE__ */(SortOrder2 => {
|
|
13
|
-
SortOrder2["Asc"] = "Asc";
|
|
14
|
-
SortOrder2["Desc"] = "Desc";
|
|
15
|
-
return SortOrder2;
|
|
16
|
-
})(SortOrder || {});
|
|
17
|
-
const sortedStatusesByPriorityAsc = [DisplayProductStatus.Unavailable, DisplayProductStatus.ComingSoon, DisplayProductStatus.SoldOut, DisplayProductStatus.RegionNotAvailable, DisplayProductStatus.Backorder, DisplayProductStatus.Available];
|
|
18
|
-
const getProductStatusPriority = product => {
|
|
19
|
-
let sortStatus = product.status;
|
|
20
|
-
if (product.variants.some(variant => variant.availableInOtherStores.length) || product.linkedProducts && product.linkedProducts.some(linkedProduct => linkedProduct.status === DisplayProductStatus.Available)) {
|
|
21
|
-
sortStatus = DisplayProductStatus.Available;
|
|
22
|
-
}
|
|
23
|
-
return sortedStatusesByPriorityAsc.indexOf(sortStatus);
|
|
24
|
-
};
|
|
25
|
-
const sortByAvailabilityDesc = (current, next) => {
|
|
26
|
-
return normalizeSortResult(getProductStatusPriority(next) - getProductStatusPriority(current));
|
|
27
|
-
};
|
|
28
|
-
const sortByPrice = order => (current, next) => {
|
|
29
|
-
const currentProductPrice = current.minDisplayPrice.amount;
|
|
30
|
-
const nextProductPrice = next.minDisplayPrice.amount;
|
|
31
|
-
if (order === "Desc" /* Desc */) {
|
|
32
|
-
return nextProductPrice - currentProductPrice;
|
|
33
|
-
} else {
|
|
34
|
-
return currentProductPrice - nextProductPrice;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const sortProducts = (currentSort, storeId, sortByWeightTag = true) => (current, next) => {
|
|
38
|
-
switch (currentSort) {
|
|
39
|
-
// Sort by price
|
|
40
|
-
case "highest-price" /* HighestPrice */:
|
|
41
|
-
case "lowest-price" /* LowestPrice */:
|
|
42
|
-
{
|
|
43
|
-
return sortByPrice(currentSort === "highest-price" /* HighestPrice */ ? "Desc" /* Desc */ : "Asc" /* Asc */)(current, next);
|
|
44
|
-
}
|
|
45
|
-
case "availability" /* Availability */:
|
|
46
|
-
{
|
|
47
|
-
return sortByAvailabilityDesc(current, next);
|
|
48
|
-
}
|
|
49
|
-
default:
|
|
50
|
-
{
|
|
51
|
-
const sorts = [sortByAvailabilityDesc];
|
|
52
|
-
if (sortByWeightTag) {
|
|
53
|
-
sorts.push(sortByTagWeight(SortSiteId.Store, storeId));
|
|
54
|
-
}
|
|
55
|
-
return combineSorts(sorts)(current, next);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
export { Sort, SortOrder, sortByAvailabilityDesc, sortByPrice, sortProducts, sortedStatusesByPriorityAsc };
|
|
60
|
-
//# sourceMappingURL=productSort.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"productSort.mjs","sources":["../../src/utils/productSort.ts"],"sourcesContent":["import type {\n Nullish,\n StorefrontProduct,\n StoreId,\n UnionToAllPossibleTuples,\n} from \"../types\";\nimport { DisplayProductStatus } from \"../types\";\nimport { combineSorts, normalizeSortResult } from \"./array\";\nimport { sortByTagWeight, SortSiteId } from \"./product\";\n\n/**\n * Narrow MinimalProProductFragment type even more to the union of fields that are needed to sort product\n */\ntype ProductMinFieldsForSorting = Pick<\n StorefrontProduct,\n \"status\" | \"tags\" | \"minDisplayPrice\"\n> & {\n variants: {\n // We only need bare minimum from array to compare array length\n // FIXME: move it to backend as a boolean field so we don't need to fetch entire array to reduce it to a boolean ourselves\n availableInOtherStores: Array<{ __typename: string }>;\n }[];\n linkedProducts?: {\n status: StorefrontProduct[\"status\"];\n }[];\n};\n\nexport enum Sort {\n HighestPrice = \"highest-price\",\n LowestPrice = \"lowest-price\",\n Availability = \"availability\",\n}\n\nexport enum SortOrder {\n Asc = \"Asc\",\n Desc = \"Desc\",\n}\n\n/**\n * Variants statuses sorted in ascending order from least preferable to most, so if some new status comes in, then the\n * lookup for `.indexOf()` would return `-1`, thus being \"worse\" then DisplayProductStatus.SoldOut and moved to the very\n * back of list\n */\nexport const sortedStatusesByPriorityAsc: UnionToAllPossibleTuples<DisplayProductStatus> =\n [\n DisplayProductStatus.Unavailable,\n DisplayProductStatus.ComingSoon,\n DisplayProductStatus.SoldOut,\n DisplayProductStatus.RegionNotAvailable,\n DisplayProductStatus.Backorder,\n DisplayProductStatus.Available,\n ];\n/**\n * Due to currently variant status being nullable for historical reasons we need to have a fallback state\n * TODO: remove once display status is StorefrontProductVariant.status is non-nullable\n */\nconst getProductStatusPriority = (\n product: ProductMinFieldsForSorting,\n): number => {\n let sortStatus = product.status;\n\n // Virtually set sort status as available if it has alternative stores\n if (\n product.variants.some((variant) => variant.availableInOtherStores.length) ||\n (product.linkedProducts &&\n product.linkedProducts.some(\n (linkedProduct) =>\n linkedProduct.status === DisplayProductStatus.Available,\n ))\n ) {\n sortStatus = DisplayProductStatus.Available;\n }\n\n return sortedStatusesByPriorityAsc.indexOf(sortStatus);\n};\n\nexport const sortByAvailabilityDesc = (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n): number => {\n return normalizeSortResult(\n getProductStatusPriority(next) - getProductStatusPriority(current),\n );\n};\n\nexport const sortByPrice =\n (order: SortOrder) =>\n (\n current: ProductMinFieldsForSorting,\n next: ProductMinFieldsForSorting,\n ): number => {\n const currentProductPrice = current.minDisplayPrice.amount;\n\n const nextProductPrice = next.minDisplayPrice.amount;\n\n if (order === SortOrder.Desc) {\n return nextProductPrice - currentProductPrice;\n } else {\n return currentProductPrice - nextProductPrice;\n }\n };\n\n/**\n * Sorts products based on the given sort type.\n * @param currentSort - sort type\n * @param sortByWeightTag - if false, then sort by weight tag is\n * ignored (e.g. for `Related Add-ons` where\n * we don't want to sort by weight tag)\n */\nexport const sortProducts =\n (\n currentSort: Nullish<string | Sort>,\n storeId?: StoreId,\n sortByWeightTag = true,\n ) =>\n (current: ProductMinFieldsForSorting, next: ProductMinFieldsForSorting) => {\n switch (currentSort) {\n // Sort by price\n case Sort.HighestPrice:\n case Sort.LowestPrice: {\n return sortByPrice(\n currentSort === Sort.HighestPrice ? SortOrder.Desc : SortOrder.Asc,\n )(current, next);\n }\n\n case Sort.Availability: {\n return sortByAvailabilityDesc(current, next);\n }\n\n default: {\n const sorts = [sortByAvailabilityDesc];\n\n // Add sorting by tag weight\n if (sortByWeightTag) {\n sorts.push(sortByTagWeight(SortSiteId.Store, storeId));\n }\n\n // Do additional sorting by tag weight only after initial sorting resulting in \"same group\"\n return combineSorts(sorts)(current, next);\n }\n }\n };\n"],"names":["Sort","SortOrder","sortedStatusesByPriorityAsc","DisplayProductStatus","Unavailable","ComingSoon","SoldOut","RegionNotAvailable","Backorder","Available","getProductStatusPriority","product","sortStatus","status","variants","some","variant","availableInOtherStores","length","linkedProducts","linkedProduct","indexOf","sortByAvailabilityDesc","current","next","normalizeSortResult","sortByPrice","order","currentProductPrice","minDisplayPrice","amount","nextProductPrice","sortProducts","currentSort","storeId","sortByWeightTag","sorts","push","sortByTagWeight","SortSiteId","Store","combineSorts"],"mappings":";;;;;AA2BY,IAAAA,IAAA,GAAA,gBAAAA,KAAL,IAAA;EACLA,MAAA,cAAe,CAAA,GAAA,eAAA;EACfA,MAAA,aAAc,CAAA,GAAA,cAAA;EACdA,MAAA,cAAe,CAAA,GAAA,cAAA;EAHLA,OAAAA,KAAAA;AAAA,CAAA,EAAAA,IAAA,IAAA,CAAA,CAAA,CAAA;AAMA,IAAAC,SAAA,GAAA,gBAAAA,UAAL,IAAA;EACLA,WAAA,KAAM,CAAA,GAAA,KAAA;EACNA,WAAA,MAAO,CAAA,GAAA,MAAA;EAFGA,OAAAA,UAAAA;AAAA,CAAA,EAAAA,SAAA,IAAA,CAAA,CAAA,CAAA;AAUL,MAAMC,2BACX,GAAA,CACEC,oBAAqB,CAAAC,WAAA,EACrBD,oBAAqB,CAAAE,UAAA,EACrBF,oBAAqB,CAAAG,OAAA,EACrBH,oBAAqB,CAAAI,kBAAA,EACrBJ,oBAAqB,CAAAK,SAAA,EACrBL,oBAAqB,CAAAM,SAAA,CACvB;AAKF,MAAMC,wBAAA,GACJC,OACW,IAAA;EACX,IAAIC,aAAaD,OAAQ,CAAAE,MAAA;EAGzB,IACEF,OAAQ,CAAAG,QAAA,CAASC,IAAK,CAACC,OAAY,IAAAA,OAAA,CAAQC,sBAAuB,CAAAC,MAAM,CACvE,IAAAP,OAAA,CAAQQ,cACP,IAAAR,OAAA,CAAQQ,cAAe,CAAAJ,IAAA,CACpBK,aAAA,IACCA,aAAc,CAAAP,MAAA,KAAWV,oBAAqB,CAAAM,SAAA,CAEpD,EAAA;IACAG,UAAA,GAAaT,oBAAqB,CAAAM,SAAA;EACpC;EAEO,OAAAP,2BAAA,CAA4BmB,QAAQT,UAAU,CAAA;AACvD,CAAA;AAEa,MAAAU,sBAAA,GAAyB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