@scayle/storefront-core 7.64.2 → 7.64.4
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 +14 -0
- package/dist/helpers/filterHelper.cjs +8 -3
- package/dist/helpers/filterHelper.d.ts +1 -1
- package/dist/helpers/filterHelper.mjs +8 -3
- package/dist/helpers/productHelpers.cjs +5 -3
- package/dist/helpers/productHelpers.d.ts +1 -1
- package/dist/helpers/productHelpers.mjs +8 -7
- package/dist/helpers/sanitizationHelpers.cjs +2 -3
- package/dist/helpers/sanitizationHelpers.mjs +4 -3
- package/dist/helpers/sortingHelper.cjs +3 -2
- package/dist/helpers/sortingHelper.d.ts +8 -13
- package/dist/helpers/sortingHelper.mjs +7 -2
- package/dist/rpc/methods/basket/basket.cjs +16 -7
- package/dist/rpc/methods/basket/basket.d.ts +9 -3
- package/dist/rpc/methods/basket/basket.mjs +12 -7
- package/dist/rpc/methods/checkout/checkout.cjs +1 -1
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/utils/user.cjs +4 -2
- package/dist/utils/user.d.ts +3 -1
- package/dist/utils/user.mjs +4 -2
- package/package.json +6 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 7.64.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Replaced `radash` utils with custom native implementations
|
|
8
|
+
|
|
9
|
+
## 7.64.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Add support for `orderCustomData` on the basket endpoints
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @scayle/storefront-api@17.6.0
|
|
16
|
+
|
|
3
17
|
## 7.64.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.transformToWhereCondition = exports.transformStateToFilters = exports.transformSortToFilter = exports.transformMinAndMaxPriceToFilter = exports.serializeFilters = exports.mergeFilters = exports.isFilterActive = exports.groupFiltersByKey = exports.groupFilterableValuesByKey = exports.getGroupedFilterableValues = exports.getFilterablePriceValue = exports.getActiveFilters = exports.deserializeFilters = void 0;
|
|
7
7
|
var _storefrontApi = require("@scayle/storefront-api");
|
|
8
|
-
var _radash = require("radash");
|
|
9
8
|
var _sortingHelper = require("./sortingHelper.cjs");
|
|
10
9
|
const transformToWhereCondition = conditions => {
|
|
11
10
|
const where = {
|
|
@@ -108,7 +107,13 @@ const getActiveFilters = (filters, activeFilters) => {
|
|
|
108
107
|
};
|
|
109
108
|
exports.getActiveFilters = getActiveFilters;
|
|
110
109
|
const groupFiltersByKey = filters => {
|
|
111
|
-
|
|
110
|
+
const groupedFilters = filters.reduce((acc, item) => {
|
|
111
|
+
const groupId = item.key;
|
|
112
|
+
if (!acc[groupId]) acc[groupId] = [];
|
|
113
|
+
acc[groupId].push(item);
|
|
114
|
+
return acc;
|
|
115
|
+
}, {});
|
|
116
|
+
return Object.entries(groupedFilters);
|
|
112
117
|
};
|
|
113
118
|
exports.groupFiltersByKey = groupFiltersByKey;
|
|
114
119
|
const transformMinAndMaxPriceToFilter = prices => {
|
|
@@ -145,7 +150,7 @@ const getFilterablePriceValue = (filterableValues, key = "min") => {
|
|
|
145
150
|
};
|
|
146
151
|
exports.getFilterablePriceValue = getFilterablePriceValue;
|
|
147
152
|
const serializeFilters = filter => {
|
|
148
|
-
if (
|
|
153
|
+
if (Object.keys(filter).length === 0) {
|
|
149
154
|
return void 0;
|
|
150
155
|
}
|
|
151
156
|
return Object.assign({}, ...Object.entries(filter).map(([filterName, filterValue]) => {
|
|
@@ -33,7 +33,7 @@ export declare const transformStateToFilters: (state: {
|
|
|
33
33
|
export declare const mergeFilters: (filters: TransformedFilter[]) => Record<string, any>;
|
|
34
34
|
export declare const isFilterActive: (filters: Record<string, any>, filterToCheck: TransformedFilter) => any;
|
|
35
35
|
export declare const getActiveFilters: (filters: Record<string, any>, activeFilters: Record<string, any>) => TransformedFilter[];
|
|
36
|
-
export declare const groupFiltersByKey: (filters: TransformedFilter[]) =>
|
|
36
|
+
export declare const groupFiltersByKey: (filters: TransformedFilter[]) => [string, TransformedFilter[]][];
|
|
37
37
|
export declare const transformMinAndMaxPriceToFilter: (prices: (CentAmount | undefined)[]) => any;
|
|
38
38
|
export declare const transformSortToFilter: (sort: string) => {
|
|
39
39
|
by: import("@scayle/storefront-api").APISortOption;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { FilterTypes } from "@scayle/storefront-api";
|
|
2
|
-
import { group, isEmpty } from "radash";
|
|
3
2
|
import { getSortByValue } from "./sortingHelper.mjs";
|
|
4
3
|
export const transformToWhereCondition = (conditions) => {
|
|
5
4
|
const where = { attributes: [] };
|
|
@@ -96,7 +95,13 @@ export const getActiveFilters = (filters, activeFilters) => {
|
|
|
96
95
|
return [].concat(...Object.values(filters)).filter((item) => isFilterActive(activeFilters, item)) || [];
|
|
97
96
|
};
|
|
98
97
|
export const groupFiltersByKey = (filters) => {
|
|
99
|
-
|
|
98
|
+
const groupedFilters = filters.reduce((acc, item) => {
|
|
99
|
+
const groupId = item.key;
|
|
100
|
+
if (!acc[groupId]) acc[groupId] = [];
|
|
101
|
+
acc[groupId].push(item);
|
|
102
|
+
return acc;
|
|
103
|
+
}, {});
|
|
104
|
+
return Object.entries(groupedFilters);
|
|
100
105
|
};
|
|
101
106
|
export const transformMinAndMaxPriceToFilter = (prices) => {
|
|
102
107
|
const [min = 0, max = 1e5] = prices;
|
|
@@ -127,7 +132,7 @@ export const getFilterablePriceValue = (filterableValues, key = "min") => {
|
|
|
127
132
|
return prices.value[key];
|
|
128
133
|
};
|
|
129
134
|
export const serializeFilters = (filter) => {
|
|
130
|
-
if (
|
|
135
|
+
if (Object.keys(filter).length === 0) {
|
|
131
136
|
return void 0;
|
|
132
137
|
}
|
|
133
138
|
return Object.assign(
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.slugify = exports.isVariantInStock = exports.isInStock = exports.getVariantCrosssellingValues = exports.getVariantBySize = exports.getVariant = exports.getTotalAppliedReductions = exports.getSizeFromVariant = exports.getSizeFromSpecificVariant = exports.getProductSiblings = exports.getProductPath = exports.getProductColors = exports.getProductAndSiblingsColors = exports.getPrice = exports.getOriginalPrice = exports.getLowestPrice = exports.getLatestCategory = exports.getCategoriesByRoute = exports.getBadgeLabel = exports.getAttribute = exports.getAppliedReductionsByCategory = exports.getAllSizesFromVariants = void 0;
|
|
7
7
|
var _storefrontApi = require("@scayle/storefront-api");
|
|
8
|
-
var _radash = require("radash");
|
|
9
8
|
var _slugify = _interopRequireDefault(require("slugify"));
|
|
10
9
|
var _product = require("../constants/product.cjs");
|
|
11
10
|
var _attributeHelpers = require("./attributeHelpers.cjs");
|
|
@@ -97,7 +96,10 @@ const getVariant = (variants, id) => {
|
|
|
97
96
|
return variants?.find(variant => variant.id === id);
|
|
98
97
|
};
|
|
99
98
|
exports.getVariant = getVariant;
|
|
100
|
-
const getAllSizesFromVariants = (variantsAttributes, attributeName = "shopSize") =>
|
|
99
|
+
const getAllSizesFromVariants = (variantsAttributes, attributeName = "shopSize") => {
|
|
100
|
+
const array = variantsAttributes.map(variant => (0, _storefrontApi.getFirstAttributeValue)(variant.attributes, attributeName)).filter(Boolean);
|
|
101
|
+
return [...new Map(array.map(item => [item?.id ?? item, item])).values()];
|
|
102
|
+
};
|
|
101
103
|
exports.getAllSizesFromVariants = getAllSizesFromVariants;
|
|
102
104
|
const getProductSiblings = (product, colorAttributeName = "colorDetail") => {
|
|
103
105
|
if (!product) {
|
|
@@ -180,7 +182,7 @@ const getVariantCrosssellingValues = variants => {
|
|
|
180
182
|
return [];
|
|
181
183
|
}
|
|
182
184
|
const crossellings = variants.map(variant => variant.advancedAttributes?.variantCrosssellings).filter(Boolean);
|
|
183
|
-
const uniqueCrossellings = (
|
|
185
|
+
const uniqueCrossellings = [...new Map(crossellings.map(item => [item?.id ?? item, item])).values()];
|
|
184
186
|
const values = uniqueCrossellings.map(r => r?.values);
|
|
185
187
|
const fieldSets = (0, _arrayHelpers.flattenDeep)(values).map(r => r?.fieldSet);
|
|
186
188
|
return (0, _arrayHelpers.flattenDeep)(fieldSets).map(r => r?.value).filter(it => !!it);
|
|
@@ -30,7 +30,7 @@ export declare const getAppliedReductionsByCategory: (price: VariantPrice | Bask
|
|
|
30
30
|
export declare const getSizeFromVariant: (variant: Variant, attributeName?: string) => Value | undefined;
|
|
31
31
|
export declare const getSizeFromSpecificVariant: (product: Product, variantId?: number) => Value | null | undefined;
|
|
32
32
|
export declare const getVariant: (variants: Variant[], id: number) => Variant | undefined;
|
|
33
|
-
export declare const getAllSizesFromVariants: (variantsAttributes: Variant[], attributeName?: string) =>
|
|
33
|
+
export declare const getAllSizesFromVariants: (variantsAttributes: Variant[], attributeName?: string) => any[];
|
|
34
34
|
export declare const getProductSiblings: (product?: Product | null, colorAttributeName?: string) => ProductSibling[];
|
|
35
35
|
export declare const getProductColors: (product: Product, colorAttributeName?: string) => string[];
|
|
36
36
|
export declare const getVariantBySize: (variants: Variant[], size: Value, sizeAttributeName?: string) => Variant | undefined;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getFirstAttributeValue } from "@scayle/storefront-api";
|
|
2
|
-
import { unique } from "radash";
|
|
3
2
|
import baseSlugify from "slugify";
|
|
4
3
|
import { ProductImageType } from "../constants/product.mjs";
|
|
5
4
|
import { getAttributeValue, getAttributeValueTuples } from "./attributeHelpers.mjs";
|
|
@@ -73,12 +72,12 @@ export const getSizeFromSpecificVariant = (product, variantId) => {
|
|
|
73
72
|
export const getVariant = (variants, id) => {
|
|
74
73
|
return variants?.find((variant) => variant.id === id);
|
|
75
74
|
};
|
|
76
|
-
export const getAllSizesFromVariants = (variantsAttributes, attributeName = "shopSize") =>
|
|
77
|
-
variantsAttributes.map(
|
|
75
|
+
export const getAllSizesFromVariants = (variantsAttributes, attributeName = "shopSize") => {
|
|
76
|
+
const array = variantsAttributes.map(
|
|
78
77
|
(variant) => getFirstAttributeValue(variant.attributes, attributeName)
|
|
79
|
-
).filter(Boolean)
|
|
80
|
-
(
|
|
81
|
-
|
|
78
|
+
).filter(Boolean);
|
|
79
|
+
return [...new Map(array.map((item) => [item?.id ?? item, item])).values()];
|
|
80
|
+
};
|
|
82
81
|
export const getProductSiblings = (product, colorAttributeName = "colorDetail") => {
|
|
83
82
|
if (!product) {
|
|
84
83
|
return [];
|
|
@@ -163,7 +162,9 @@ export const getVariantCrosssellingValues = (variants) => {
|
|
|
163
162
|
return [];
|
|
164
163
|
}
|
|
165
164
|
const crossellings = variants.map((variant) => variant.advancedAttributes?.variantCrosssellings).filter(Boolean);
|
|
166
|
-
const uniqueCrossellings =
|
|
165
|
+
const uniqueCrossellings = [
|
|
166
|
+
...new Map(crossellings.map((item) => [item?.id ?? item, item])).values()
|
|
167
|
+
];
|
|
167
168
|
const values = uniqueCrossellings.map((r) => r?.values);
|
|
168
169
|
const fieldSets = flattenDeep(values).map((r) => r?.fieldSet);
|
|
169
170
|
return flattenDeep(fieldSets).map((r) => r?.value).filter((it) => !!it);
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.stripShopLocaleFromPath = exports.purifySensitiveValue = exports.purifySensitiveData = exports.createAndPurifyHeaders = void 0;
|
|
7
|
-
var _radash = require("radash");
|
|
8
7
|
const SANITIZATION_MASK = "********";
|
|
9
8
|
const regex = /(?<!^).(?!$)/g;
|
|
10
9
|
const stripShopLocaleFromPath = (locale, path, splitter = "/") => path.split(splitter).filter(segment => segment.toLowerCase() !== locale.toLowerCase()).join("/");
|
|
@@ -15,7 +14,7 @@ const purifySensitiveValue = (value, showFirstAndLastChar = false) => {
|
|
|
15
14
|
exports.purifySensitiveValue = purifySensitiveValue;
|
|
16
15
|
const purifySensitiveData = (data = {}, blacklistedKeys = ["password"], showFirstAndLastChar = false) => {
|
|
17
16
|
return Object.entries(data).reduce((purifiedPayload, [key, value]) => {
|
|
18
|
-
if (
|
|
17
|
+
if (!!value && value.constructor === Object) {
|
|
19
18
|
purifiedPayload[key] = purifySensitiveData(value, blacklistedKeys);
|
|
20
19
|
return purifiedPayload;
|
|
21
20
|
}
|
|
@@ -30,7 +29,7 @@ const purifySensitiveData = (data = {}, blacklistedKeys = ["password"], showFirs
|
|
|
30
29
|
};
|
|
31
30
|
exports.purifySensitiveData = purifySensitiveData;
|
|
32
31
|
const createAndPurifyHeaders = headers => {
|
|
33
|
-
const sanitizedHeaders = (
|
|
32
|
+
const sanitizedHeaders = Object.fromEntries(Object.entries(headers).filter(([_, value]) => value !== void 0));
|
|
34
33
|
return new Headers(sanitizedHeaders);
|
|
35
34
|
};
|
|
36
35
|
exports.createAndPurifyHeaders = createAndPurifyHeaders;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isObject, shake } from "radash";
|
|
2
1
|
const SANITIZATION_MASK = "********";
|
|
3
2
|
const regex = /(?<!^).(?!$)/g;
|
|
4
3
|
export const stripShopLocaleFromPath = (locale, path, splitter = "/") => path.split(splitter).filter((segment) => segment.toLowerCase() !== locale.toLowerCase()).join("/");
|
|
@@ -8,7 +7,7 @@ export const purifySensitiveValue = (value, showFirstAndLastChar = false) => {
|
|
|
8
7
|
export const purifySensitiveData = (data = {}, blacklistedKeys = ["password"], showFirstAndLastChar = false) => {
|
|
9
8
|
return Object.entries(data).reduce(
|
|
10
9
|
(purifiedPayload, [key, value]) => {
|
|
11
|
-
if (
|
|
10
|
+
if (!!value && value.constructor === Object) {
|
|
12
11
|
purifiedPayload[key] = purifySensitiveData(value, blacklistedKeys);
|
|
13
12
|
return purifiedPayload;
|
|
14
13
|
}
|
|
@@ -26,6 +25,8 @@ export const purifySensitiveData = (data = {}, blacklistedKeys = ["password"], s
|
|
|
26
25
|
);
|
|
27
26
|
};
|
|
28
27
|
export const createAndPurifyHeaders = (headers) => {
|
|
29
|
-
const sanitizedHeaders =
|
|
28
|
+
const sanitizedHeaders = Object.fromEntries(
|
|
29
|
+
Object.entries(headers).filter(([_, value]) => value !== void 0)
|
|
30
|
+
);
|
|
30
31
|
return new Headers(sanitizedHeaders);
|
|
31
32
|
};
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getSortingValues = exports.getSortByValue = void 0;
|
|
7
7
|
var _storefrontApi = require("@scayle/storefront-api");
|
|
8
|
-
var _radash = require("radash");
|
|
9
8
|
var _sorting = require("../constants/sorting.cjs");
|
|
10
9
|
const SORTING_VALUES = {
|
|
11
10
|
topSeller: {
|
|
@@ -44,7 +43,9 @@ const SORTING_VALUES = {
|
|
|
44
43
|
query: _sorting.SortQuery.REDUCTION_ASC
|
|
45
44
|
}
|
|
46
45
|
};
|
|
47
|
-
const getSortingValues = (options = ["topSeller", "dateNewest", "priceDesc", "priceAsc", "reductionDesc", "reductionAsc"]) =>
|
|
46
|
+
const getSortingValues = (options = ["topSeller", "dateNewest", "priceDesc", "priceAsc", "reductionDesc", "reductionAsc"]) => {
|
|
47
|
+
return Object.fromEntries(options.filter(key => key in SORTING_VALUES).map(key => [key, SORTING_VALUES[key]]));
|
|
48
|
+
};
|
|
48
49
|
exports.getSortingValues = getSortingValues;
|
|
49
50
|
const getSortByValue = (query, defaultSort) => {
|
|
50
51
|
switch (query) {
|
|
@@ -1,42 +1,37 @@
|
|
|
1
1
|
import { APISortOption, APISortOrder } from '@scayle/storefront-api';
|
|
2
2
|
import type { Query, SortingValueKey } from '../index';
|
|
3
|
-
export declare const getSortingValues: (options?: Array<SortingValueKey>) =>
|
|
4
|
-
|
|
3
|
+
export declare const getSortingValues: (options?: Array<SortingValueKey>) => {
|
|
4
|
+
[k: string]: {
|
|
5
5
|
by: APISortOption;
|
|
6
6
|
direction: APISortOrder;
|
|
7
7
|
name: "topseller";
|
|
8
8
|
query: "topseller";
|
|
9
|
-
}
|
|
10
|
-
dateNewest: {
|
|
9
|
+
} | {
|
|
11
10
|
by: APISortOption;
|
|
12
11
|
name: "date_newest";
|
|
13
12
|
query: "date-newest";
|
|
14
|
-
}
|
|
15
|
-
priceDesc: {
|
|
13
|
+
} | {
|
|
16
14
|
by: APISortOption;
|
|
17
15
|
direction: APISortOrder;
|
|
18
16
|
name: "price_desc";
|
|
19
17
|
query: "price-desc";
|
|
20
|
-
}
|
|
21
|
-
priceAsc: {
|
|
18
|
+
} | {
|
|
22
19
|
by: APISortOption;
|
|
23
20
|
direction: APISortOrder;
|
|
24
21
|
name: "price_asc";
|
|
25
22
|
query: "price-asc";
|
|
26
|
-
}
|
|
27
|
-
reductionDesc: {
|
|
23
|
+
} | {
|
|
28
24
|
by: APISortOption;
|
|
29
25
|
direction: APISortOrder;
|
|
30
26
|
name: "reduction_desc";
|
|
31
27
|
query: "reduction-desc";
|
|
32
|
-
}
|
|
33
|
-
reductionAsc: {
|
|
28
|
+
} | {
|
|
34
29
|
by: APISortOption;
|
|
35
30
|
direction: APISortOrder;
|
|
36
31
|
name: "reduction_asc";
|
|
37
32
|
query: "reduction-asc";
|
|
38
33
|
};
|
|
39
|
-
}
|
|
34
|
+
};
|
|
40
35
|
export declare const getSortByValue: (query: Query, defaultSort?: SortingValueKey) => {
|
|
41
36
|
by: APISortOption;
|
|
42
37
|
direction: APISortOrder;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { APISortOption, APISortOrder } from "@scayle/storefront-api";
|
|
2
|
-
import { pick } from "radash";
|
|
3
2
|
import { SortName, SortQuery } from "../constants/sorting.mjs";
|
|
4
3
|
const SORTING_VALUES = {
|
|
5
4
|
topSeller: {
|
|
@@ -45,7 +44,13 @@ export const getSortingValues = (options = [
|
|
|
45
44
|
"priceAsc",
|
|
46
45
|
"reductionDesc",
|
|
47
46
|
"reductionAsc"
|
|
48
|
-
]) =>
|
|
47
|
+
]) => {
|
|
48
|
+
return Object.fromEntries(
|
|
49
|
+
options.filter((key) => key in SORTING_VALUES).map(
|
|
50
|
+
(key) => [key, SORTING_VALUES[key]]
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
};
|
|
49
54
|
export const getSortByValue = (query, defaultSort) => {
|
|
50
55
|
switch (query) {
|
|
51
56
|
case SortQuery.PRICE_DESC:
|
|
@@ -21,7 +21,8 @@ const addItemToBasket = exports.addItemToBasket = async function addItemToBasket
|
|
|
21
21
|
customData,
|
|
22
22
|
existingItemHandling = _constants.ExistingItemHandling.AddQuantityToExisting,
|
|
23
23
|
itemGroup,
|
|
24
|
-
with: _with
|
|
24
|
+
with: _with,
|
|
25
|
+
orderCustomData
|
|
25
26
|
}, context) {
|
|
26
27
|
if (!(0, _types.hasSession)(context)) {
|
|
27
28
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
@@ -48,7 +49,8 @@ const addItemToBasket = exports.addItemToBasket = async function addItemToBasket
|
|
|
48
49
|
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
49
50
|
}
|
|
50
51
|
}], {
|
|
51
|
-
skipAvailabilityCheck: false
|
|
52
|
+
skipAvailabilityCheck: false,
|
|
53
|
+
orderCustomData
|
|
52
54
|
}, {
|
|
53
55
|
existingItemHandling
|
|
54
56
|
});
|
|
@@ -94,7 +96,8 @@ const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBas
|
|
|
94
96
|
}));
|
|
95
97
|
const result = await bapiClient.basket.addOrUpdateItems(basketKey, itemsToBeAddedOrUpdated, {
|
|
96
98
|
skipAvailabilityCheck: false,
|
|
97
|
-
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
99
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
100
|
+
orderCustomData: params.orderCustomData
|
|
98
101
|
}, {
|
|
99
102
|
existingItemHandling: params.existingItemHandling || _constants.ExistingItemHandling.AddQuantityToExisting
|
|
100
103
|
});
|
|
@@ -129,7 +132,8 @@ const getBasket = exports.getBasket = async function getBasket2(options, context
|
|
|
129
132
|
const response = await bapiClient.basket.get(basketKey, {
|
|
130
133
|
with: resolvedWith,
|
|
131
134
|
campaignKey,
|
|
132
|
-
includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData
|
|
135
|
+
includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData,
|
|
136
|
+
orderCustomData: options?.orderCustomData
|
|
133
137
|
});
|
|
134
138
|
if (response.type === "failure") {
|
|
135
139
|
const {
|
|
@@ -155,7 +159,8 @@ const removeItemFromBasket = exports.removeItemFromBasket = async function remov
|
|
|
155
159
|
return await bapiClient.basket.deleteItem(basketKey, options.itemKey, {
|
|
156
160
|
with: resolvedWith,
|
|
157
161
|
campaignKey,
|
|
158
|
-
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
162
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
163
|
+
orderCustomData: options.orderCustomData
|
|
159
164
|
});
|
|
160
165
|
};
|
|
161
166
|
const clearBasket = exports.clearBasket = async function clearBasket2(context) {
|
|
@@ -175,12 +180,16 @@ const clearBasket = exports.clearBasket = async function clearBasket2(context) {
|
|
|
175
180
|
const mergeBaskets = exports.mergeBaskets = async function mergeBaskets2({
|
|
176
181
|
fromBasketKey,
|
|
177
182
|
toBasketKey,
|
|
178
|
-
with: _with
|
|
183
|
+
with: _with,
|
|
184
|
+
orderCustomData
|
|
179
185
|
}, context) {
|
|
180
186
|
const resolvedWith = getWithParams({
|
|
181
187
|
with: _with
|
|
182
188
|
}, context);
|
|
183
|
-
return await (0, _user.mergeBaskets)(fromBasketKey, toBasketKey,
|
|
189
|
+
return await (0, _user.mergeBaskets)(fromBasketKey, toBasketKey, {
|
|
190
|
+
...resolvedWith,
|
|
191
|
+
orderCustomData
|
|
192
|
+
}, context);
|
|
184
193
|
};
|
|
185
194
|
function parseBasketError(response) {
|
|
186
195
|
const parsedError = {
|
|
@@ -2,25 +2,31 @@ import type { AddOrUpdateItemError } from '@scayle/storefront-api';
|
|
|
2
2
|
import { ErrorResponse } from '../../../errors';
|
|
3
3
|
import type { AddOrUpdateItemType, BasketResponseData, BasketWithOptions, Product, RpcContext, Variant } from '../../../types';
|
|
4
4
|
import { ExistingItemHandling } from '../../../constants';
|
|
5
|
-
export declare const addItemToBasket: ({ variantId, promotionId, quantity, displayData, customData, existingItemHandling, itemGroup, with: _with, }: AddOrUpdateItemType & {
|
|
5
|
+
export declare const addItemToBasket: ({ variantId, promotionId, quantity, displayData, customData, existingItemHandling, itemGroup, with: _with, orderCustomData, }: AddOrUpdateItemType & {
|
|
6
6
|
existingItemHandling?: ExistingItemHandling;
|
|
7
7
|
with?: BasketWithOptions;
|
|
8
|
+
orderCustomData?: Record<string, unknown>;
|
|
8
9
|
}, context: RpcContext) => Promise<ErrorResponse | BasketResponseData<Product, Variant>>;
|
|
9
10
|
export declare const addItemsToBasket: (params: {
|
|
10
11
|
items: AddOrUpdateItemType[];
|
|
11
12
|
existingItemHandling: ExistingItemHandling;
|
|
12
13
|
with?: BasketWithOptions;
|
|
14
|
+
orderCustomData?: Record<string, unknown>;
|
|
13
15
|
}, context: RpcContext) => Promise<ErrorResponse | BasketResponseData<Product, Variant>>;
|
|
14
|
-
export declare const getBasket: (options: BasketWithOptions
|
|
16
|
+
export declare const getBasket: (options: (BasketWithOptions & {
|
|
17
|
+
orderCustomData?: Record<string, unknown>;
|
|
18
|
+
}) | undefined, context: RpcContext) => Promise<ErrorResponse | BasketResponseData<Product, Variant>>;
|
|
15
19
|
export declare const removeItemFromBasket: (options: {
|
|
16
20
|
itemKey: string;
|
|
17
21
|
with?: BasketWithOptions;
|
|
22
|
+
orderCustomData?: Record<string, unknown>;
|
|
18
23
|
}, context: RpcContext) => Promise<ErrorResponse | BasketResponseData<Product, Variant>>;
|
|
19
24
|
export declare const clearBasket: (context: RpcContext) => Promise<true | ErrorResponse>;
|
|
20
|
-
export declare const mergeBaskets: ({ fromBasketKey, toBasketKey, with: _with }: {
|
|
25
|
+
export declare const mergeBaskets: ({ fromBasketKey, toBasketKey, with: _with, orderCustomData }: {
|
|
21
26
|
fromBasketKey: string;
|
|
22
27
|
toBasketKey: string;
|
|
23
28
|
with?: BasketWithOptions;
|
|
29
|
+
orderCustomData?: Record<string, unknown>;
|
|
24
30
|
}, context: RpcContext) => Promise<{
|
|
25
31
|
type: "failure";
|
|
26
32
|
statusCode: number;
|
|
@@ -20,7 +20,8 @@ export const addItemToBasket = async function addItemToBasket2({
|
|
|
20
20
|
customData,
|
|
21
21
|
existingItemHandling = ExistingItemHandling.AddQuantityToExisting,
|
|
22
22
|
itemGroup,
|
|
23
|
-
with: _with
|
|
23
|
+
with: _with,
|
|
24
|
+
orderCustomData
|
|
24
25
|
}, context) {
|
|
25
26
|
if (!hasSession(context)) {
|
|
26
27
|
return new ErrorResponse(
|
|
@@ -53,7 +54,8 @@ export const addItemToBasket = async function addItemToBasket2({
|
|
|
53
54
|
}
|
|
54
55
|
],
|
|
55
56
|
{
|
|
56
|
-
skipAvailabilityCheck: false
|
|
57
|
+
skipAvailabilityCheck: false,
|
|
58
|
+
orderCustomData
|
|
57
59
|
},
|
|
58
60
|
{
|
|
59
61
|
existingItemHandling
|
|
@@ -103,7 +105,8 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
103
105
|
itemsToBeAddedOrUpdated,
|
|
104
106
|
{
|
|
105
107
|
skipAvailabilityCheck: false,
|
|
106
|
-
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
108
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
109
|
+
orderCustomData: params.orderCustomData
|
|
107
110
|
},
|
|
108
111
|
{
|
|
109
112
|
existingItemHandling: params.existingItemHandling || ExistingItemHandling.AddQuantityToExisting
|
|
@@ -143,7 +146,8 @@ export const getBasket = async function getBasket2(options, context) {
|
|
|
143
146
|
const response = await bapiClient.basket.get(basketKey, {
|
|
144
147
|
with: resolvedWith,
|
|
145
148
|
campaignKey,
|
|
146
|
-
includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData
|
|
149
|
+
includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData,
|
|
150
|
+
orderCustomData: options?.orderCustomData
|
|
147
151
|
});
|
|
148
152
|
if (response.type === "failure") {
|
|
149
153
|
const { statusCode, message } = parseBasketError(response);
|
|
@@ -171,7 +175,8 @@ export const removeItemFromBasket = async function removeItemFromBasket2(options
|
|
|
171
175
|
return await bapiClient.basket.deleteItem(basketKey, options.itemKey, {
|
|
172
176
|
with: resolvedWith,
|
|
173
177
|
campaignKey,
|
|
174
|
-
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData
|
|
178
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
179
|
+
orderCustomData: options.orderCustomData
|
|
175
180
|
});
|
|
176
181
|
};
|
|
177
182
|
export const clearBasket = async function clearBasket2(context) {
|
|
@@ -188,7 +193,7 @@ export const clearBasket = async function clearBasket2(context) {
|
|
|
188
193
|
context.log.debug("The basket has been cleared");
|
|
189
194
|
return true;
|
|
190
195
|
};
|
|
191
|
-
export const mergeBaskets = async function mergeBaskets2({ fromBasketKey, toBasketKey, with: _with }, context) {
|
|
196
|
+
export const mergeBaskets = async function mergeBaskets2({ fromBasketKey, toBasketKey, with: _with, orderCustomData }, context) {
|
|
192
197
|
const resolvedWith = getWithParams(
|
|
193
198
|
{ with: _with },
|
|
194
199
|
context
|
|
@@ -196,7 +201,7 @@ export const mergeBaskets = async function mergeBaskets2({ fromBasketKey, toBask
|
|
|
196
201
|
return await mergeBasketFunction(
|
|
197
202
|
fromBasketKey,
|
|
198
203
|
toBasketKey,
|
|
199
|
-
resolvedWith,
|
|
204
|
+
{ ...resolvedWith, orderCustomData },
|
|
200
205
|
context
|
|
201
206
|
);
|
|
202
207
|
};
|
|
@@ -33,7 +33,7 @@ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutTo
|
|
|
33
33
|
carrier,
|
|
34
34
|
basketId: context.basketKey,
|
|
35
35
|
campaignKey: context.campaignKey
|
|
36
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.64.
|
|
36
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.64.4"}`).setProtectedHeader({
|
|
37
37
|
alg: "HS256",
|
|
38
38
|
typ: "JWT"
|
|
39
39
|
}).sign(secret);
|
|
@@ -27,7 +27,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
|
|
|
27
27
|
carrier,
|
|
28
28
|
basketId: context.basketKey,
|
|
29
29
|
campaignKey: context.campaignKey
|
|
30
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.64.
|
|
30
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.64.4"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
31
31
|
return {
|
|
32
32
|
accessToken: refreshedAccessToken,
|
|
33
33
|
checkoutJwt
|
package/dist/utils/user.cjs
CHANGED
|
@@ -12,7 +12,8 @@ const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, context) =>
|
|
|
12
12
|
} = context;
|
|
13
13
|
const fromOriginBasket = await bapiClient.basket.get(fromBasketKey, {
|
|
14
14
|
with: withOptions,
|
|
15
|
-
campaignKey
|
|
15
|
+
campaignKey,
|
|
16
|
+
orderCustomData: withOptions.orderCustomData
|
|
16
17
|
});
|
|
17
18
|
context.log.debug(`Merging basket ${fromBasketKey} to ${toBasketKey}`);
|
|
18
19
|
if (fromBasketKey === toBasketKey) {
|
|
@@ -37,7 +38,8 @@ const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, context) =>
|
|
|
37
38
|
const mergedBasket = await bapiClient.basket.addOrUpdateItems(toBasketKey, itemsToAddOrUpdate, {
|
|
38
39
|
with: withOptions,
|
|
39
40
|
campaignKey,
|
|
40
|
-
includeItemsWithoutProductData: withOptions?.includeItemsWithoutProductData
|
|
41
|
+
includeItemsWithoutProductData: withOptions?.includeItemsWithoutProductData,
|
|
42
|
+
orderCustomData: withOptions.orderCustomData
|
|
41
43
|
}, {
|
|
42
44
|
existingItemHandling: _constants.ExistingItemHandling.AddQuantityToExisting
|
|
43
45
|
});
|
package/dist/utils/user.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { BasketWithOptions, RpcContext } from '../types';
|
|
2
|
-
export declare const mergeBaskets: (fromBasketKey: string, toBasketKey: string, withOptions: BasketWithOptions
|
|
2
|
+
export declare const mergeBaskets: (fromBasketKey: string, toBasketKey: string, withOptions: BasketWithOptions & {
|
|
3
|
+
orderCustomData?: Record<string, unknown>;
|
|
4
|
+
}, context: RpcContext) => Promise<{
|
|
3
5
|
type: "failure";
|
|
4
6
|
statusCode: number;
|
|
5
7
|
basket: import("@scayle/storefront-api").BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
|
package/dist/utils/user.mjs
CHANGED
|
@@ -3,7 +3,8 @@ export const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, cont
|
|
|
3
3
|
const { bapiClient, campaignKey } = context;
|
|
4
4
|
const fromOriginBasket = await bapiClient.basket.get(fromBasketKey, {
|
|
5
5
|
with: withOptions,
|
|
6
|
-
campaignKey
|
|
6
|
+
campaignKey,
|
|
7
|
+
orderCustomData: withOptions.orderCustomData
|
|
7
8
|
});
|
|
8
9
|
context.log.debug(`Merging basket ${fromBasketKey} to ${toBasketKey}`);
|
|
9
10
|
if (fromBasketKey === toBasketKey) {
|
|
@@ -28,7 +29,8 @@ export const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, cont
|
|
|
28
29
|
{
|
|
29
30
|
with: withOptions,
|
|
30
31
|
campaignKey,
|
|
31
|
-
includeItemsWithoutProductData: withOptions?.includeItemsWithoutProductData
|
|
32
|
+
includeItemsWithoutProductData: withOptions?.includeItemsWithoutProductData,
|
|
33
|
+
orderCustomData: withOptions.orderCustomData
|
|
32
34
|
},
|
|
33
35
|
{
|
|
34
36
|
existingItemHandling: ExistingItemHandling.AddQuantityToExisting
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "7.64.
|
|
3
|
+
"version": "7.64.4",
|
|
4
4
|
"description": "Collection of essential utilities to work with the Storefront API",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,11 +59,10 @@
|
|
|
59
59
|
"test:ci": "vitest --run --passWithNoTests --coverage --reporter=default --reporter=junit"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@scayle/storefront-api": "17.
|
|
62
|
+
"@scayle/storefront-api": "17.6.0",
|
|
63
63
|
"crypto-js": "^4.2.0",
|
|
64
64
|
"hookable": "^5.5.3",
|
|
65
65
|
"jose": "^5.6.3",
|
|
66
|
-
"radash": "^12.1.0",
|
|
67
66
|
"slugify": "^1.6.6",
|
|
68
67
|
"ufo": "^1.5.3",
|
|
69
68
|
"uncrypto": "^0.1.3",
|
|
@@ -72,18 +71,18 @@
|
|
|
72
71
|
"devDependencies": {
|
|
73
72
|
"@scayle/eslint-config-storefront": "4.3.0",
|
|
74
73
|
"@types/crypto-js": "4.2.2",
|
|
75
|
-
"@types/node": "20.
|
|
74
|
+
"@types/node": "20.16.5",
|
|
76
75
|
"@types/webpack-env": "1.18.5",
|
|
77
76
|
"@vitest/coverage-v8": "2.0.5",
|
|
78
77
|
"dprint": "0.47.2",
|
|
79
|
-
"eslint": "9.
|
|
78
|
+
"eslint": "9.10.0",
|
|
80
79
|
"eslint-formatter-gitlab": "5.1.0",
|
|
81
80
|
"publint": "0.2.10",
|
|
82
81
|
"rimraf": "6.0.1",
|
|
83
82
|
"ts-node": "10.9.2",
|
|
84
|
-
"typescript": "5.
|
|
83
|
+
"typescript": "5.6.2",
|
|
85
84
|
"unbuild": "2.0.0",
|
|
86
|
-
"unstorage": "1.
|
|
85
|
+
"unstorage": "1.12.0",
|
|
87
86
|
"vitest": "2.0.5"
|
|
88
87
|
},
|
|
89
88
|
"optionalDependencies": {
|