@scayle/storefront-core 7.67.0 → 7.68.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 +14 -0
- package/dist/rpc/methods/basket/basket.cjs +8 -8
- package/dist/rpc/methods/basket/basket.mjs +8 -8
- package/dist/rpc/methods/brands.cjs +4 -4
- package/dist/rpc/methods/brands.d.ts +2 -2
- package/dist/rpc/methods/brands.mjs +4 -4
- package/dist/rpc/methods/categories.cjs +9 -9
- package/dist/rpc/methods/categories.d.ts +1 -1
- package/dist/rpc/methods/categories.mjs +9 -9
- package/dist/rpc/methods/checkout/checkout.cjs +1 -1
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/navigationTrees.cjs +3 -3
- package/dist/rpc/methods/navigationTrees.d.ts +3 -3
- package/dist/rpc/methods/navigationTrees.mjs +3 -3
- package/dist/rpc/methods/products.cjs +16 -16
- package/dist/rpc/methods/products.d.ts +4 -4
- package/dist/rpc/methods/products.mjs +16 -16
- package/dist/rpc/methods/promotion.cjs +6 -6
- package/dist/rpc/methods/promotion.mjs +6 -6
- package/dist/rpc/methods/search.cjs +9 -9
- package/dist/rpc/methods/search.d.ts +3 -3
- package/dist/rpc/methods/search.mjs +9 -9
- package/dist/rpc/methods/shopConfiguration.cjs +2 -2
- package/dist/rpc/methods/shopConfiguration.d.ts +1 -1
- package/dist/rpc/methods/shopConfiguration.mjs +2 -2
- package/dist/rpc/methods/variants.cjs +2 -2
- package/dist/rpc/methods/variants.d.ts +1 -1
- package/dist/rpc/methods/variants.mjs +2 -2
- package/dist/rpc/methods/wishlist.cjs +6 -6
- package/dist/rpc/methods/wishlist.mjs +6 -6
- package/dist/types/api/context.d.ts +1 -1
- package/dist/utils/user.cjs +8 -8
- package/dist/utils/user.mjs +8 -8
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 7.68.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Set `sapiClient` in `RpcContext` as required to improve the updatability of RPC methods.
|
|
8
|
+
|
|
9
|
+
## 7.67.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
**Dependencies**
|
|
14
|
+
|
|
15
|
+
- Updated dependency to @scayle/storefront-api@17.10.1
|
|
16
|
+
|
|
3
17
|
## 7.67.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -29,13 +29,13 @@ const addItemToBasket = exports.addItemToBasket = async function addItemToBasket
|
|
|
29
29
|
}
|
|
30
30
|
const {
|
|
31
31
|
campaignKey,
|
|
32
|
-
|
|
32
|
+
sapiClient,
|
|
33
33
|
basketKey
|
|
34
34
|
} = context;
|
|
35
35
|
const resolvedWith = getWithParams({
|
|
36
36
|
with: _with
|
|
37
37
|
}, context);
|
|
38
|
-
const result = await
|
|
38
|
+
const result = await sapiClient.basket.addOrUpdateItems(basketKey, [{
|
|
39
39
|
variantId,
|
|
40
40
|
quantity,
|
|
41
41
|
params: {
|
|
@@ -76,7 +76,7 @@ const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBas
|
|
|
76
76
|
}
|
|
77
77
|
const {
|
|
78
78
|
campaignKey,
|
|
79
|
-
|
|
79
|
+
sapiClient,
|
|
80
80
|
basketKey
|
|
81
81
|
} = context;
|
|
82
82
|
const resolvedWith = getWithParams(params, context);
|
|
@@ -94,7 +94,7 @@ const addItemsToBasket = exports.addItemsToBasket = async function addItemsToBas
|
|
|
94
94
|
itemGroup: item.itemGroup ?? void 0
|
|
95
95
|
}
|
|
96
96
|
}));
|
|
97
|
-
const result = await
|
|
97
|
+
const result = await sapiClient.basket.addOrUpdateItems(basketKey, itemsToBeAddedOrUpdated, {
|
|
98
98
|
skipAvailabilityCheck: false,
|
|
99
99
|
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
100
100
|
orderCustomData: params.orderCustomData
|
|
@@ -122,14 +122,14 @@ const getBasket = exports.getBasket = async function getBasket2(options, context
|
|
|
122
122
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
123
123
|
}
|
|
124
124
|
const {
|
|
125
|
-
|
|
125
|
+
sapiClient,
|
|
126
126
|
campaignKey,
|
|
127
127
|
basketKey
|
|
128
128
|
} = context;
|
|
129
129
|
const resolvedWith = getWithParams({
|
|
130
130
|
with: options
|
|
131
131
|
}, context);
|
|
132
|
-
const response = await
|
|
132
|
+
const response = await sapiClient.basket.get(basketKey, {
|
|
133
133
|
with: resolvedWith,
|
|
134
134
|
campaignKey,
|
|
135
135
|
includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData,
|
|
@@ -151,12 +151,12 @@ const removeItemFromBasket = exports.removeItemFromBasket = async function remov
|
|
|
151
151
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
152
152
|
}
|
|
153
153
|
const {
|
|
154
|
-
|
|
154
|
+
sapiClient,
|
|
155
155
|
campaignKey,
|
|
156
156
|
basketKey
|
|
157
157
|
} = context;
|
|
158
158
|
const resolvedWith = getWithParams(options, context);
|
|
159
|
-
return await
|
|
159
|
+
return await sapiClient.basket.deleteItem(basketKey, options.itemKey, {
|
|
160
160
|
with: resolvedWith,
|
|
161
161
|
campaignKey,
|
|
162
162
|
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
@@ -30,12 +30,12 @@ export const addItemToBasket = async function addItemToBasket2({
|
|
|
30
30
|
"No Session found"
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
|
-
const { campaignKey,
|
|
33
|
+
const { campaignKey, sapiClient, basketKey } = context;
|
|
34
34
|
const resolvedWith = getWithParams(
|
|
35
35
|
{ with: _with },
|
|
36
36
|
context
|
|
37
37
|
);
|
|
38
|
-
const result = await
|
|
38
|
+
const result = await sapiClient.basket.addOrUpdateItems(
|
|
39
39
|
basketKey,
|
|
40
40
|
[
|
|
41
41
|
{
|
|
@@ -84,7 +84,7 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
84
84
|
"No Session found"
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
|
-
const { campaignKey,
|
|
87
|
+
const { campaignKey, sapiClient, basketKey } = context;
|
|
88
88
|
const resolvedWith = getWithParams(params, context);
|
|
89
89
|
const itemsToBeAddedOrUpdated = params.items.map((item) => ({
|
|
90
90
|
variantId: item.variantId,
|
|
@@ -100,7 +100,7 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
100
100
|
itemGroup: item.itemGroup ?? void 0
|
|
101
101
|
}
|
|
102
102
|
}));
|
|
103
|
-
const result = await
|
|
103
|
+
const result = await sapiClient.basket.addOrUpdateItems(
|
|
104
104
|
basketKey,
|
|
105
105
|
itemsToBeAddedOrUpdated,
|
|
106
106
|
{
|
|
@@ -138,12 +138,12 @@ export const getBasket = async function getBasket2(options, context) {
|
|
|
138
138
|
"No Session found"
|
|
139
139
|
);
|
|
140
140
|
}
|
|
141
|
-
const {
|
|
141
|
+
const { sapiClient, campaignKey, basketKey } = context;
|
|
142
142
|
const resolvedWith = getWithParams(
|
|
143
143
|
{ with: options },
|
|
144
144
|
context
|
|
145
145
|
);
|
|
146
|
-
const response = await
|
|
146
|
+
const response = await sapiClient.basket.get(basketKey, {
|
|
147
147
|
with: resolvedWith,
|
|
148
148
|
campaignKey,
|
|
149
149
|
includeItemsWithoutProductData: resolvedWith.includeItemsWithoutProductData,
|
|
@@ -170,9 +170,9 @@ export const removeItemFromBasket = async function removeItemFromBasket2(options
|
|
|
170
170
|
"No Session found"
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
|
-
const {
|
|
173
|
+
const { sapiClient, campaignKey, basketKey } = context;
|
|
174
174
|
const resolvedWith = getWithParams(options, context);
|
|
175
|
-
return await
|
|
175
|
+
return await sapiClient.basket.deleteItem(basketKey, options.itemKey, {
|
|
176
176
|
with: resolvedWith,
|
|
177
177
|
campaignKey,
|
|
178
178
|
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
@@ -8,10 +8,10 @@ const MAX_PER_PAGE = 100;
|
|
|
8
8
|
const getBrands = exports.getBrands = async function getBrands2({
|
|
9
9
|
pagination
|
|
10
10
|
}, {
|
|
11
|
-
|
|
11
|
+
sapiClient,
|
|
12
12
|
cached
|
|
13
13
|
}) {
|
|
14
|
-
return await cached(
|
|
14
|
+
return await cached(sapiClient.brands.get, {
|
|
15
15
|
cacheKeyPrefix: "getBrands"
|
|
16
16
|
})({
|
|
17
17
|
pagination: {
|
|
@@ -23,10 +23,10 @@ const getBrands = exports.getBrands = async function getBrands2({
|
|
|
23
23
|
const getBrandById = exports.getBrandById = async function getBrandById2({
|
|
24
24
|
brandId
|
|
25
25
|
}, {
|
|
26
|
-
|
|
26
|
+
sapiClient,
|
|
27
27
|
cached
|
|
28
28
|
}) {
|
|
29
|
-
return await cached(
|
|
29
|
+
return await cached(sapiClient.brands.getById, {
|
|
30
30
|
cacheKeyPrefix: `getBrandById-${brandId}`
|
|
31
31
|
})(brandId);
|
|
32
32
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Brand, BrandsEndpointRequestParameters, BrandsEndpointResponseData } from '../../types';
|
|
2
|
-
export declare const getBrands: ({ pagination }: BrandsEndpointRequestParameters, {
|
|
2
|
+
export declare const getBrands: ({ pagination }: BrandsEndpointRequestParameters, { sapiClient, cached }: import("../../types").RpcContext) => Promise<BrandsEndpointResponseData>;
|
|
3
3
|
export declare const getBrandById: ({ brandId }: {
|
|
4
4
|
brandId: number;
|
|
5
|
-
}, {
|
|
5
|
+
}, { sapiClient, cached }: import("../../types").RpcContext) => Promise<Brand>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const MAX_PER_PAGE = 100;
|
|
2
|
-
export const getBrands = async function getBrands2({ pagination }, {
|
|
3
|
-
return await cached(
|
|
2
|
+
export const getBrands = async function getBrands2({ pagination }, { sapiClient, cached }) {
|
|
3
|
+
return await cached(sapiClient.brands.get, {
|
|
4
4
|
cacheKeyPrefix: "getBrands"
|
|
5
5
|
})({
|
|
6
6
|
pagination: {
|
|
@@ -9,8 +9,8 @@ export const getBrands = async function getBrands2({ pagination }, { bapiClient,
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
-
export const getBrandById = async function getBrandById2({ brandId }, {
|
|
13
|
-
return await cached(
|
|
12
|
+
export const getBrandById = async function getBrandById2({ brandId }, { sapiClient, cached }) {
|
|
13
|
+
return await cached(sapiClient.brands.getById, {
|
|
14
14
|
cacheKeyPrefix: `getBrandById-${brandId}`
|
|
15
15
|
})(brandId);
|
|
16
16
|
};
|
|
@@ -11,9 +11,9 @@ const getRootCategories = exports.getRootCategories = async function getRootCate
|
|
|
11
11
|
properties
|
|
12
12
|
}, {
|
|
13
13
|
cached,
|
|
14
|
-
|
|
14
|
+
sapiClient
|
|
15
15
|
}) {
|
|
16
|
-
const result = await cached(
|
|
16
|
+
const result = await cached(sapiClient.categories.getRoots, {
|
|
17
17
|
cacheKeyPrefix: "root-categories"
|
|
18
18
|
})({
|
|
19
19
|
with: {
|
|
@@ -35,10 +35,10 @@ const getCategoryByPath = exports.getCategoryByPath = async function getCategory
|
|
|
35
35
|
}, context) {
|
|
36
36
|
const {
|
|
37
37
|
cached,
|
|
38
|
-
|
|
38
|
+
sapiClient
|
|
39
39
|
} = context;
|
|
40
40
|
const sanitizedPath = (0, _helpers.splitAndRemoveEmpty)(path);
|
|
41
|
-
return await cached(
|
|
41
|
+
return await cached(sapiClient.categories.getByPath, {
|
|
42
42
|
cacheKeyPrefix: `getByPath-category-${sanitizedPath}`
|
|
43
43
|
})(sanitizedPath, {
|
|
44
44
|
with: {
|
|
@@ -56,7 +56,7 @@ const getCategoriesByPath = exports.getCategoriesByPath = async function getCate
|
|
|
56
56
|
}, context) {
|
|
57
57
|
const {
|
|
58
58
|
cached,
|
|
59
|
-
|
|
59
|
+
sapiClient
|
|
60
60
|
} = context;
|
|
61
61
|
if (path === "/") {
|
|
62
62
|
return getRootCategories({
|
|
@@ -66,7 +66,7 @@ const getCategoriesByPath = exports.getCategoriesByPath = async function getCate
|
|
|
66
66
|
}, context);
|
|
67
67
|
}
|
|
68
68
|
const sanitizedPath = (0, _helpers.splitAndRemoveEmpty)(path);
|
|
69
|
-
const result = await cached(
|
|
69
|
+
const result = await cached(sapiClient.categories.getByPath, {
|
|
70
70
|
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
71
71
|
})(sanitizedPath, {
|
|
72
72
|
with: {
|
|
@@ -76,7 +76,7 @@ const getCategoriesByPath = exports.getCategoriesByPath = async function getCate
|
|
|
76
76
|
includeHidden
|
|
77
77
|
});
|
|
78
78
|
const rootPath = await Promise.all((result.rootlineIds || []).map(id => {
|
|
79
|
-
return cached(
|
|
79
|
+
return cached(sapiClient.categories.getById, {
|
|
80
80
|
cacheKeyPrefix: `getById-categories-${id}`
|
|
81
81
|
})(id, {
|
|
82
82
|
with: {
|
|
@@ -113,9 +113,9 @@ const getCategoryById = exports.getCategoryById = async function getCategoryById
|
|
|
113
113
|
}, context) {
|
|
114
114
|
const {
|
|
115
115
|
cached,
|
|
116
|
-
|
|
116
|
+
sapiClient
|
|
117
117
|
} = context;
|
|
118
|
-
return await cached(
|
|
118
|
+
return await cached(sapiClient.categories.getById, {
|
|
119
119
|
cacheKeyPrefix: `getById-categories-${id}`
|
|
120
120
|
})(id, {
|
|
121
121
|
with: {
|
|
@@ -3,7 +3,7 @@ export declare const getRootCategories: ({ children, includeHidden, properties }
|
|
|
3
3
|
children?: number;
|
|
4
4
|
includeHidden?: true;
|
|
5
5
|
properties?: ProductCategoryPropertyWith;
|
|
6
|
-
}, { cached,
|
|
6
|
+
}, { cached, sapiClient }: import("../../types").RpcContext) => Promise<{
|
|
7
7
|
categories: Category[];
|
|
8
8
|
activeNode: undefined;
|
|
9
9
|
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { splitAndRemoveEmpty } from "../../helpers/index.mjs";
|
|
2
|
-
export const getRootCategories = async function getRootCategories2({ children = 1, includeHidden, properties }, { cached,
|
|
3
|
-
const result = await cached(
|
|
2
|
+
export const getRootCategories = async function getRootCategories2({ children = 1, includeHidden, properties }, { cached, sapiClient }) {
|
|
3
|
+
const result = await cached(sapiClient.categories.getRoots, {
|
|
4
4
|
cacheKeyPrefix: "root-categories"
|
|
5
5
|
})({
|
|
6
6
|
with: { children, properties },
|
|
@@ -12,19 +12,19 @@ export const getRootCategories = async function getRootCategories2({ children =
|
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
export const getCategoryByPath = async function getCategoryByPath2({ path, children = 1, includeHidden, properties }, context) {
|
|
15
|
-
const { cached,
|
|
15
|
+
const { cached, sapiClient } = context;
|
|
16
16
|
const sanitizedPath = splitAndRemoveEmpty(path);
|
|
17
|
-
return await cached(
|
|
17
|
+
return await cached(sapiClient.categories.getByPath, {
|
|
18
18
|
cacheKeyPrefix: `getByPath-category-${sanitizedPath}`
|
|
19
19
|
})(sanitizedPath, { with: { children, properties }, includeHidden });
|
|
20
20
|
};
|
|
21
21
|
export const getCategoriesByPath = async function getCategoriesByPath2({ path, children = 1, includeHidden, properties }, context) {
|
|
22
|
-
const { cached,
|
|
22
|
+
const { cached, sapiClient } = context;
|
|
23
23
|
if (path === "/") {
|
|
24
24
|
return getRootCategories({ children, includeHidden, properties }, context);
|
|
25
25
|
}
|
|
26
26
|
const sanitizedPath = splitAndRemoveEmpty(path);
|
|
27
|
-
const result = await cached(
|
|
27
|
+
const result = await cached(sapiClient.categories.getByPath, {
|
|
28
28
|
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
29
29
|
})(sanitizedPath, {
|
|
30
30
|
with: { children, properties },
|
|
@@ -32,7 +32,7 @@ export const getCategoriesByPath = async function getCategoriesByPath2({ path, c
|
|
|
32
32
|
});
|
|
33
33
|
const rootPath = await Promise.all(
|
|
34
34
|
(result.rootlineIds || []).map((id) => {
|
|
35
|
-
return cached(
|
|
35
|
+
return cached(sapiClient.categories.getById, {
|
|
36
36
|
cacheKeyPrefix: `getById-categories-${id}`
|
|
37
37
|
})(id, {
|
|
38
38
|
with: {
|
|
@@ -62,8 +62,8 @@ export const getCategoriesByPath = async function getCategoriesByPath2({ path, c
|
|
|
62
62
|
return { categories: tree, activeNode: result };
|
|
63
63
|
};
|
|
64
64
|
export const getCategoryById = async function getCategoryById2({ id, children = 1, includeHidden, properties }, context) {
|
|
65
|
-
const { cached,
|
|
66
|
-
return await cached(
|
|
65
|
+
const { cached, sapiClient } = context;
|
|
66
|
+
return await cached(sapiClient.categories.getById, {
|
|
67
67
|
cacheKeyPrefix: `getById-categories-${id}`
|
|
68
68
|
})(id, {
|
|
69
69
|
with: {
|
|
@@ -37,7 +37,7 @@ const getCheckoutToken = exports.getCheckoutToken = async function getCheckoutTo
|
|
|
37
37
|
carrier,
|
|
38
38
|
basketId: context.basketKey,
|
|
39
39
|
campaignKey: context.campaignKey
|
|
40
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.
|
|
40
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.68.0"}`).setProtectedHeader({
|
|
41
41
|
alg: "HS256",
|
|
42
42
|
typ: "JWT"
|
|
43
43
|
}).sign(secret);
|
|
@@ -35,7 +35,7 @@ export const getCheckoutToken = async function getCheckoutToken2(jwtPayload = {}
|
|
|
35
35
|
carrier,
|
|
36
36
|
basketId: context.basketKey,
|
|
37
37
|
campaignKey: context.campaignKey
|
|
38
|
-
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.
|
|
38
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"7.68.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
39
39
|
return {
|
|
40
40
|
accessToken: refreshedAccessToken,
|
|
41
41
|
checkoutJwt
|
|
@@ -9,7 +9,7 @@ var _constants = require("../../constants/index.cjs");
|
|
|
9
9
|
const fetchAllNavigationTrees = exports.fetchAllNavigationTrees = async function fetchAllNavigationTrees2({
|
|
10
10
|
params
|
|
11
11
|
}, {
|
|
12
|
-
|
|
12
|
+
sapiClient: {
|
|
13
13
|
navigation
|
|
14
14
|
},
|
|
15
15
|
cached
|
|
@@ -22,7 +22,7 @@ const fetchNavigationTreeById = exports.fetchNavigationTreeById = async function
|
|
|
22
22
|
treeId,
|
|
23
23
|
params
|
|
24
24
|
}, {
|
|
25
|
-
|
|
25
|
+
sapiClient: {
|
|
26
26
|
navigation
|
|
27
27
|
},
|
|
28
28
|
cached
|
|
@@ -35,7 +35,7 @@ const fetchNavigationTreeByName = exports.fetchNavigationTreeByName = async func
|
|
|
35
35
|
treeName,
|
|
36
36
|
params
|
|
37
37
|
}, {
|
|
38
|
-
|
|
38
|
+
sapiClient: {
|
|
39
39
|
navigation
|
|
40
40
|
},
|
|
41
41
|
cached
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NavigationAllEndpointResponseData, NavigationTree } from '@scayle/storefront-api';
|
|
2
2
|
import type { FetchNavigationTreeByIdParams, FetchNavigationTreeByNameParams, FetchNavigationTreesParams } from '../../types';
|
|
3
3
|
import { ErrorResponse } from '../../errors';
|
|
4
|
-
export declare const fetchAllNavigationTrees: ({ params }: FetchNavigationTreesParams, {
|
|
5
|
-
export declare const fetchNavigationTreeById: ({ treeId, params }: FetchNavigationTreeByIdParams, {
|
|
6
|
-
export declare const fetchNavigationTreeByName: ({ treeName, params }: FetchNavigationTreeByNameParams, {
|
|
4
|
+
export declare const fetchAllNavigationTrees: ({ params }: FetchNavigationTreesParams, { sapiClient: { navigation }, cached }: import("../../types").RpcContext) => Promise<NavigationAllEndpointResponseData>;
|
|
5
|
+
export declare const fetchNavigationTreeById: ({ treeId, params }: FetchNavigationTreeByIdParams, { sapiClient: { navigation }, cached }: import("../../types").RpcContext) => Promise<NavigationTree>;
|
|
6
|
+
export declare const fetchNavigationTreeByName: ({ treeName, params }: FetchNavigationTreeByNameParams, { sapiClient: { navigation }, cached }: import("../../types").RpcContext) => Promise<ErrorResponse | NavigationTree>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ErrorResponse } from "../../errors/index.mjs";
|
|
2
2
|
import { HttpStatusCode, HttpStatusMessage } from "../../constants/index.mjs";
|
|
3
|
-
export const fetchAllNavigationTrees = async function fetchAllNavigationTrees2({ params }, {
|
|
3
|
+
export const fetchAllNavigationTrees = async function fetchAllNavigationTrees2({ params }, { sapiClient: { navigation }, cached }) {
|
|
4
4
|
return await cached(navigation.getAll, {
|
|
5
5
|
cacheKeyPrefix: "getAll-navigation-trees"
|
|
6
6
|
})(params);
|
|
7
7
|
};
|
|
8
|
-
export const fetchNavigationTreeById = async function fetchNavigationTreeById2({ treeId, params }, {
|
|
8
|
+
export const fetchNavigationTreeById = async function fetchNavigationTreeById2({ treeId, params }, { sapiClient: { navigation }, cached }) {
|
|
9
9
|
return await cached(navigation.getById, {
|
|
10
10
|
cacheKeyPrefix: `getById-navigation-trees-${treeId}`
|
|
11
11
|
})(treeId, params);
|
|
12
12
|
};
|
|
13
|
-
export const fetchNavigationTreeByName = async function fetchNavigationTreeByName2({ treeName, params }, {
|
|
13
|
+
export const fetchNavigationTreeByName = async function fetchNavigationTreeByName2({ treeName, params }, { sapiClient: { navigation }, cached }) {
|
|
14
14
|
return await cached(
|
|
15
15
|
async (name, params2) => {
|
|
16
16
|
const navigationTree = (await navigation.getAll(params2)).find(
|
|
@@ -30,7 +30,7 @@ async function resolveCategoryIdFromParams(context, params) {
|
|
|
30
30
|
categoryId = params.categoryId;
|
|
31
31
|
} else if (params.category && params.category !== "/") {
|
|
32
32
|
category = params.category;
|
|
33
|
-
const result = await context.cached(context.
|
|
33
|
+
const result = await context.cached(context.sapiClient.categories.getByPath, {
|
|
34
34
|
cacheKeyPrefix: `getByPath-categories-${category}`
|
|
35
35
|
})((0, _helpers.splitAndRemoveEmpty)(category));
|
|
36
36
|
categoryId = result.id;
|
|
@@ -43,12 +43,12 @@ async function resolveCategoryIdFromParams(context, params) {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
const getProductById = exports.getProductById = async function getProductById2(options, {
|
|
46
|
-
|
|
46
|
+
sapiClient,
|
|
47
47
|
cached,
|
|
48
48
|
campaignKey,
|
|
49
49
|
withParams
|
|
50
50
|
}) {
|
|
51
|
-
return await cached(
|
|
51
|
+
return await cached(sapiClient.products.getById, {
|
|
52
52
|
cacheKeyPrefix: `getById-product-${options.id}`,
|
|
53
53
|
ttl: 5 * _cache.MINUTE
|
|
54
54
|
})(options.id, {
|
|
@@ -59,12 +59,12 @@ const getProductById = exports.getProductById = async function getProductById2(o
|
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
61
|
const getProductsByIds = exports.getProductsByIds = async function getProductsByIds2(options, {
|
|
62
|
-
|
|
62
|
+
sapiClient,
|
|
63
63
|
cached,
|
|
64
64
|
campaignKey,
|
|
65
65
|
withParams
|
|
66
66
|
}) {
|
|
67
|
-
return await cached(
|
|
67
|
+
return await cached(sapiClient.products.getByIds, {
|
|
68
68
|
cacheKeyPrefix: "getByIds-products",
|
|
69
69
|
ttl: 5 * _cache.MINUTE
|
|
70
70
|
})(options.ids, {
|
|
@@ -74,12 +74,12 @@ const getProductsByIds = exports.getProductsByIds = async function getProductsBy
|
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
76
|
const getProductsByReferenceKeys = exports.getProductsByReferenceKeys = async function getProductsByReferenceKeys2(options, {
|
|
77
|
-
|
|
77
|
+
sapiClient,
|
|
78
78
|
cached,
|
|
79
79
|
campaignKey,
|
|
80
80
|
withParams
|
|
81
81
|
}) {
|
|
82
|
-
return await cached(
|
|
82
|
+
return await cached(sapiClient.products.getByReferenceKeys, {
|
|
83
83
|
cacheKeyPrefix: "getByReferenceKeys-products",
|
|
84
84
|
ttl: 5 * _cache.MINUTE
|
|
85
85
|
})(options.referenceKeys, {
|
|
@@ -98,7 +98,7 @@ const getProductsCount = exports.getProductsCount = async function getProductsCo
|
|
|
98
98
|
} = params;
|
|
99
99
|
const {
|
|
100
100
|
cached,
|
|
101
|
-
|
|
101
|
+
sapiClient,
|
|
102
102
|
campaignKey
|
|
103
103
|
} = context;
|
|
104
104
|
const {
|
|
@@ -109,7 +109,7 @@ const getProductsCount = exports.getProductsCount = async function getProductsCo
|
|
|
109
109
|
return response;
|
|
110
110
|
}
|
|
111
111
|
const sanitizedAttributes = response;
|
|
112
|
-
const productCount = await cached(
|
|
112
|
+
const productCount = await cached(sapiClient.products.query, {
|
|
113
113
|
ttl: 15 * _cache.MINUTE,
|
|
114
114
|
cacheKeyPrefix: "products-query"
|
|
115
115
|
})({
|
|
@@ -138,11 +138,11 @@ const fetchAllFiltersForCategory = exports.fetchAllFiltersForCategory = async fu
|
|
|
138
138
|
category
|
|
139
139
|
}, {
|
|
140
140
|
cached,
|
|
141
|
-
|
|
141
|
+
sapiClient,
|
|
142
142
|
campaignKey
|
|
143
143
|
}) {
|
|
144
144
|
const fetchAndMapFiltersToSlugs = async () => {
|
|
145
|
-
const filtersFromBAPI = await cached(
|
|
145
|
+
const filtersFromBAPI = await cached(sapiClient.filters.get)({
|
|
146
146
|
where: {
|
|
147
147
|
categoryId: category.id
|
|
148
148
|
},
|
|
@@ -184,7 +184,7 @@ const getFilters = exports.getFilters = async function getFilters2(params, conte
|
|
|
184
184
|
} = params;
|
|
185
185
|
const {
|
|
186
186
|
cached,
|
|
187
|
-
|
|
187
|
+
sapiClient,
|
|
188
188
|
campaignKey
|
|
189
189
|
} = context;
|
|
190
190
|
const {
|
|
@@ -196,7 +196,7 @@ const getFilters = exports.getFilters = async function getFilters2(params, conte
|
|
|
196
196
|
return response;
|
|
197
197
|
}
|
|
198
198
|
const sanitizedAttributes = response;
|
|
199
|
-
const [filters, productCount] = await Promise.all([cached(
|
|
199
|
+
const [filters, productCount] = await Promise.all([cached(sapiClient.filters.get, {
|
|
200
200
|
cacheKeyPrefix: `get-filters-${categoryId}`
|
|
201
201
|
})({
|
|
202
202
|
where: {
|
|
@@ -211,7 +211,7 @@ const getFilters = exports.getFilters = async function getFilters2(params, conte
|
|
|
211
211
|
campaignKey,
|
|
212
212
|
including: includedFilters,
|
|
213
213
|
orFiltersOperator
|
|
214
|
-
}), cached(
|
|
214
|
+
}), cached(sapiClient.products.query, {
|
|
215
215
|
ttl: 15 * _cache.MINUTE,
|
|
216
216
|
cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : categoryId}`
|
|
217
217
|
})({
|
|
@@ -252,7 +252,7 @@ const getProductsByCategory = exports.getProductsByCategory = async function get
|
|
|
252
252
|
} = params;
|
|
253
253
|
const {
|
|
254
254
|
cached,
|
|
255
|
-
|
|
255
|
+
sapiClient,
|
|
256
256
|
campaignKey
|
|
257
257
|
} = context;
|
|
258
258
|
const {
|
|
@@ -267,7 +267,7 @@ const getProductsByCategory = exports.getProductsByCategory = async function get
|
|
|
267
267
|
const {
|
|
268
268
|
entities: products,
|
|
269
269
|
pagination
|
|
270
|
-
} = await cached(
|
|
270
|
+
} = await cached(sapiClient.products.query, {
|
|
271
271
|
...cache,
|
|
272
272
|
ttl: cache?.ttl ?? 15 * _cache.MINUTE,
|
|
273
273
|
cacheKeyPrefix: cache?.cacheKeyPrefix || `products-query-category-${category === "/" ? "root" : categoryId}`
|
|
@@ -20,9 +20,9 @@ export declare function resolveCategoryIdFromParams(context: RpcContext, params:
|
|
|
20
20
|
category: string | undefined;
|
|
21
21
|
categoryId: number | undefined;
|
|
22
22
|
}>;
|
|
23
|
-
export declare const getProductById: (options: FetchProductParams, {
|
|
24
|
-
export declare const getProductsByIds: (options: FetchProductsByIdsParams, {
|
|
25
|
-
export declare const getProductsByReferenceKeys: (options: FetchProductsByReferenceKeysParams, {
|
|
23
|
+
export declare const getProductById: (options: FetchProductParams, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Product>;
|
|
24
|
+
export declare const getProductsByIds: (options: FetchProductsByIdsParams, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Product[]>;
|
|
25
|
+
export declare const getProductsByReferenceKeys: (options: FetchProductsByReferenceKeysParams, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Product[]>;
|
|
26
26
|
export declare const getProductsCount: (params: FetchProductsCountParams, context: RpcContext) => Promise<(string[] & ErrorResponse) | {
|
|
27
27
|
count: number;
|
|
28
28
|
}>;
|
|
@@ -31,7 +31,7 @@ export declare const fetchAllFiltersForCategory: ({ includedFilters, category }:
|
|
|
31
31
|
category: {
|
|
32
32
|
id?: number;
|
|
33
33
|
};
|
|
34
|
-
}, { cached,
|
|
34
|
+
}, { cached, sapiClient, campaignKey }: RpcContext) => Promise<string[]>;
|
|
35
35
|
export declare const getFilters: (params: FetchFiltersParams, context: RpcContext) => Promise<(string[] & ErrorResponse) | {
|
|
36
36
|
filters: FiltersEndpointResponseData;
|
|
37
37
|
unfilteredCount: number;
|
|
@@ -22,7 +22,7 @@ export async function resolveCategoryIdFromParams(context, params) {
|
|
|
22
22
|
} else if (params.category && params.category !== "/") {
|
|
23
23
|
category = params.category;
|
|
24
24
|
const result = await context.cached(
|
|
25
|
-
context.
|
|
25
|
+
context.sapiClient.categories.getByPath,
|
|
26
26
|
{
|
|
27
27
|
cacheKeyPrefix: `getByPath-categories-${category}`
|
|
28
28
|
}
|
|
@@ -33,8 +33,8 @@ export async function resolveCategoryIdFromParams(context, params) {
|
|
|
33
33
|
}
|
|
34
34
|
return { category, categoryId };
|
|
35
35
|
}
|
|
36
|
-
export const getProductById = async function getProductById2(options, {
|
|
37
|
-
return await cached(
|
|
36
|
+
export const getProductById = async function getProductById2(options, { sapiClient, cached, campaignKey, withParams }) {
|
|
37
|
+
return await cached(sapiClient.products.getById, {
|
|
38
38
|
cacheKeyPrefix: `getById-product-${options.id}`,
|
|
39
39
|
ttl: 5 * MINUTE
|
|
40
40
|
})(options.id, {
|
|
@@ -44,8 +44,8 @@ export const getProductById = async function getProductById2(options, { bapiClie
|
|
|
44
44
|
includeSellableForFree: options.includeSellableForFree
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
|
-
export const getProductsByIds = async function getProductsByIds2(options, {
|
|
48
|
-
return await cached(
|
|
47
|
+
export const getProductsByIds = async function getProductsByIds2(options, { sapiClient, cached, campaignKey, withParams }) {
|
|
48
|
+
return await cached(sapiClient.products.getByIds, {
|
|
49
49
|
cacheKeyPrefix: "getByIds-products",
|
|
50
50
|
ttl: 5 * MINUTE
|
|
51
51
|
})(options.ids, {
|
|
@@ -54,8 +54,8 @@ export const getProductsByIds = async function getProductsByIds2(options, { bapi
|
|
|
54
54
|
pricePromotionKey: options.pricePromotionKey
|
|
55
55
|
});
|
|
56
56
|
};
|
|
57
|
-
export const getProductsByReferenceKeys = async function getProductsByReferenceKeys2(options, {
|
|
58
|
-
return await cached(
|
|
57
|
+
export const getProductsByReferenceKeys = async function getProductsByReferenceKeys2(options, { sapiClient, cached, campaignKey, withParams }) {
|
|
58
|
+
return await cached(sapiClient.products.getByReferenceKeys, {
|
|
59
59
|
cacheKeyPrefix: "getByReferenceKeys-products",
|
|
60
60
|
ttl: 5 * MINUTE
|
|
61
61
|
})(options.referenceKeys, {
|
|
@@ -72,7 +72,7 @@ export const getProductsCount = async function getProductsCount2(params, context
|
|
|
72
72
|
includeSellableForFree = false,
|
|
73
73
|
orFiltersOperator = void 0
|
|
74
74
|
} = params;
|
|
75
|
-
const { cached,
|
|
75
|
+
const { cached, sapiClient, campaignKey } = context;
|
|
76
76
|
const { categoryId } = await resolveCategoryIdFromParams(context, params);
|
|
77
77
|
const response = await getSanitizedAttributes(
|
|
78
78
|
context,
|
|
@@ -84,7 +84,7 @@ export const getProductsCount = async function getProductsCount2(params, context
|
|
|
84
84
|
return response;
|
|
85
85
|
}
|
|
86
86
|
const sanitizedAttributes = response;
|
|
87
|
-
const productCount = await cached(
|
|
87
|
+
const productCount = await cached(sapiClient.products.query, {
|
|
88
88
|
ttl: 15 * MINUTE,
|
|
89
89
|
cacheKeyPrefix: "products-query"
|
|
90
90
|
})({
|
|
@@ -111,9 +111,9 @@ export const getProductsCount = async function getProductsCount2(params, context
|
|
|
111
111
|
count: productCount?.pagination.total
|
|
112
112
|
};
|
|
113
113
|
};
|
|
114
|
-
export const fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({ includedFilters = [], category }, { cached,
|
|
114
|
+
export const fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({ includedFilters = [], category }, { cached, sapiClient, campaignKey }) {
|
|
115
115
|
const fetchAndMapFiltersToSlugs = async () => {
|
|
116
|
-
const filtersFromBAPI = await cached(
|
|
116
|
+
const filtersFromBAPI = await cached(sapiClient.filters.get)({
|
|
117
117
|
where: { categoryId: category.id },
|
|
118
118
|
campaignKey,
|
|
119
119
|
including: includedFilters
|
|
@@ -152,7 +152,7 @@ export const getFilters = async function getFilters2(params, context) {
|
|
|
152
152
|
includeSellableForFree = false,
|
|
153
153
|
orFiltersOperator
|
|
154
154
|
} = params;
|
|
155
|
-
const { cached,
|
|
155
|
+
const { cached, sapiClient, campaignKey } = context;
|
|
156
156
|
const { category, categoryId } = await resolveCategoryIdFromParams(
|
|
157
157
|
context,
|
|
158
158
|
params
|
|
@@ -168,7 +168,7 @@ export const getFilters = async function getFilters2(params, context) {
|
|
|
168
168
|
}
|
|
169
169
|
const sanitizedAttributes = response;
|
|
170
170
|
const [filters, productCount] = await Promise.all([
|
|
171
|
-
cached(
|
|
171
|
+
cached(sapiClient.filters.get, {
|
|
172
172
|
cacheKeyPrefix: `get-filters-${categoryId}`
|
|
173
173
|
})({
|
|
174
174
|
where: {
|
|
@@ -187,7 +187,7 @@ export const getFilters = async function getFilters2(params, context) {
|
|
|
187
187
|
including: includedFilters,
|
|
188
188
|
orFiltersOperator
|
|
189
189
|
}),
|
|
190
|
-
cached(
|
|
190
|
+
cached(sapiClient.products.query, {
|
|
191
191
|
ttl: 15 * MINUTE,
|
|
192
192
|
cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : categoryId}`
|
|
193
193
|
})({
|
|
@@ -230,7 +230,7 @@ export const getProductsByCategory = async function getProductsByCategory2(param
|
|
|
230
230
|
includeSoldOut = void 0,
|
|
231
231
|
orFiltersOperator = void 0
|
|
232
232
|
} = params;
|
|
233
|
-
const { cached,
|
|
233
|
+
const { cached, sapiClient, campaignKey } = context;
|
|
234
234
|
const { category, categoryId } = await resolveCategoryIdFromParams(
|
|
235
235
|
context,
|
|
236
236
|
params
|
|
@@ -246,7 +246,7 @@ export const getProductsByCategory = async function getProductsByCategory2(param
|
|
|
246
246
|
}
|
|
247
247
|
const sanitizedAttributes = response;
|
|
248
248
|
const { entities: products, pagination } = await cached(
|
|
249
|
-
|
|
249
|
+
sapiClient.products.query,
|
|
250
250
|
{
|
|
251
251
|
...cache,
|
|
252
252
|
ttl: cache?.ttl ?? 15 * MINUTE,
|
|
@@ -13,10 +13,10 @@ const setPaginationDefault = pagination => {
|
|
|
13
13
|
};
|
|
14
14
|
const getPromotions = exports.getPromotions = async function getPromotions2(params = {}, context) {
|
|
15
15
|
const {
|
|
16
|
-
|
|
16
|
+
sapiClient,
|
|
17
17
|
cached
|
|
18
18
|
} = context;
|
|
19
|
-
return await cached(
|
|
19
|
+
return await cached(sapiClient.promotions.get, {
|
|
20
20
|
cacheKeyPrefix: "getPromotions"
|
|
21
21
|
})({
|
|
22
22
|
...params,
|
|
@@ -25,13 +25,13 @@ const getPromotions = exports.getPromotions = async function getPromotions2(para
|
|
|
25
25
|
};
|
|
26
26
|
const getCurrentPromotions = exports.getCurrentPromotions = async function getCurrentPromotions2(params = {}, context) {
|
|
27
27
|
const {
|
|
28
|
-
|
|
28
|
+
sapiClient,
|
|
29
29
|
cached
|
|
30
30
|
} = context;
|
|
31
31
|
const now = /* @__PURE__ */new Date();
|
|
32
32
|
now.setSeconds(0, 0);
|
|
33
33
|
const activeAt = now.toISOString();
|
|
34
|
-
return await cached(
|
|
34
|
+
return await cached(sapiClient.promotions.get, {
|
|
35
35
|
cacheKeyPrefix: "getPromotions"
|
|
36
36
|
})({
|
|
37
37
|
...params,
|
|
@@ -41,10 +41,10 @@ const getCurrentPromotions = exports.getCurrentPromotions = async function getCu
|
|
|
41
41
|
};
|
|
42
42
|
const getPromotionsByIds = exports.getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
|
|
43
43
|
const {
|
|
44
|
-
|
|
44
|
+
sapiClient,
|
|
45
45
|
cached
|
|
46
46
|
} = context;
|
|
47
|
-
return await cached(
|
|
47
|
+
return await cached(sapiClient.promotions.getByIds, {
|
|
48
48
|
cacheKeyPrefix: "getByIds-promotions"
|
|
49
49
|
})(ids);
|
|
50
50
|
};
|
|
@@ -9,8 +9,8 @@ const setPaginationDefault = (pagination) => {
|
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
export const getPromotions = async function getPromotions2(params = {}, context) {
|
|
12
|
-
const {
|
|
13
|
-
return await cached(
|
|
12
|
+
const { sapiClient, cached } = context;
|
|
13
|
+
return await cached(sapiClient.promotions.get, {
|
|
14
14
|
cacheKeyPrefix: "getPromotions"
|
|
15
15
|
})({
|
|
16
16
|
...params,
|
|
@@ -18,11 +18,11 @@ export const getPromotions = async function getPromotions2(params = {}, context)
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
export const getCurrentPromotions = async function getCurrentPromotions2(params = {}, context) {
|
|
21
|
-
const {
|
|
21
|
+
const { sapiClient, cached } = context;
|
|
22
22
|
const now = /* @__PURE__ */ new Date();
|
|
23
23
|
now.setSeconds(0, 0);
|
|
24
24
|
const activeAt = now.toISOString();
|
|
25
|
-
return await cached(
|
|
25
|
+
return await cached(sapiClient.promotions.get, {
|
|
26
26
|
cacheKeyPrefix: "getPromotions"
|
|
27
27
|
})({
|
|
28
28
|
...params,
|
|
@@ -31,8 +31,8 @@ export const getCurrentPromotions = async function getCurrentPromotions2(params
|
|
|
31
31
|
});
|
|
32
32
|
};
|
|
33
33
|
export const getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
|
|
34
|
-
const {
|
|
35
|
-
return await cached(
|
|
34
|
+
const { sapiClient, cached } = context;
|
|
35
|
+
return await cached(sapiClient.promotions.getByIds, {
|
|
36
36
|
cacheKeyPrefix: "getByIds-promotions"
|
|
37
37
|
})(ids);
|
|
38
38
|
};
|
|
@@ -6,12 +6,12 @@ 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,
|
|
9
|
+
const getCategoryId = async (cached, sapiClient, slug) => {
|
|
10
10
|
if (!slug) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
const sanitizedPath = (0, _stringHelpers.splitAndRemoveEmpty)(slug);
|
|
14
|
-
const result = await cached(
|
|
14
|
+
const result = await cached(sapiClient.categories.getByPath, {
|
|
15
15
|
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
16
16
|
})(sanitizedPath);
|
|
17
17
|
return result.id;
|
|
@@ -23,11 +23,11 @@ const searchProducts = exports.searchProducts = async function searchProducts2({
|
|
|
23
23
|
productLimit
|
|
24
24
|
}, {
|
|
25
25
|
cached,
|
|
26
|
-
|
|
26
|
+
sapiClient,
|
|
27
27
|
withParams
|
|
28
28
|
}) {
|
|
29
|
-
const categoryId = await getCategoryId(cached,
|
|
30
|
-
return await cached(
|
|
29
|
+
const categoryId = await getCategoryId(cached, sapiClient, slug);
|
|
30
|
+
return await cached(sapiClient.typeahead.suggestions, {
|
|
31
31
|
cacheKeyPrefix: `typeahead-suggestions-${term}`
|
|
32
32
|
})(term, {
|
|
33
33
|
productLimit,
|
|
@@ -40,10 +40,10 @@ const getSearchSuggestions = exports.getSearchSuggestions = async function getSe
|
|
|
40
40
|
with: _with,
|
|
41
41
|
categoryId
|
|
42
42
|
}, {
|
|
43
|
-
|
|
43
|
+
sapiClient,
|
|
44
44
|
withParams
|
|
45
45
|
}) {
|
|
46
|
-
return await
|
|
46
|
+
return await sapiClient.searchv2.suggestions(term, {
|
|
47
47
|
categoryId,
|
|
48
48
|
with: _with ?? withParams?.searchV2
|
|
49
49
|
});
|
|
@@ -54,10 +54,10 @@ const resolveSearch = exports.resolveSearch = async function resolveSearch2({
|
|
|
54
54
|
categoryId
|
|
55
55
|
}, {
|
|
56
56
|
cached,
|
|
57
|
-
|
|
57
|
+
sapiClient,
|
|
58
58
|
withParams
|
|
59
59
|
}) {
|
|
60
|
-
const resolvedEntity = await cached(
|
|
60
|
+
const resolvedEntity = await cached(sapiClient.searchv2.resolve, {
|
|
61
61
|
cacheKeyPrefix: `resolve-${term}`
|
|
62
62
|
})(term, {
|
|
63
63
|
categoryId,
|
|
@@ -7,7 +7,7 @@ export declare const searchProducts: ({ term, slug, with: _with, productLimit }:
|
|
|
7
7
|
slug?: string;
|
|
8
8
|
with?: SearchWith;
|
|
9
9
|
productLimit?: number;
|
|
10
|
-
}, { cached,
|
|
11
|
-
export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters, {
|
|
12
|
-
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, { cached,
|
|
10
|
+
}, { cached, sapiClient, withParams }: import("../../types").RpcContext) => Promise<TypeaheadSuggestionsEndpointResponseData>;
|
|
11
|
+
export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters, { sapiClient, withParams }: import("../../types").RpcContext) => Promise<SearchV2SuggestionsEndpointResponseData>;
|
|
12
|
+
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, { cached, sapiClient, withParams }: import("../../types").RpcContext) => Promise<import("@scayle/storefront-api").SearchEntity | null>;
|
|
13
13
|
export {};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { MIN_WITH_PARAMS_SEARCH } from "../../constants/index.mjs";
|
|
2
2
|
import { splitAndRemoveEmpty } from "../../helpers/stringHelpers.mjs";
|
|
3
|
-
const getCategoryId = async (cached,
|
|
3
|
+
const getCategoryId = async (cached, sapiClient, slug) => {
|
|
4
4
|
if (!slug) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
7
|
const sanitizedPath = splitAndRemoveEmpty(slug);
|
|
8
|
-
const result = await cached(
|
|
8
|
+
const result = await cached(sapiClient.categories.getByPath, {
|
|
9
9
|
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
10
10
|
})(sanitizedPath);
|
|
11
11
|
return result.id;
|
|
12
12
|
};
|
|
13
|
-
export const searchProducts = async function searchProducts2({ term, slug, with: _with, productLimit }, { cached,
|
|
14
|
-
const categoryId = await getCategoryId(cached,
|
|
15
|
-
return await cached(
|
|
13
|
+
export const searchProducts = async function searchProducts2({ term, slug, with: _with, productLimit }, { cached, sapiClient, withParams }) {
|
|
14
|
+
const categoryId = await getCategoryId(cached, sapiClient, slug);
|
|
15
|
+
return await cached(sapiClient.typeahead.suggestions, {
|
|
16
16
|
cacheKeyPrefix: `typeahead-suggestions-${term}`
|
|
17
17
|
})(term, {
|
|
18
18
|
productLimit,
|
|
@@ -20,8 +20,8 @@ export const searchProducts = async function searchProducts2({ term, slug, with:
|
|
|
20
20
|
with: _with ?? withParams?.search ?? MIN_WITH_PARAMS_SEARCH
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
export const getSearchSuggestions = async function getSearchSuggestions2({ term, with: _with, categoryId }, {
|
|
24
|
-
return await
|
|
23
|
+
export const getSearchSuggestions = async function getSearchSuggestions2({ term, with: _with, categoryId }, { sapiClient, withParams }) {
|
|
24
|
+
return await sapiClient.searchv2.suggestions(
|
|
25
25
|
term,
|
|
26
26
|
{
|
|
27
27
|
categoryId,
|
|
@@ -29,8 +29,8 @@ export const getSearchSuggestions = async function getSearchSuggestions2({ term,
|
|
|
29
29
|
}
|
|
30
30
|
);
|
|
31
31
|
};
|
|
32
|
-
export const resolveSearch = async function resolveSearch2({ term, with: _with, categoryId }, { cached,
|
|
33
|
-
const resolvedEntity = await cached(
|
|
32
|
+
export const resolveSearch = async function resolveSearch2({ term, with: _with, categoryId }, { cached, sapiClient, withParams }) {
|
|
33
|
+
const resolvedEntity = await cached(sapiClient.searchv2.resolve, {
|
|
34
34
|
cacheKeyPrefix: `resolve-${term}`
|
|
35
35
|
})(term, {
|
|
36
36
|
categoryId,
|
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getShopConfiguration = void 0;
|
|
7
7
|
const getShopConfiguration = exports.getShopConfiguration = async function getShopConfiguration2({
|
|
8
8
|
cached,
|
|
9
|
-
|
|
9
|
+
sapiClient
|
|
10
10
|
}) {
|
|
11
|
-
return await cached(
|
|
11
|
+
return await cached(sapiClient.shopConfiguration.get, {
|
|
12
12
|
cacheKeyPrefix: "get-shopConfigurations"
|
|
13
13
|
})();
|
|
14
14
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ShopConfiguration } from '@scayle/storefront-api';
|
|
2
2
|
import type { RpcContext } from '../../types';
|
|
3
|
-
declare const getShopConfiguration: ({ cached,
|
|
3
|
+
declare const getShopConfiguration: ({ cached, sapiClient }: RpcContext) => Promise<ShopConfiguration>;
|
|
4
4
|
export { getShopConfiguration };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const getShopConfiguration = async function getShopConfiguration2({ cached,
|
|
2
|
-
return await cached(
|
|
1
|
+
const getShopConfiguration = async function getShopConfiguration2({ cached, sapiClient }) {
|
|
2
|
+
return await cached(sapiClient.shopConfiguration.get, {
|
|
3
3
|
cacheKeyPrefix: "get-shopConfigurations"
|
|
4
4
|
})();
|
|
5
5
|
};
|
|
@@ -12,13 +12,13 @@ const getVariantById = exports.getVariantById = async function getVariantById2({
|
|
|
12
12
|
include = defaultWith,
|
|
13
13
|
pricePromotionKey = "default"
|
|
14
14
|
}, {
|
|
15
|
-
|
|
15
|
+
sapiClient,
|
|
16
16
|
cached,
|
|
17
17
|
campaignKey,
|
|
18
18
|
withParams
|
|
19
19
|
}) {
|
|
20
20
|
const resolvedWith = include ?? withParams?.variant ?? defaultWith;
|
|
21
|
-
return await cached(
|
|
21
|
+
return await cached(sapiClient.variants.getByIds, {
|
|
22
22
|
cacheKeyPrefix: "getByIds-variants"
|
|
23
23
|
})(ids, include ? {
|
|
24
24
|
with: resolvedWith,
|
|
@@ -5,4 +5,4 @@ export interface FetchVariantsParams {
|
|
|
5
5
|
include?: ProductWith;
|
|
6
6
|
pricePromotionKey?: string;
|
|
7
7
|
}
|
|
8
|
-
export declare const getVariantById: ({ ids, include, pricePromotionKey }: FetchVariantsParams, {
|
|
8
|
+
export declare const getVariantById: ({ ids, include, pricePromotionKey }: FetchVariantsParams, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<VariantDetail[]>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const defaultWith = {
|
|
2
2
|
attributes: "all"
|
|
3
3
|
};
|
|
4
|
-
export const getVariantById = async function getVariantById2({ ids, include = defaultWith, pricePromotionKey = "default" }, {
|
|
4
|
+
export const getVariantById = async function getVariantById2({ ids, include = defaultWith, pricePromotionKey = "default" }, { sapiClient, cached, campaignKey, withParams }) {
|
|
5
5
|
const resolvedWith = include ?? withParams?.variant ?? defaultWith;
|
|
6
|
-
return await cached(
|
|
6
|
+
return await cached(sapiClient.variants.getByIds, {
|
|
7
7
|
cacheKeyPrefix: "getByIds-variants"
|
|
8
8
|
})(
|
|
9
9
|
ids,
|
|
@@ -16,14 +16,14 @@ const getWishlist = exports.getWishlist = async function getWishlist2(options, c
|
|
|
16
16
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
17
17
|
}
|
|
18
18
|
const {
|
|
19
|
-
|
|
19
|
+
sapiClient,
|
|
20
20
|
campaignKey,
|
|
21
21
|
wishlistKey
|
|
22
22
|
} = context;
|
|
23
23
|
const resolvedWith = getWithParams({
|
|
24
24
|
with: options
|
|
25
25
|
}, context);
|
|
26
|
-
return await
|
|
26
|
+
return await sapiClient.wishlist.get(wishlistKey, {
|
|
27
27
|
with: resolvedWith,
|
|
28
28
|
campaignKey,
|
|
29
29
|
pricePromotionKey: resolvedWith?.pricePromotionKey ?? ""
|
|
@@ -34,7 +34,7 @@ const addItemToWishlist = exports.addItemToWishlist = async function addItemToWi
|
|
|
34
34
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
35
35
|
}
|
|
36
36
|
const {
|
|
37
|
-
|
|
37
|
+
sapiClient,
|
|
38
38
|
campaignKey,
|
|
39
39
|
wishlistKey
|
|
40
40
|
} = context;
|
|
@@ -47,7 +47,7 @@ const addItemToWishlist = exports.addItemToWishlist = async function addItemToWi
|
|
|
47
47
|
if (!productId && !variantId) {
|
|
48
48
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No productId or variantId given");
|
|
49
49
|
}
|
|
50
|
-
const result = await
|
|
50
|
+
const result = await sapiClient.wishlist.addItem(wishlistKey, variantId ? {
|
|
51
51
|
variantId
|
|
52
52
|
} : {
|
|
53
53
|
productId
|
|
@@ -78,12 +78,12 @@ const removeItemFromWishlist = exports.removeItemFromWishlist = async function r
|
|
|
78
78
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
79
79
|
}
|
|
80
80
|
const {
|
|
81
|
-
|
|
81
|
+
sapiClient,
|
|
82
82
|
campaignKey,
|
|
83
83
|
wishlistKey
|
|
84
84
|
} = context;
|
|
85
85
|
const resolvedWith = getWithParams(options, context);
|
|
86
|
-
return await
|
|
86
|
+
return await sapiClient.wishlist.deleteItem(wishlistKey, options.itemKey, {
|
|
87
87
|
with: resolvedWith,
|
|
88
88
|
campaignKey
|
|
89
89
|
});
|
|
@@ -17,9 +17,9 @@ export const getWishlist = async function getWishlist2(options, context) {
|
|
|
17
17
|
"No Session found"
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
|
-
const {
|
|
20
|
+
const { sapiClient, campaignKey, wishlistKey } = context;
|
|
21
21
|
const resolvedWith = getWithParams({ with: options }, context);
|
|
22
|
-
return await
|
|
22
|
+
return await sapiClient.wishlist.get(wishlistKey, {
|
|
23
23
|
with: resolvedWith,
|
|
24
24
|
campaignKey,
|
|
25
25
|
pricePromotionKey: resolvedWith?.pricePromotionKey ?? ""
|
|
@@ -33,7 +33,7 @@ export const addItemToWishlist = async function addItemToWishlist2(options, cont
|
|
|
33
33
|
"No Session found"
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
-
const {
|
|
36
|
+
const { sapiClient, campaignKey, wishlistKey } = context;
|
|
37
37
|
const { productId, variantId } = options;
|
|
38
38
|
const resolvedWith = getWithParams(options, context);
|
|
39
39
|
const pricePromotionKey = resolvedWith?.pricePromotionKey ?? "";
|
|
@@ -44,7 +44,7 @@ export const addItemToWishlist = async function addItemToWishlist2(options, cont
|
|
|
44
44
|
"No productId or variantId given"
|
|
45
45
|
);
|
|
46
46
|
}
|
|
47
|
-
const result = await
|
|
47
|
+
const result = await sapiClient.wishlist.addItem(
|
|
48
48
|
wishlistKey,
|
|
49
49
|
variantId ? { variantId } : { productId },
|
|
50
50
|
{
|
|
@@ -69,9 +69,9 @@ export const removeItemFromWishlist = async function removeItemFromWishlist2(opt
|
|
|
69
69
|
"No Session found"
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
|
-
const {
|
|
72
|
+
const { sapiClient, campaignKey, wishlistKey } = context;
|
|
73
73
|
const resolvedWith = getWithParams(options, context);
|
|
74
|
-
return await
|
|
74
|
+
return await sapiClient.wishlist.deleteItem(wishlistKey, options.itemKey, {
|
|
75
75
|
with: resolvedWith,
|
|
76
76
|
campaignKey
|
|
77
77
|
});
|
|
@@ -76,7 +76,7 @@ export type RpcContext = {
|
|
|
76
76
|
* @deprecated bapiClient got renamed. Use {@link RpcContext.sapiClient} from now on.
|
|
77
77
|
*/
|
|
78
78
|
bapiClient: StorefrontAPIClient;
|
|
79
|
-
sapiClient
|
|
79
|
+
sapiClient: StorefrontAPIClient;
|
|
80
80
|
cached: CachedType;
|
|
81
81
|
/**
|
|
82
82
|
* @deprecated this flag will be removed in a future release.
|
package/dist/utils/user.cjs
CHANGED
|
@@ -7,10 +7,10 @@ exports.mergeWishlists = exports.mergeBaskets = void 0;
|
|
|
7
7
|
var _constants = require("../constants/index.cjs");
|
|
8
8
|
const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, context) => {
|
|
9
9
|
const {
|
|
10
|
-
|
|
10
|
+
sapiClient,
|
|
11
11
|
campaignKey
|
|
12
12
|
} = context;
|
|
13
|
-
const fromOriginBasket = await
|
|
13
|
+
const fromOriginBasket = await sapiClient.basket.get(fromBasketKey, {
|
|
14
14
|
with: withOptions,
|
|
15
15
|
campaignKey,
|
|
16
16
|
orderCustomData: withOptions.orderCustomData
|
|
@@ -35,7 +35,7 @@ const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, context) =>
|
|
|
35
35
|
pricePromotionKey: withOptions.pricePromotionKey
|
|
36
36
|
}
|
|
37
37
|
}));
|
|
38
|
-
const mergedBasket = await
|
|
38
|
+
const mergedBasket = await sapiClient.basket.addOrUpdateItems(toBasketKey, itemsToAddOrUpdate, {
|
|
39
39
|
with: withOptions,
|
|
40
40
|
campaignKey,
|
|
41
41
|
includeItemsWithoutProductData: withOptions?.includeItemsWithoutProductData,
|
|
@@ -44,7 +44,7 @@ const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, context) =>
|
|
|
44
44
|
existingItemHandling: _constants.ExistingItemHandling.AddQuantityToExisting
|
|
45
45
|
});
|
|
46
46
|
fromBasket.items.map(async item => {
|
|
47
|
-
return await
|
|
47
|
+
return await sapiClient.basket.deleteItem(fromBasketKey, item.key);
|
|
48
48
|
});
|
|
49
49
|
return mergedBasket;
|
|
50
50
|
}
|
|
@@ -52,10 +52,10 @@ const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, context) =>
|
|
|
52
52
|
exports.mergeBaskets = mergeBaskets;
|
|
53
53
|
const mergeWishlists = async (fromWishlistKey, toWishlistKey, withOptions, context) => {
|
|
54
54
|
const {
|
|
55
|
-
|
|
55
|
+
sapiClient,
|
|
56
56
|
campaignKey
|
|
57
57
|
} = context;
|
|
58
|
-
const oldWishlist = await
|
|
58
|
+
const oldWishlist = await sapiClient.wishlist.get(fromWishlistKey, {
|
|
59
59
|
with: withOptions,
|
|
60
60
|
campaignKey
|
|
61
61
|
});
|
|
@@ -67,7 +67,7 @@ const mergeWishlists = async (fromWishlistKey, toWishlistKey, withOptions, conte
|
|
|
67
67
|
variantId
|
|
68
68
|
} = item;
|
|
69
69
|
if (productId || variantId) {
|
|
70
|
-
await
|
|
70
|
+
await sapiClient.wishlist.addItem(toWishlistKey, {
|
|
71
71
|
...(variantId ? {
|
|
72
72
|
variantId
|
|
73
73
|
} : {
|
|
@@ -82,7 +82,7 @@ const mergeWishlists = async (fromWishlistKey, toWishlistKey, withOptions, conte
|
|
|
82
82
|
customData: item.customData
|
|
83
83
|
} : void 0)
|
|
84
84
|
});
|
|
85
|
-
|
|
85
|
+
sapiClient.wishlist.deleteItem(fromWishlistKey, item?.key);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}
|
package/dist/utils/user.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ExistingItemHandling } from "../constants/index.mjs";
|
|
2
2
|
export const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, context) => {
|
|
3
|
-
const {
|
|
4
|
-
const fromOriginBasket = await
|
|
3
|
+
const { sapiClient, campaignKey } = context;
|
|
4
|
+
const fromOriginBasket = await sapiClient.basket.get(fromBasketKey, {
|
|
5
5
|
with: withOptions,
|
|
6
6
|
campaignKey,
|
|
7
7
|
orderCustomData: withOptions.orderCustomData
|
|
@@ -23,7 +23,7 @@ export const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, cont
|
|
|
23
23
|
pricePromotionKey: withOptions.pricePromotionKey
|
|
24
24
|
}
|
|
25
25
|
}));
|
|
26
|
-
const mergedBasket = await
|
|
26
|
+
const mergedBasket = await sapiClient.basket.addOrUpdateItems(
|
|
27
27
|
toBasketKey,
|
|
28
28
|
itemsToAddOrUpdate,
|
|
29
29
|
{
|
|
@@ -37,14 +37,14 @@ export const mergeBaskets = async (fromBasketKey, toBasketKey, withOptions, cont
|
|
|
37
37
|
}
|
|
38
38
|
);
|
|
39
39
|
fromBasket.items.map(async (item) => {
|
|
40
|
-
return await
|
|
40
|
+
return await sapiClient.basket.deleteItem(fromBasketKey, item.key);
|
|
41
41
|
});
|
|
42
42
|
return mergedBasket;
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
export const mergeWishlists = async (fromWishlistKey, toWishlistKey, withOptions, context) => {
|
|
46
|
-
const {
|
|
47
|
-
const oldWishlist = await
|
|
46
|
+
const { sapiClient, campaignKey } = context;
|
|
47
|
+
const oldWishlist = await sapiClient.wishlist.get(fromWishlistKey, {
|
|
48
48
|
with: withOptions,
|
|
49
49
|
campaignKey
|
|
50
50
|
});
|
|
@@ -53,7 +53,7 @@ export const mergeWishlists = async (fromWishlistKey, toWishlistKey, withOptions
|
|
|
53
53
|
for (const item of oldWishlist.items) {
|
|
54
54
|
const { productId, variantId } = item;
|
|
55
55
|
if (productId || variantId) {
|
|
56
|
-
await
|
|
56
|
+
await sapiClient.wishlist.addItem(
|
|
57
57
|
toWishlistKey,
|
|
58
58
|
{
|
|
59
59
|
...variantId ? { variantId } : { productId }
|
|
@@ -64,7 +64,7 @@ export const mergeWishlists = async (fromWishlistKey, toWishlistKey, withOptions
|
|
|
64
64
|
...item.customData && Object.keys(item.customData).length ? { customData: item.customData } : void 0
|
|
65
65
|
}
|
|
66
66
|
);
|
|
67
|
-
|
|
67
|
+
sapiClient.wishlist.deleteItem(fromWishlistKey, item?.key);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/storefront-core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.68.0",
|
|
4
4
|
"description": "Collection of essential utilities to work with the Storefront API",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"test:ci": "vitest --run --passWithNoTests --coverage --reporter=default --reporter=junit --outputFile=./junit.xml"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@scayle/storefront-api": "17.10.
|
|
62
|
+
"@scayle/storefront-api": "17.10.1",
|
|
63
63
|
"crypto-js": "^4.2.0",
|
|
64
64
|
"hookable": "^5.5.3",
|
|
65
65
|
"jose": "^5.6.3",
|