@scayle/storefront-core 7.48.2 → 7.49.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/api/customer.d.ts +1 -1
- package/dist/cache/cache.d.ts +2 -2
- package/dist/cache/cached.d.ts +2 -2
- package/dist/cache/providers/redis.d.ts +3 -3
- package/dist/cache/providers/unstorage.d.ts +1 -1
- package/dist/constants/basket.d.ts +1 -1
- package/dist/constants/hash.d.ts +1 -1
- package/dist/constants/httpStatus.d.ts +1 -1
- package/dist/constants/product.d.ts +1 -1
- package/dist/constants/promotion.d.ts +1 -1
- package/dist/constants/sorting.d.ts +1 -1
- package/dist/constants/withParameters.d.ts +1 -1
- package/dist/errors/baseError.d.ts +1 -1
- package/dist/helpers/advancedAttributeHelpers.cjs +9 -5
- package/dist/helpers/advancedAttributeHelpers.d.ts +7 -3
- package/dist/helpers/advancedAttributeHelpers.mjs +7 -4
- package/dist/helpers/categoryHelper.d.ts +1 -1
- package/dist/helpers/filterHelper.cjs +22 -22
- package/dist/helpers/filterHelper.d.ts +3 -3
- package/dist/helpers/filterHelper.mjs +20 -20
- package/dist/helpers/imageHelpers.d.ts +2 -2
- package/dist/helpers/orderHelpers.d.ts +1 -1
- package/dist/helpers/productDisruptorHelper.d.ts +1 -1
- package/dist/helpers/productHelpers.cjs +2 -2
- package/dist/helpers/productHelpers.d.ts +3 -3
- package/dist/helpers/productHelpers.mjs +4 -2
- package/dist/rpc/methods/basket/basket.cjs +1 -1
- package/dist/rpc/methods/basket/basket.d.ts +2 -2
- package/dist/rpc/methods/basket/basket.mjs +2 -4
- package/dist/rpc/methods/brands.d.ts +1 -1
- package/dist/rpc/methods/categories.d.ts +1 -1
- package/dist/rpc/methods/checkout/order.d.ts +1 -1
- package/dist/rpc/methods/checkout/shopUser.d.ts +1 -1
- package/dist/rpc/methods/navigationTrees.d.ts +1 -1
- package/dist/rpc/methods/products.cjs +107 -107
- package/dist/rpc/methods/products.d.ts +10 -10
- package/dist/rpc/methods/products.mjs +92 -92
- package/dist/rpc/methods/promotion.d.ts +1 -1
- package/dist/rpc/methods/search.cjs +10 -10
- package/dist/rpc/methods/search.d.ts +1 -1
- package/dist/rpc/methods/search.mjs +10 -10
- package/dist/rpc/methods/shopConfiguration.d.ts +2 -2
- package/dist/rpc/methods/variants.d.ts +1 -1
- package/dist/rpc/methods/wishlist.cjs +16 -16
- package/dist/rpc/methods/wishlist.d.ts +1 -1
- package/dist/rpc/methods/wishlist.mjs +10 -10
- package/dist/types/api/context.d.ts +2 -2
- package/dist/types/api/rpc.d.ts +1 -1
- package/dist/types/bapi/order.d.ts +2 -0
- package/dist/types/bapi/search.d.ts +7 -7
- package/dist/types/user.d.ts +6 -6
- package/dist/utils/compression.mjs +1 -1
- package/dist/utils/log.d.ts +1 -1
- package/dist/utils/user.d.ts +1 -1
- package/package.json +5 -5
|
@@ -9,6 +9,18 @@ var _constants = require("../../constants/index.cjs");
|
|
|
9
9
|
var _cache = require("../../cache/index.cjs");
|
|
10
10
|
var _response = require("../../utils/response.cjs");
|
|
11
11
|
const MAX_PER_PAGE = 100;
|
|
12
|
+
const sanitizeAttributesForBAPI = ({
|
|
13
|
+
attributes,
|
|
14
|
+
filterKeys,
|
|
15
|
+
includedFilters = []
|
|
16
|
+
}) => {
|
|
17
|
+
return attributes.filter(({
|
|
18
|
+
key
|
|
19
|
+
}) => key && filterKeys.includes(key.toLowerCase()) && !includedFilters?.includes(key.toLowerCase()));
|
|
20
|
+
};
|
|
21
|
+
const mapFiltersToSlugs = (filters = []) => filters.map(({
|
|
22
|
+
slug
|
|
23
|
+
}) => slug.toLowerCase());
|
|
12
24
|
const getProductById = exports.getProductById = async function getProductById2(options, {
|
|
13
25
|
bapiClient,
|
|
14
26
|
cached,
|
|
@@ -55,73 +67,71 @@ const getProductsByReferenceKeys = exports.getProductsByReferenceKeys = async fu
|
|
|
55
67
|
pricePromotionKey: options.pricePromotionKey
|
|
56
68
|
});
|
|
57
69
|
};
|
|
58
|
-
const
|
|
70
|
+
const getProductsCount = exports.getProductsCount = async function getProductsCount2({
|
|
59
71
|
category = "/",
|
|
60
|
-
|
|
61
|
-
with: _with,
|
|
62
|
-
perPage = 20,
|
|
63
|
-
page = 1,
|
|
72
|
+
categoryId = void 0,
|
|
64
73
|
where = void 0,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
includeSellableForFree = void 0,
|
|
68
|
-
includeSoldOut = void 0,
|
|
74
|
+
includeSoldOut = false,
|
|
75
|
+
includeSellableForFree = false,
|
|
69
76
|
orFiltersOperator = void 0
|
|
70
|
-
},
|
|
77
|
+
}, {
|
|
78
|
+
cached,
|
|
79
|
+
bapiClient,
|
|
80
|
+
campaignKey
|
|
81
|
+
}) {
|
|
71
82
|
let result;
|
|
72
|
-
const {
|
|
73
|
-
cached,
|
|
74
|
-
bapiClient,
|
|
75
|
-
campaignKey
|
|
76
|
-
} = context;
|
|
77
83
|
if (category !== "/") {
|
|
84
|
+
const sanitizedPath = (0, _helpers.splitAndRemoveEmpty)(category);
|
|
78
85
|
result = await cached(bapiClient.categories.getByPath, {
|
|
79
|
-
cacheKeyPrefix: `getByPath-categories-${
|
|
80
|
-
})(
|
|
86
|
+
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
87
|
+
})(sanitizedPath);
|
|
81
88
|
}
|
|
82
|
-
const {
|
|
83
|
-
filters
|
|
84
|
-
} = await (0, _response.unwrap)(getFilters({
|
|
85
|
-
category,
|
|
86
|
-
includeSoldOut,
|
|
87
|
-
where,
|
|
88
|
-
includeSellableForFree
|
|
89
|
-
}, context));
|
|
90
|
-
const {
|
|
91
|
-
entities: products,
|
|
92
|
-
pagination
|
|
93
|
-
} = await cached(bapiClient.products.query, {
|
|
94
|
-
...cache,
|
|
89
|
+
const productCount = await cached(bapiClient.products.query, {
|
|
95
90
|
ttl: 15 * _cache.MINUTE,
|
|
96
|
-
cacheKeyPrefix:
|
|
91
|
+
cacheKeyPrefix: "products-query"
|
|
97
92
|
})({
|
|
98
93
|
where: {
|
|
99
|
-
|
|
100
|
-
categoryId: result?.id,
|
|
94
|
+
categoryId: categoryId ?? result?.id,
|
|
101
95
|
minPrice: where?.minPrice,
|
|
102
96
|
maxPrice: where?.maxPrice,
|
|
103
|
-
attributes:
|
|
104
|
-
|
|
105
|
-
filterKeys: mapFiltersToSlugs(filters)
|
|
106
|
-
}), ...(where?.whitelistAttributes || [])],
|
|
107
|
-
disableFuzziness: where?.disableFuzziness
|
|
97
|
+
attributes: where?.attributes,
|
|
98
|
+
term: where?.term
|
|
108
99
|
},
|
|
100
|
+
includeSoldOut,
|
|
101
|
+
includeSellableForFree,
|
|
102
|
+
campaignKey,
|
|
109
103
|
pagination: {
|
|
110
|
-
perPage:
|
|
111
|
-
page
|
|
104
|
+
perPage: 1
|
|
112
105
|
},
|
|
113
|
-
campaignKey,
|
|
114
|
-
pricePromotionKey,
|
|
115
|
-
includeSellableForFree,
|
|
116
|
-
includeSoldOut,
|
|
117
|
-
with: _with ?? context.withParams?.product ?? _constants.MIN_WITH_PARAMS_PRODUCT,
|
|
118
|
-
sort,
|
|
119
106
|
orFiltersOperator
|
|
120
107
|
});
|
|
121
108
|
return {
|
|
122
|
-
|
|
123
|
-
|
|
109
|
+
count: productCount?.pagination.total
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
const fetchAllFiltersForCategory = exports.fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({
|
|
113
|
+
includedFilters = [],
|
|
114
|
+
category
|
|
115
|
+
}, {
|
|
116
|
+
cached,
|
|
117
|
+
bapiClient,
|
|
118
|
+
campaignKey
|
|
119
|
+
}) {
|
|
120
|
+
const fetchAndMapFiltersToSlugs = async () => {
|
|
121
|
+
const filtersFromBAPI = await cached(bapiClient.filters.get)({
|
|
122
|
+
where: {
|
|
123
|
+
categoryId: category.id
|
|
124
|
+
},
|
|
125
|
+
campaignKey,
|
|
126
|
+
including: includedFilters
|
|
127
|
+
});
|
|
128
|
+
return mapFiltersToSlugs(filtersFromBAPI);
|
|
124
129
|
};
|
|
130
|
+
return await cached(fetchAndMapFiltersToSlugs, {
|
|
131
|
+
ttl: 4 * 60 * 60,
|
|
132
|
+
// cached for 4 hours
|
|
133
|
+
cacheKey: `filters-for-category-${category.slug}`
|
|
134
|
+
})();
|
|
125
135
|
};
|
|
126
136
|
const getFilters = exports.getFilters = async function getFilters2({
|
|
127
137
|
category = "/",
|
|
@@ -193,81 +203,71 @@ const getFilters = exports.getFilters = async function getFilters2({
|
|
|
193
203
|
unfilteredCount: productCount?.pagination.total
|
|
194
204
|
};
|
|
195
205
|
};
|
|
196
|
-
const
|
|
197
|
-
includedFilters = [],
|
|
198
|
-
category
|
|
199
|
-
}, {
|
|
200
|
-
cached,
|
|
201
|
-
bapiClient,
|
|
202
|
-
campaignKey
|
|
203
|
-
}) {
|
|
204
|
-
const fetchAndMapFiltersToSlugs = async () => {
|
|
205
|
-
const filtersFromBAPI = await cached(bapiClient.filters.get)({
|
|
206
|
-
where: {
|
|
207
|
-
categoryId: category.id
|
|
208
|
-
},
|
|
209
|
-
campaignKey,
|
|
210
|
-
including: includedFilters
|
|
211
|
-
});
|
|
212
|
-
return mapFiltersToSlugs(filtersFromBAPI);
|
|
213
|
-
};
|
|
214
|
-
return await cached(fetchAndMapFiltersToSlugs, {
|
|
215
|
-
ttl: 4 * 60 * 60,
|
|
216
|
-
// cached for 4 hours
|
|
217
|
-
cacheKey: `filters-for-category-${category.slug}`
|
|
218
|
-
})();
|
|
219
|
-
};
|
|
220
|
-
const getProductsCount = exports.getProductsCount = async function getProductsCount2({
|
|
206
|
+
const getProductsByCategory = exports.getProductsByCategory = async function getProductsByCategory2({
|
|
221
207
|
category = "/",
|
|
222
|
-
|
|
208
|
+
cache,
|
|
209
|
+
with: _with,
|
|
210
|
+
perPage = 20,
|
|
211
|
+
page = 1,
|
|
223
212
|
where = void 0,
|
|
224
|
-
|
|
225
|
-
|
|
213
|
+
sort = void 0,
|
|
214
|
+
pricePromotionKey = "",
|
|
215
|
+
includeSellableForFree = void 0,
|
|
216
|
+
includeSoldOut = void 0,
|
|
226
217
|
orFiltersOperator = void 0
|
|
227
|
-
}, {
|
|
228
|
-
cached,
|
|
229
|
-
bapiClient,
|
|
230
|
-
campaignKey
|
|
231
|
-
}) {
|
|
218
|
+
}, context) {
|
|
232
219
|
let result;
|
|
220
|
+
const {
|
|
221
|
+
cached,
|
|
222
|
+
bapiClient,
|
|
223
|
+
campaignKey
|
|
224
|
+
} = context;
|
|
233
225
|
if (category !== "/") {
|
|
234
|
-
const sanitizedPath = (0, _helpers.splitAndRemoveEmpty)(category);
|
|
235
226
|
result = await cached(bapiClient.categories.getByPath, {
|
|
236
|
-
cacheKeyPrefix: `getByPath-categories-${
|
|
237
|
-
})(
|
|
227
|
+
cacheKeyPrefix: `getByPath-categories-${category}`
|
|
228
|
+
})((0, _helpers.splitAndRemoveEmpty)(category));
|
|
238
229
|
}
|
|
239
|
-
const
|
|
230
|
+
const {
|
|
231
|
+
filters
|
|
232
|
+
} = await (0, _response.unwrap)(getFilters({
|
|
233
|
+
category,
|
|
234
|
+
includeSoldOut,
|
|
235
|
+
where,
|
|
236
|
+
includeSellableForFree
|
|
237
|
+
}, context));
|
|
238
|
+
const {
|
|
239
|
+
entities: products,
|
|
240
|
+
pagination
|
|
241
|
+
} = await cached(bapiClient.products.query, {
|
|
242
|
+
...cache,
|
|
240
243
|
ttl: 15 * _cache.MINUTE,
|
|
241
|
-
cacheKeyPrefix:
|
|
244
|
+
cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : category}`
|
|
242
245
|
})({
|
|
243
246
|
where: {
|
|
244
|
-
|
|
247
|
+
term: where?.term,
|
|
248
|
+
categoryId: result?.id,
|
|
245
249
|
minPrice: where?.minPrice,
|
|
246
250
|
maxPrice: where?.maxPrice,
|
|
247
|
-
attributes:
|
|
248
|
-
|
|
251
|
+
attributes: [...sanitizeAttributesForBAPI({
|
|
252
|
+
attributes: where?.attributes || [],
|
|
253
|
+
filterKeys: mapFiltersToSlugs(filters)
|
|
254
|
+
}), ...(where?.whitelistAttributes || [])],
|
|
255
|
+
disableFuzziness: where?.disableFuzziness
|
|
249
256
|
},
|
|
250
|
-
includeSoldOut,
|
|
251
|
-
includeSellableForFree,
|
|
252
|
-
campaignKey,
|
|
253
257
|
pagination: {
|
|
254
|
-
perPage:
|
|
258
|
+
perPage: Math.min(perPage, MAX_PER_PAGE),
|
|
259
|
+
page
|
|
255
260
|
},
|
|
261
|
+
campaignKey,
|
|
262
|
+
pricePromotionKey,
|
|
263
|
+
includeSellableForFree,
|
|
264
|
+
includeSoldOut,
|
|
265
|
+
with: _with ?? context.withParams?.product ?? _constants.MIN_WITH_PARAMS_PRODUCT,
|
|
266
|
+
sort,
|
|
256
267
|
orFiltersOperator
|
|
257
268
|
});
|
|
258
269
|
return {
|
|
259
|
-
|
|
270
|
+
products,
|
|
271
|
+
pagination
|
|
260
272
|
};
|
|
261
|
-
};
|
|
262
|
-
const sanitizeAttributesForBAPI = ({
|
|
263
|
-
attributes,
|
|
264
|
-
filterKeys,
|
|
265
|
-
includedFilters = []
|
|
266
|
-
}) => {
|
|
267
|
-
return attributes.filter(({
|
|
268
|
-
key
|
|
269
|
-
}) => key && filterKeys.includes(key.toLowerCase()) && !includedFilters?.includes(key.toLowerCase()));
|
|
270
|
-
};
|
|
271
|
-
const mapFiltersToSlugs = (filters = []) => filters.map(({
|
|
272
|
-
slug
|
|
273
|
-
}) => slug.toLowerCase());
|
|
273
|
+
};
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import type { FiltersEndpointResponseData } from '@aboutyou/backbone/endpoints/filters/filters';
|
|
2
|
-
import { FetchFiltersParams, FetchProductParams, FetchProductsByCategoryParams, FetchProductsByIdsParams, FetchProductsByReferenceKeysParams, FetchProductsCountParams, Product, RpcContext } from '../../types';
|
|
2
|
+
import type { FetchFiltersParams, FetchProductParams, FetchProductsByCategoryParams, FetchProductsByIdsParams, FetchProductsByReferenceKeysParams, FetchProductsCountParams, Product, RpcContext } from '../../types';
|
|
3
3
|
export declare const getProductById: (options: FetchProductParams, { bapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Product>;
|
|
4
4
|
export declare const getProductsByIds: (options: FetchProductsByIdsParams, { bapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Product[]>;
|
|
5
5
|
export declare const getProductsByReferenceKeys: (options: FetchProductsByReferenceKeysParams, { bapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Product[]>;
|
|
6
|
-
export declare const
|
|
7
|
-
|
|
8
|
-
pagination: import("@aboutyou/backbone/endpoints/products/productsByIds").Pagination;
|
|
9
|
-
}>;
|
|
10
|
-
export declare const getFilters: ({ category, includedFilters, where, includeSoldOut, includeSellableForFree, orFiltersOperator, }: FetchFiltersParams, context: RpcContext) => Promise<{
|
|
11
|
-
filters: FiltersEndpointResponseData;
|
|
12
|
-
unfilteredCount: number;
|
|
6
|
+
export declare const getProductsCount: ({ category, categoryId, where, includeSoldOut, includeSellableForFree, orFiltersOperator, }: FetchProductsCountParams, { cached, bapiClient, campaignKey }: RpcContext) => Promise<{
|
|
7
|
+
count: number;
|
|
13
8
|
}>;
|
|
14
9
|
export declare const fetchAllFiltersForCategory: ({ includedFilters, category }: {
|
|
15
10
|
includedFilters?: string[] | undefined;
|
|
@@ -18,6 +13,11 @@ export declare const fetchAllFiltersForCategory: ({ includedFilters, category }:
|
|
|
18
13
|
id: number;
|
|
19
14
|
};
|
|
20
15
|
}, { cached, bapiClient, campaignKey }: RpcContext) => Promise<string[]>;
|
|
21
|
-
export declare const
|
|
22
|
-
|
|
16
|
+
export declare const getFilters: ({ category, includedFilters, where, includeSoldOut, includeSellableForFree, orFiltersOperator, }: FetchFiltersParams, context: RpcContext) => Promise<{
|
|
17
|
+
filters: FiltersEndpointResponseData;
|
|
18
|
+
unfilteredCount: number;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const getProductsByCategory: ({ category, cache, with: _with, perPage, page, where, sort, pricePromotionKey, includeSellableForFree, includeSoldOut, orFiltersOperator, }: FetchProductsByCategoryParams, context: RpcContext) => Promise<{
|
|
21
|
+
products: Product[];
|
|
22
|
+
pagination: import("@aboutyou/backbone/endpoints/products/productsByIds").Pagination;
|
|
23
23
|
}>;
|
|
@@ -3,6 +3,16 @@ import { MIN_WITH_PARAMS_PRODUCT } from "../../constants/index.mjs";
|
|
|
3
3
|
import { MINUTE } from "../../cache/index.mjs";
|
|
4
4
|
import { unwrap } from "../../utils/response.mjs";
|
|
5
5
|
const MAX_PER_PAGE = 100;
|
|
6
|
+
const sanitizeAttributesForBAPI = ({
|
|
7
|
+
attributes,
|
|
8
|
+
filterKeys,
|
|
9
|
+
includedFilters = []
|
|
10
|
+
}) => {
|
|
11
|
+
return attributes.filter(
|
|
12
|
+
({ key }) => key && filterKeys.includes(key.toLowerCase()) && !includedFilters?.includes(key.toLowerCase())
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
const mapFiltersToSlugs = (filters = []) => filters.map(({ slug }) => slug.toLowerCase());
|
|
6
16
|
export const getProductById = async function getProductById2(options, { bapiClient, cached, campaignKey, withParams }) {
|
|
7
17
|
return await cached(bapiClient.products.getById, {
|
|
8
18
|
cacheKeyPrefix: `getById-product-${options.id}`,
|
|
@@ -34,71 +44,59 @@ export const getProductsByReferenceKeys = async function getProductsByReferenceK
|
|
|
34
44
|
pricePromotionKey: options.pricePromotionKey
|
|
35
45
|
});
|
|
36
46
|
};
|
|
37
|
-
export const
|
|
47
|
+
export const getProductsCount = async function getProductsCount2({
|
|
38
48
|
category = "/",
|
|
39
|
-
|
|
40
|
-
with: _with,
|
|
41
|
-
perPage = 20,
|
|
42
|
-
page = 1,
|
|
49
|
+
categoryId = void 0,
|
|
43
50
|
where = void 0,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
includeSellableForFree = void 0,
|
|
47
|
-
includeSoldOut = void 0,
|
|
51
|
+
includeSoldOut = false,
|
|
52
|
+
includeSellableForFree = false,
|
|
48
53
|
orFiltersOperator = void 0
|
|
49
|
-
},
|
|
54
|
+
}, { cached, bapiClient, campaignKey }) {
|
|
50
55
|
let result;
|
|
51
|
-
const { cached, bapiClient, campaignKey } = context;
|
|
52
56
|
if (category !== "/") {
|
|
57
|
+
const sanitizedPath = splitAndRemoveEmpty(category);
|
|
53
58
|
result = await cached(bapiClient.categories.getByPath, {
|
|
54
|
-
cacheKeyPrefix: `getByPath-categories-${
|
|
55
|
-
})(
|
|
59
|
+
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
60
|
+
})(sanitizedPath);
|
|
56
61
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
const { entities: products, pagination } = await cached(
|
|
64
|
-
bapiClient.products.query,
|
|
65
|
-
{
|
|
66
|
-
...cache,
|
|
67
|
-
ttl: 15 * MINUTE,
|
|
68
|
-
cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : category}`
|
|
69
|
-
}
|
|
70
|
-
)({
|
|
62
|
+
const productCount = await cached(bapiClient.products.query, {
|
|
63
|
+
ttl: 15 * MINUTE,
|
|
64
|
+
cacheKeyPrefix: "products-query"
|
|
65
|
+
})({
|
|
71
66
|
where: {
|
|
72
|
-
|
|
73
|
-
categoryId: result?.id,
|
|
67
|
+
categoryId: categoryId ?? result?.id,
|
|
74
68
|
minPrice: where?.minPrice,
|
|
75
69
|
maxPrice: where?.maxPrice,
|
|
76
|
-
attributes:
|
|
77
|
-
|
|
78
|
-
attributes: where?.attributes || [],
|
|
79
|
-
filterKeys: mapFiltersToSlugs(filters)
|
|
80
|
-
}),
|
|
81
|
-
...where?.whitelistAttributes || []
|
|
82
|
-
],
|
|
83
|
-
disableFuzziness: where?.disableFuzziness
|
|
70
|
+
attributes: where?.attributes,
|
|
71
|
+
term: where?.term
|
|
84
72
|
},
|
|
73
|
+
includeSoldOut,
|
|
74
|
+
includeSellableForFree,
|
|
75
|
+
campaignKey,
|
|
85
76
|
pagination: {
|
|
86
|
-
perPage:
|
|
87
|
-
page
|
|
77
|
+
perPage: 1
|
|
88
78
|
},
|
|
89
|
-
campaignKey,
|
|
90
|
-
pricePromotionKey,
|
|
91
|
-
includeSellableForFree,
|
|
92
|
-
includeSoldOut,
|
|
93
|
-
with: _with ?? context.withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
94
|
-
sort,
|
|
95
79
|
orFiltersOperator
|
|
96
80
|
});
|
|
97
81
|
return {
|
|
98
|
-
|
|
99
|
-
pagination
|
|
82
|
+
count: productCount?.pagination.total
|
|
100
83
|
};
|
|
101
84
|
};
|
|
85
|
+
export const fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({ includedFilters = [], category }, { cached, bapiClient, campaignKey }) {
|
|
86
|
+
const fetchAndMapFiltersToSlugs = async () => {
|
|
87
|
+
const filtersFromBAPI = await cached(bapiClient.filters.get)({
|
|
88
|
+
where: { categoryId: category.id },
|
|
89
|
+
campaignKey,
|
|
90
|
+
including: includedFilters
|
|
91
|
+
});
|
|
92
|
+
return mapFiltersToSlugs(filtersFromBAPI);
|
|
93
|
+
};
|
|
94
|
+
return await cached(fetchAndMapFiltersToSlugs, {
|
|
95
|
+
ttl: 4 * 60 * 60,
|
|
96
|
+
// cached for 4 hours
|
|
97
|
+
cacheKey: `filters-for-category-${category.slug}`
|
|
98
|
+
})();
|
|
99
|
+
};
|
|
102
100
|
export const getFilters = async function getFilters2({
|
|
103
101
|
category = "/",
|
|
104
102
|
includedFilters,
|
|
@@ -173,66 +171,68 @@ export const getFilters = async function getFilters2({
|
|
|
173
171
|
unfilteredCount: productCount?.pagination.total
|
|
174
172
|
};
|
|
175
173
|
};
|
|
176
|
-
export const
|
|
177
|
-
const fetchAndMapFiltersToSlugs = async () => {
|
|
178
|
-
const filtersFromBAPI = await cached(bapiClient.filters.get)({
|
|
179
|
-
where: { categoryId: category.id },
|
|
180
|
-
campaignKey,
|
|
181
|
-
including: includedFilters
|
|
182
|
-
});
|
|
183
|
-
return mapFiltersToSlugs(filtersFromBAPI);
|
|
184
|
-
};
|
|
185
|
-
return await cached(fetchAndMapFiltersToSlugs, {
|
|
186
|
-
ttl: 4 * 60 * 60,
|
|
187
|
-
// cached for 4 hours
|
|
188
|
-
cacheKey: `filters-for-category-${category.slug}`
|
|
189
|
-
})();
|
|
190
|
-
};
|
|
191
|
-
export const getProductsCount = async function getProductsCount2({
|
|
174
|
+
export const getProductsByCategory = async function getProductsByCategory2({
|
|
192
175
|
category = "/",
|
|
193
|
-
|
|
176
|
+
cache,
|
|
177
|
+
with: _with,
|
|
178
|
+
perPage = 20,
|
|
179
|
+
page = 1,
|
|
194
180
|
where = void 0,
|
|
195
|
-
|
|
196
|
-
|
|
181
|
+
sort = void 0,
|
|
182
|
+
pricePromotionKey = "",
|
|
183
|
+
includeSellableForFree = void 0,
|
|
184
|
+
includeSoldOut = void 0,
|
|
197
185
|
orFiltersOperator = void 0
|
|
198
|
-
},
|
|
186
|
+
}, context) {
|
|
199
187
|
let result;
|
|
188
|
+
const { cached, bapiClient, campaignKey } = context;
|
|
200
189
|
if (category !== "/") {
|
|
201
|
-
const sanitizedPath = splitAndRemoveEmpty(category);
|
|
202
190
|
result = await cached(bapiClient.categories.getByPath, {
|
|
203
|
-
cacheKeyPrefix: `getByPath-categories-${
|
|
204
|
-
})(
|
|
191
|
+
cacheKeyPrefix: `getByPath-categories-${category}`
|
|
192
|
+
})(splitAndRemoveEmpty(category));
|
|
205
193
|
}
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
194
|
+
const { filters } = await unwrap(
|
|
195
|
+
getFilters(
|
|
196
|
+
{ category, includeSoldOut, where, includeSellableForFree },
|
|
197
|
+
context
|
|
198
|
+
)
|
|
199
|
+
);
|
|
200
|
+
const { entities: products, pagination } = await cached(
|
|
201
|
+
bapiClient.products.query,
|
|
202
|
+
{
|
|
203
|
+
...cache,
|
|
204
|
+
ttl: 15 * MINUTE,
|
|
205
|
+
cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : category}`
|
|
206
|
+
}
|
|
207
|
+
)({
|
|
210
208
|
where: {
|
|
211
|
-
|
|
209
|
+
term: where?.term,
|
|
210
|
+
categoryId: result?.id,
|
|
212
211
|
minPrice: where?.minPrice,
|
|
213
212
|
maxPrice: where?.maxPrice,
|
|
214
|
-
attributes:
|
|
215
|
-
|
|
213
|
+
attributes: [
|
|
214
|
+
...sanitizeAttributesForBAPI({
|
|
215
|
+
attributes: where?.attributes || [],
|
|
216
|
+
filterKeys: mapFiltersToSlugs(filters)
|
|
217
|
+
}),
|
|
218
|
+
...where?.whitelistAttributes || []
|
|
219
|
+
],
|
|
220
|
+
disableFuzziness: where?.disableFuzziness
|
|
216
221
|
},
|
|
217
|
-
includeSoldOut,
|
|
218
|
-
includeSellableForFree,
|
|
219
|
-
campaignKey,
|
|
220
222
|
pagination: {
|
|
221
|
-
perPage:
|
|
223
|
+
perPage: Math.min(perPage, MAX_PER_PAGE),
|
|
224
|
+
page
|
|
222
225
|
},
|
|
226
|
+
campaignKey,
|
|
227
|
+
pricePromotionKey,
|
|
228
|
+
includeSellableForFree,
|
|
229
|
+
includeSoldOut,
|
|
230
|
+
with: _with ?? context.withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
231
|
+
sort,
|
|
223
232
|
orFiltersOperator
|
|
224
233
|
});
|
|
225
234
|
return {
|
|
226
|
-
|
|
235
|
+
products,
|
|
236
|
+
pagination
|
|
227
237
|
};
|
|
228
238
|
};
|
|
229
|
-
const sanitizeAttributesForBAPI = ({
|
|
230
|
-
attributes,
|
|
231
|
-
filterKeys,
|
|
232
|
-
includedFilters = []
|
|
233
|
-
}) => {
|
|
234
|
-
return attributes.filter(
|
|
235
|
-
({ key }) => key && filterKeys.includes(key.toLowerCase()) && !includedFilters?.includes(key.toLowerCase())
|
|
236
|
-
);
|
|
237
|
-
};
|
|
238
|
-
const mapFiltersToSlugs = (filters = []) => filters.map(({ slug }) => slug.toLowerCase());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PromotionsParams, PromotionsResponseData } from '../../types';
|
|
1
|
+
import type { PromotionsParams, PromotionsResponseData } from '../../types';
|
|
2
2
|
export declare const getPromotions: (params: Omit<PromotionsParams, "ids"> | undefined, context: import("../../types").RpcContext) => Promise<PromotionsResponseData>;
|
|
3
3
|
export declare const getCurrentPromotions: (params: Omit<PromotionsParams, "ids" | "activeAt"> | undefined, context: import("../../types").RpcContext) => Promise<PromotionsResponseData>;
|
|
4
4
|
export declare const getPromotionsByIds: (ids: string[], context: import("../../types").RpcContext) => Promise<PromotionsResponseData>;
|
|
@@ -6,6 +6,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.searchProducts = exports.resolveSearch = exports.getSearchSuggestions = void 0;
|
|
7
7
|
var _constants = require("../../constants/index.cjs");
|
|
8
8
|
var _stringHelpers = require("../../helpers/stringHelpers.cjs");
|
|
9
|
+
const getCategoryId = async (cached, bapiClient, slug) => {
|
|
10
|
+
if (!slug) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const sanitizedPath = (0, _stringHelpers.splitAndRemoveEmpty)(slug);
|
|
14
|
+
const result = await cached(bapiClient.categories.getByPath, {
|
|
15
|
+
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
16
|
+
})(sanitizedPath);
|
|
17
|
+
return result.id;
|
|
18
|
+
};
|
|
9
19
|
const searchProducts = exports.searchProducts = async function searchProducts2({
|
|
10
20
|
term,
|
|
11
21
|
slug,
|
|
@@ -57,14 +67,4 @@ const resolveSearch = exports.resolveSearch = async function resolveSearch2({
|
|
|
57
67
|
return null;
|
|
58
68
|
}
|
|
59
69
|
return resolvedEntity;
|
|
60
|
-
};
|
|
61
|
-
const getCategoryId = async (cached, bapiClient, slug) => {
|
|
62
|
-
if (!slug) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const sanitizedPath = (0, _stringHelpers.splitAndRemoveEmpty)(slug);
|
|
66
|
-
const result = await cached(bapiClient.categories.getByPath, {
|
|
67
|
-
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
68
|
-
})(sanitizedPath);
|
|
69
|
-
return result.id;
|
|
70
70
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TypeaheadSuggestionsEndpointRequestParameters, TypeaheadSuggestionsEndpointResponseData } from '@aboutyou/backbone/endpoints/typeahead/typeahead';
|
|
2
|
-
import type { SearchV2ResolveEndpointParameters,
|
|
2
|
+
import type { SearchV2ResolveEndpointParameters, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/bapi/search';
|
|
3
3
|
type SearchWith = TypeaheadSuggestionsEndpointRequestParameters['with'];
|
|
4
4
|
/** @deprecated `searchProducts` is deprecated. Please, use `getSuggestions` or `resolve` RPC methods */
|
|
5
5
|
export declare const searchProducts: ({ term, slug, with: _with, productLimit }: {
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { MIN_WITH_PARAMS_SEARCH } from "../../constants/index.mjs";
|
|
2
2
|
import { splitAndRemoveEmpty } from "../../helpers/stringHelpers.mjs";
|
|
3
|
+
const getCategoryId = async (cached, bapiClient, slug) => {
|
|
4
|
+
if (!slug) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const sanitizedPath = splitAndRemoveEmpty(slug);
|
|
8
|
+
const result = await cached(bapiClient.categories.getByPath, {
|
|
9
|
+
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
10
|
+
})(sanitizedPath);
|
|
11
|
+
return result.id;
|
|
12
|
+
};
|
|
3
13
|
export const searchProducts = async function searchProducts2({ term, slug, with: _with, productLimit }, { cached, bapiClient, withParams }) {
|
|
4
14
|
const categoryId = await getCategoryId(cached, bapiClient, slug);
|
|
5
15
|
return await cached(bapiClient.typeahead.suggestions, {
|
|
@@ -31,13 +41,3 @@ export const resolveSearch = async function resolveSearch2({ term, with: _with,
|
|
|
31
41
|
}
|
|
32
42
|
return resolvedEntity;
|
|
33
43
|
};
|
|
34
|
-
const getCategoryId = async (cached, bapiClient, slug) => {
|
|
35
|
-
if (!slug) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const sanitizedPath = splitAndRemoveEmpty(slug);
|
|
39
|
-
const result = await cached(bapiClient.categories.getByPath, {
|
|
40
|
-
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
41
|
-
})(sanitizedPath);
|
|
42
|
-
return result.id;
|
|
43
|
-
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ShopConfigurationResponseData } from '@aboutyou/backbone/endpoints/shopconfiguration/shopconfiguration';
|
|
2
|
-
import { RpcContext } from '../../types';
|
|
1
|
+
import type { ShopConfigurationResponseData } from '@aboutyou/backbone/endpoints/shopconfiguration/shopconfiguration';
|
|
2
|
+
import type { RpcContext } from '../../types';
|
|
3
3
|
declare const getShopConfiguration: ({ cached, bapiClient }: RpcContext) => Promise<ShopConfigurationResponseData>;
|
|
4
4
|
export { getShopConfiguration };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProductWith } from '@aboutyou/backbone';
|
|
2
2
|
import type { VariantDetail } from '@aboutyou/backbone/endpoints/variants/variantsByIds';
|
|
3
|
-
import { RpcContext } from '../../types';
|
|
3
|
+
import type { RpcContext } from '../../types';
|
|
4
4
|
export interface FetchVariantsParams {
|
|
5
5
|
ids: number[];
|
|
6
6
|
include?: ProductWith;
|
|
@@ -10,6 +10,22 @@ var _response = require("../../utils/response.cjs");
|
|
|
10
10
|
function getWithParams(params, context) {
|
|
11
11
|
return params.with ?? context.withParams?.basket ?? _constants.MIN_WITH_PARAMS_WISHLIST;
|
|
12
12
|
}
|
|
13
|
+
const getWishlist = exports.getWishlist = async function getWishlist2(options, context) {
|
|
14
|
+
(0, _types.assertSession)(context);
|
|
15
|
+
const {
|
|
16
|
+
bapiClient,
|
|
17
|
+
campaignKey,
|
|
18
|
+
wishlistKey
|
|
19
|
+
} = context;
|
|
20
|
+
const resolvedWith = getWithParams({
|
|
21
|
+
with: options
|
|
22
|
+
}, context);
|
|
23
|
+
return await bapiClient.wishlist.get(wishlistKey, {
|
|
24
|
+
with: resolvedWith,
|
|
25
|
+
campaignKey,
|
|
26
|
+
pricePromotionKey: resolvedWith?.pricePromotionKey ?? ""
|
|
27
|
+
});
|
|
28
|
+
};
|
|
13
29
|
const addItemToWishlist = exports.addItemToWishlist = async function addItemToWishlist2(options, context) {
|
|
14
30
|
(0, _types.assertSession)(context);
|
|
15
31
|
const {
|
|
@@ -50,22 +66,6 @@ const addItemToWishlist = exports.addItemToWishlist = async function addItemToWi
|
|
|
50
66
|
});
|
|
51
67
|
}
|
|
52
68
|
};
|
|
53
|
-
const getWishlist = exports.getWishlist = async function getWishlist2(options, context) {
|
|
54
|
-
(0, _types.assertSession)(context);
|
|
55
|
-
const {
|
|
56
|
-
bapiClient,
|
|
57
|
-
campaignKey,
|
|
58
|
-
wishlistKey
|
|
59
|
-
} = context;
|
|
60
|
-
const resolvedWith = getWithParams({
|
|
61
|
-
with: options
|
|
62
|
-
}, context);
|
|
63
|
-
return await bapiClient.wishlist.get(wishlistKey, {
|
|
64
|
-
with: resolvedWith,
|
|
65
|
-
campaignKey,
|
|
66
|
-
pricePromotionKey: resolvedWith?.pricePromotionKey ?? ""
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
69
|
const removeItemFromWishlist = exports.removeItemFromWishlist = async function removeItemFromWishlist2(options, context) {
|
|
70
70
|
(0, _types.assertSession)(context);
|
|
71
71
|
const {
|