@scayle/storefront-core 7.69.3 → 8.1.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 +209 -0
- package/dist/cache/cached.cjs +1 -1
- package/dist/cache/cached.d.ts +1 -1
- package/dist/cache/cached.mjs +1 -1
- package/dist/constants/basket.cjs +15 -1
- package/dist/constants/basket.d.ts +16 -0
- package/dist/constants/basket.mjs +14 -0
- package/dist/errors/errorResponse.d.ts +1 -1
- package/dist/errors/index.cjs +0 -22
- package/dist/errors/index.d.ts +0 -2
- package/dist/errors/index.mjs +0 -2
- package/dist/helpers/productHelpers.cjs +1 -35
- package/dist/helpers/productHelpers.d.ts +0 -8
- package/dist/helpers/productHelpers.mjs +0 -27
- package/dist/rpc/methods/basket/basket.cjs +33 -9
- package/dist/rpc/methods/basket/basket.d.ts +20 -4
- package/dist/rpc/methods/basket/basket.mjs +32 -14
- package/dist/rpc/methods/brands.cjs +3 -2
- package/dist/rpc/methods/brands.d.ts +2 -2
- package/dist/rpc/methods/brands.mjs +3 -2
- package/dist/rpc/methods/categories.cjs +3 -2
- package/dist/rpc/methods/categories.d.ts +2 -2
- package/dist/rpc/methods/categories.mjs +13 -6
- package/dist/rpc/methods/cbd.d.ts +1 -1
- package/dist/rpc/methods/checkout/checkout.cjs +1 -1
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/checkout/order.d.ts +1 -1
- package/dist/rpc/methods/oauth/idp.cjs +1 -2
- package/dist/rpc/methods/oauth/idp.d.ts +1 -1
- package/dist/rpc/methods/oauth/idp.mjs +1 -2
- package/dist/rpc/methods/products.cjs +4 -3
- package/dist/rpc/methods/products.d.ts +3 -3
- package/dist/rpc/methods/products.mjs +22 -12
- package/dist/rpc/methods/promotion.cjs +4 -3
- package/dist/rpc/methods/promotion.d.ts +3 -3
- package/dist/rpc/methods/promotion.mjs +9 -5
- package/dist/rpc/methods/search.cjs +3 -33
- package/dist/rpc/methods/search.d.ts +1 -11
- package/dist/rpc/methods/search.mjs +2 -23
- package/dist/rpc/methods/shopConfiguration.cjs +2 -1
- package/dist/rpc/methods/shopConfiguration.d.ts +1 -1
- package/dist/rpc/methods/shopConfiguration.mjs +7 -3
- package/dist/rpc/methods/user.cjs +3 -15
- package/dist/rpc/methods/user.d.ts +1 -1
- package/dist/rpc/methods/user.mjs +2 -15
- package/dist/rpc/methods/variants.cjs +2 -1
- package/dist/rpc/methods/variants.d.ts +1 -1
- package/dist/rpc/methods/variants.mjs +7 -3
- package/dist/rpc/methods/wishlist.cjs +3 -2
- package/dist/rpc/methods/wishlist.d.ts +3 -4
- package/dist/rpc/methods/wishlist.mjs +17 -9
- package/dist/server.cjs +1 -24
- package/dist/server.d.ts +0 -3
- package/dist/server.mjs +0 -2
- package/dist/types/api/auth.d.ts +0 -9
- package/dist/types/api/context.d.ts +0 -12
- package/dist/types/user.d.ts +0 -4
- package/dist/utils/basket.cjs +14 -0
- package/dist/utils/basket.d.ts +2 -0
- package/dist/utils/basket.mjs +12 -0
- package/dist/utils/index.cjs +11 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.mjs +1 -0
- package/dist/utils/keys.cjs +3 -3
- package/dist/utils/keys.mjs +3 -3
- package/dist/utils/sapi.cjs +19 -0
- package/dist/utils/sapi.d.ts +5 -0
- package/dist/utils/sapi.mjs +13 -0
- package/package.json +6 -9
- package/dist/bapi/init.cjs +0 -19
- package/dist/bapi/init.d.ts +0 -15
- package/dist/bapi/init.mjs +0 -12
- package/dist/cache/providers/redis.cjs +0 -94
- package/dist/cache/providers/redis.d.ts +0 -28
- package/dist/cache/providers/redis.mjs +0 -86
- package/dist/errors/BAPIError.cjs +0 -18
- package/dist/errors/BAPIError.d.ts +0 -8
- package/dist/errors/BAPIError.mjs +0 -11
- package/dist/errors/baseError.cjs +0 -17
- package/dist/errors/baseError.d.ts +0 -5
- package/dist/errors/baseError.mjs +0 -10
- package/dist/utils/compression.cjs +0 -25
- package/dist/utils/compression.d.ts +0 -2
- package/dist/utils/compression.mjs +0 -17
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "../../../constants/index.mjs";
|
|
9
9
|
import { mergeBaskets as mergeBasketFunction } from "../../../utils/user.mjs";
|
|
10
10
|
import { unwrap } from "../../../utils/response.mjs";
|
|
11
|
+
import { wasAddedWithReducedQuantity } from "../../../utils/index.mjs";
|
|
11
12
|
const SAPI_ERROR_NAME = "SAPI ERROR";
|
|
12
13
|
function getWithParams(params, context) {
|
|
13
14
|
return params.with ?? context.withParams?.basket ?? MIN_WITH_PARAMS_BASKET;
|
|
@@ -62,16 +63,22 @@ export const addItemToBasket = async function addItemToBasket2({
|
|
|
62
63
|
}
|
|
63
64
|
);
|
|
64
65
|
if (result.type === "success") {
|
|
65
|
-
return result.basket;
|
|
66
|
+
return { basket: result.basket };
|
|
67
|
+
} else if (result.type === "failure" && wasAddedWithReducedQuantity(result.errors)) {
|
|
68
|
+
return {
|
|
69
|
+
basket: result.basket,
|
|
70
|
+
errors: result.errors
|
|
71
|
+
};
|
|
66
72
|
} else {
|
|
67
73
|
const { message, statusCode } = parseBasketError(result);
|
|
68
74
|
context.log.error("Adding item to basket failed", { message, statusCode });
|
|
69
75
|
return new ErrorResponse(
|
|
70
|
-
|
|
76
|
+
HttpStatusCode.BAD_REQUEST,
|
|
71
77
|
SAPI_ERROR_NAME,
|
|
72
78
|
"Adding item to basket failed",
|
|
73
79
|
{
|
|
74
|
-
detail: message
|
|
80
|
+
detail: message,
|
|
81
|
+
errors: result.errors
|
|
75
82
|
}
|
|
76
83
|
);
|
|
77
84
|
}
|
|
@@ -113,7 +120,12 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
113
120
|
}
|
|
114
121
|
);
|
|
115
122
|
if (result.type === "success") {
|
|
116
|
-
return result.basket;
|
|
123
|
+
return { basket: result.basket };
|
|
124
|
+
} else if (result.type === "failure" && wasAddedWithReducedQuantity(result.errors)) {
|
|
125
|
+
return {
|
|
126
|
+
basket: result.basket,
|
|
127
|
+
errors: result.errors
|
|
128
|
+
};
|
|
117
129
|
} else {
|
|
118
130
|
const { statusCode, message } = parseBasketError(result);
|
|
119
131
|
context.log.error("Adding one or more items to basket failed", {
|
|
@@ -121,11 +133,12 @@ export const addItemsToBasket = async function addItemsToBasket2(params, context
|
|
|
121
133
|
message
|
|
122
134
|
});
|
|
123
135
|
return new ErrorResponse(
|
|
124
|
-
|
|
136
|
+
HttpStatusCode.BAD_REQUEST,
|
|
125
137
|
SAPI_ERROR_NAME,
|
|
126
138
|
"Adding one or more items to basket failed",
|
|
127
139
|
{
|
|
128
|
-
detail: message
|
|
140
|
+
detail: message,
|
|
141
|
+
errors: result.errors
|
|
129
142
|
}
|
|
130
143
|
);
|
|
131
144
|
}
|
|
@@ -160,7 +173,7 @@ export const getBasket = async function getBasket2(options, context) {
|
|
|
160
173
|
}
|
|
161
174
|
);
|
|
162
175
|
}
|
|
163
|
-
return response.basket;
|
|
176
|
+
return { basket: response.basket };
|
|
164
177
|
};
|
|
165
178
|
export const removeItemFromBasket = async function removeItemFromBasket2(options, context) {
|
|
166
179
|
if (!hasSession(context)) {
|
|
@@ -172,19 +185,24 @@ export const removeItemFromBasket = async function removeItemFromBasket2(options
|
|
|
172
185
|
}
|
|
173
186
|
const { sapiClient, campaignKey, basketKey } = context;
|
|
174
187
|
const resolvedWith = getWithParams(options, context);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
188
|
+
const basket = await sapiClient.basket.deleteItem(
|
|
189
|
+
basketKey,
|
|
190
|
+
options.itemKey,
|
|
191
|
+
{
|
|
192
|
+
with: resolvedWith,
|
|
193
|
+
campaignKey,
|
|
194
|
+
includeItemsWithoutProductData: resolvedWith?.includeItemsWithoutProductData,
|
|
195
|
+
orderCustomData: options.orderCustomData
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
return { basket };
|
|
181
199
|
};
|
|
182
200
|
export const clearBasket = async function clearBasket2(context) {
|
|
183
201
|
const getBasketResponse = await getBasket({}, context);
|
|
184
202
|
if (getBasketResponse instanceof ErrorResponse) {
|
|
185
203
|
return getBasketResponse;
|
|
186
204
|
}
|
|
187
|
-
const basket = await unwrap(getBasketResponse);
|
|
205
|
+
const { basket } = await unwrap(getBasketResponse);
|
|
188
206
|
await Promise.all(
|
|
189
207
|
basket.items.map(async (item) => {
|
|
190
208
|
await removeItemFromBasket({ itemKey: item.key }, context);
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getBrands = exports.getBrandById = void 0;
|
|
7
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
7
8
|
const MAX_PER_PAGE = 100;
|
|
8
9
|
const getBrands = exports.getBrands = async function getBrands2({
|
|
9
10
|
pagination
|
|
@@ -11,7 +12,7 @@ const getBrands = exports.getBrands = async function getBrands2({
|
|
|
11
12
|
sapiClient,
|
|
12
13
|
cached
|
|
13
14
|
}) {
|
|
14
|
-
return await cached(sapiClient.brands.get, {
|
|
15
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.brands.get), {
|
|
15
16
|
cacheKeyPrefix: "getBrands"
|
|
16
17
|
})({
|
|
17
18
|
pagination: {
|
|
@@ -26,7 +27,7 @@ const getBrandById = exports.getBrandById = async function getBrandById2({
|
|
|
26
27
|
sapiClient,
|
|
27
28
|
cached
|
|
28
29
|
}) {
|
|
29
|
-
return await cached(sapiClient.brands.getById, {
|
|
30
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.brands.getById), {
|
|
30
31
|
cacheKeyPrefix: `getBrandById-${brandId}`
|
|
31
32
|
})(brandId);
|
|
32
33
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Brand, BrandsEndpointRequestParameters, BrandsEndpointResponseData } from '../../types';
|
|
2
|
-
export declare const getBrands: ({ pagination }: BrandsEndpointRequestParameters, { sapiClient, cached }: import("../../types").RpcContext) => Promise<BrandsEndpointResponseData>;
|
|
2
|
+
export declare const getBrands: ({ pagination }: BrandsEndpointRequestParameters, { sapiClient, cached }: import("../../types").RpcContext) => Promise<Response | BrandsEndpointResponseData>;
|
|
3
3
|
export declare const getBrandById: ({ brandId }: {
|
|
4
4
|
brandId: number;
|
|
5
|
-
}, { sapiClient, cached }: import("../../types").RpcContext) => Promise<Brand>;
|
|
5
|
+
}, { sapiClient, cached }: import("../../types").RpcContext) => Promise<Response | Brand>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
1
2
|
const MAX_PER_PAGE = 100;
|
|
2
3
|
export const getBrands = async function getBrands2({ pagination }, { sapiClient, cached }) {
|
|
3
|
-
return await cached(sapiClient.brands.get, {
|
|
4
|
+
return await cached(mapSAPIFetchErrorToResponse(sapiClient.brands.get), {
|
|
4
5
|
cacheKeyPrefix: "getBrands"
|
|
5
6
|
})({
|
|
6
7
|
pagination: {
|
|
@@ -10,7 +11,7 @@ export const getBrands = async function getBrands2({ pagination }, { sapiClient,
|
|
|
10
11
|
});
|
|
11
12
|
};
|
|
12
13
|
export const getBrandById = async function getBrandById2({ brandId }, { sapiClient, cached }) {
|
|
13
|
-
return await cached(sapiClient.brands.getById, {
|
|
14
|
+
return await cached(mapSAPIFetchErrorToResponse(sapiClient.brands.getById), {
|
|
14
15
|
cacheKeyPrefix: `getBrandById-${brandId}`
|
|
15
16
|
})(brandId);
|
|
16
17
|
};
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getRootCategories = exports.getCategoryByPath = exports.getCategoryById = exports.getCategoriesByPath = void 0;
|
|
7
7
|
var _helpers = require("../../helpers/index.cjs");
|
|
8
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
8
9
|
const getRootCategories = exports.getRootCategories = async function getRootCategories2({
|
|
9
10
|
children = 1,
|
|
10
11
|
includeHidden,
|
|
@@ -38,7 +39,7 @@ const getCategoryByPath = exports.getCategoryByPath = async function getCategory
|
|
|
38
39
|
sapiClient
|
|
39
40
|
} = context;
|
|
40
41
|
const sanitizedPath = (0, _helpers.splitAndRemoveEmpty)(path);
|
|
41
|
-
return await cached(sapiClient.categories.getByPath, {
|
|
42
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.categories.getByPath), {
|
|
42
43
|
cacheKeyPrefix: `getByPath-category-${sanitizedPath}`
|
|
43
44
|
})(sanitizedPath, {
|
|
44
45
|
with: {
|
|
@@ -115,7 +116,7 @@ const getCategoryById = exports.getCategoryById = async function getCategoryById
|
|
|
115
116
|
cached,
|
|
116
117
|
sapiClient
|
|
117
118
|
} = context;
|
|
118
|
-
return await cached(sapiClient.categories.getById, {
|
|
119
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.categories.getById), {
|
|
119
120
|
cacheKeyPrefix: `getById-categories-${id}`
|
|
120
121
|
})(id, {
|
|
121
122
|
with: {
|
|
@@ -12,7 +12,7 @@ export declare const getCategoryByPath: ({ path, children, includeHidden, proper
|
|
|
12
12
|
children?: number;
|
|
13
13
|
includeHidden?: true;
|
|
14
14
|
properties?: ProductCategoryPropertyWith;
|
|
15
|
-
}, context: import("../../types").RpcContext) => Promise<Category>;
|
|
15
|
+
}, context: import("../../types").RpcContext) => Promise<Response | Category>;
|
|
16
16
|
export declare const getCategoriesByPath: ({ path, children, includeHidden, properties }: {
|
|
17
17
|
path: string;
|
|
18
18
|
children?: number;
|
|
@@ -30,4 +30,4 @@ export declare const getCategoryById: ({ id, children, includeHidden, properties
|
|
|
30
30
|
children?: number;
|
|
31
31
|
includeHidden?: true;
|
|
32
32
|
properties?: ProductCategoryPropertyWith;
|
|
33
|
-
}, context: import("../../types").RpcContext) => Promise<Category>;
|
|
33
|
+
}, context: import("../../types").RpcContext) => Promise<Response | Category>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { splitAndRemoveEmpty } from "../../helpers/index.mjs";
|
|
2
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
2
3
|
export const getRootCategories = async function getRootCategories2({ children = 1, includeHidden, properties }, { cached, sapiClient }) {
|
|
3
4
|
const result = await cached(sapiClient.categories.getRoots, {
|
|
4
5
|
cacheKeyPrefix: "root-categories"
|
|
@@ -14,9 +15,12 @@ export const getRootCategories = async function getRootCategories2({ children =
|
|
|
14
15
|
export const getCategoryByPath = async function getCategoryByPath2({ path, children = 1, includeHidden, properties }, context) {
|
|
15
16
|
const { cached, sapiClient } = context;
|
|
16
17
|
const sanitizedPath = splitAndRemoveEmpty(path);
|
|
17
|
-
return await cached(
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
return await cached(
|
|
19
|
+
mapSAPIFetchErrorToResponse(sapiClient.categories.getByPath),
|
|
20
|
+
{
|
|
21
|
+
cacheKeyPrefix: `getByPath-category-${sanitizedPath}`
|
|
22
|
+
}
|
|
23
|
+
)(sanitizedPath, { with: { children, properties }, includeHidden });
|
|
20
24
|
};
|
|
21
25
|
export const getCategoriesByPath = async function getCategoriesByPath2({ path, children = 1, includeHidden, properties }, context) {
|
|
22
26
|
const { cached, sapiClient } = context;
|
|
@@ -63,9 +67,12 @@ export const getCategoriesByPath = async function getCategoriesByPath2({ path, c
|
|
|
63
67
|
};
|
|
64
68
|
export const getCategoryById = async function getCategoryById2({ id, children = 1, includeHidden, properties }, context) {
|
|
65
69
|
const { cached, sapiClient } = context;
|
|
66
|
-
return await cached(
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
return await cached(
|
|
71
|
+
mapSAPIFetchErrorToResponse(sapiClient.categories.getById),
|
|
72
|
+
{
|
|
73
|
+
cacheKeyPrefix: `getById-categories-${id}`
|
|
74
|
+
}
|
|
75
|
+
)(id, {
|
|
69
76
|
with: {
|
|
70
77
|
children,
|
|
71
78
|
parents: "all",
|
|
@@ -2,4 +2,4 @@ import { ErrorResponse } from '../../errors';
|
|
|
2
2
|
import type { Order, RpcContext } from '../../types';
|
|
3
3
|
export declare const getOrderDataByCbd: ({ cbdToken }: {
|
|
4
4
|
cbdToken: string;
|
|
5
|
-
}, context: RpcContext) => Promise<
|
|
5
|
+
}, context: RpcContext) => Promise<ErrorResponse | Order>;
|
|
@@ -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"}@${"
|
|
40
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.1.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"}@${"
|
|
38
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.1.0"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
39
39
|
return {
|
|
40
40
|
accessToken: refreshedAccessToken,
|
|
41
41
|
checkoutJwt
|
|
@@ -2,4 +2,4 @@ import { ErrorResponse } from '../../../errors';
|
|
|
2
2
|
import type { Order } from '../../../types';
|
|
3
3
|
export declare const getOrderById: ({ orderId }: {
|
|
4
4
|
orderId: number;
|
|
5
|
-
}, context: import("../../../types").RpcContext) => Promise<
|
|
5
|
+
}, context: import("../../../types").RpcContext) => Promise<ErrorResponse | Order>;
|
|
@@ -51,8 +51,7 @@ const handleIDPLoginCallback = exports.handleIDPLoginCallback = async function h
|
|
|
51
51
|
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
52
52
|
}
|
|
53
53
|
const OAuthClient = (0, _oauth.getOAuthClient)(context);
|
|
54
|
-
const
|
|
55
|
-
const tokens = await OAuthClient.generateToken(code);
|
|
54
|
+
const tokens = await OAuthClient.generateToken(payload.code);
|
|
56
55
|
await (0, _session.postLogin)(context, tokens);
|
|
57
56
|
return {
|
|
58
57
|
message: "success"
|
|
@@ -7,6 +7,6 @@ export declare const getExternalIdpRedirect: ({ queryParams }: {
|
|
|
7
7
|
}>;
|
|
8
8
|
export declare const handleIDPLoginCallback: (payload: {
|
|
9
9
|
code: string;
|
|
10
|
-
}
|
|
10
|
+
}, context: RpcContext) => Promise<ErrorResponse | {
|
|
11
11
|
message: string;
|
|
12
12
|
}>;
|
|
@@ -54,8 +54,7 @@ export const handleIDPLoginCallback = async function handleIDPLoginCallback2(pay
|
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
const OAuthClient = getOAuthClient(context);
|
|
57
|
-
const
|
|
58
|
-
const tokens = await OAuthClient.generateToken(code);
|
|
57
|
+
const tokens = await OAuthClient.generateToken(payload.code);
|
|
59
58
|
await postLogin(context, tokens);
|
|
60
59
|
return {
|
|
61
60
|
message: "success"
|
|
@@ -9,6 +9,7 @@ var _helpers = require("../../helpers/index.cjs");
|
|
|
9
9
|
var _constants = require("../../constants/index.cjs");
|
|
10
10
|
var _cache = require("../../cache/index.cjs");
|
|
11
11
|
var _response = require("../../utils/response.cjs");
|
|
12
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
12
13
|
var _errors = require("../../errors/index.cjs");
|
|
13
14
|
const MAX_PER_PAGE = 100;
|
|
14
15
|
const sanitizeAttributesForSAPI = ({
|
|
@@ -48,7 +49,7 @@ const getProductById = exports.getProductById = async function getProductById2(o
|
|
|
48
49
|
campaignKey,
|
|
49
50
|
withParams
|
|
50
51
|
}) {
|
|
51
|
-
return await cached(sapiClient.products.getById, {
|
|
52
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.products.getById), {
|
|
52
53
|
cacheKeyPrefix: `getById-product-${options.id}`,
|
|
53
54
|
ttl: 5 * _cache.MINUTE
|
|
54
55
|
})(options.id, {
|
|
@@ -64,7 +65,7 @@ const getProductsByIds = exports.getProductsByIds = async function getProductsBy
|
|
|
64
65
|
campaignKey,
|
|
65
66
|
withParams
|
|
66
67
|
}) {
|
|
67
|
-
return await cached(sapiClient.products.getByIds, {
|
|
68
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.products.getByIds), {
|
|
68
69
|
cacheKeyPrefix: "getByIds-products",
|
|
69
70
|
ttl: 5 * _cache.MINUTE
|
|
70
71
|
})(options.ids, {
|
|
@@ -79,7 +80,7 @@ const getProductsByReferenceKeys = exports.getProductsByReferenceKeys = async fu
|
|
|
79
80
|
campaignKey,
|
|
80
81
|
withParams
|
|
81
82
|
}) {
|
|
82
|
-
return await cached(sapiClient.products.getByReferenceKeys, {
|
|
83
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.products.getByReferenceKeys), {
|
|
83
84
|
cacheKeyPrefix: "getByReferenceKeys-products",
|
|
84
85
|
ttl: 5 * _cache.MINUTE
|
|
85
86
|
})(options.referenceKeys, {
|
|
@@ -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, { 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[]>;
|
|
23
|
+
export declare const getProductById: (options: FetchProductParams, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Response | Product>;
|
|
24
|
+
export declare const getProductsByIds: (options: FetchProductsByIdsParams, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Response | Product[]>;
|
|
25
|
+
export declare const getProductsByReferenceKeys: (options: FetchProductsByReferenceKeysParams, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Response | Product[]>;
|
|
26
26
|
export declare const getProductsCount: (params: FetchProductsCountParams, context: RpcContext) => Promise<(string[] & ErrorResponse) | {
|
|
27
27
|
count: number;
|
|
28
28
|
}>;
|
|
@@ -2,6 +2,7 @@ import { splitAndRemoveEmpty } from "../../helpers/index.mjs";
|
|
|
2
2
|
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
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
5
6
|
import { ErrorResponse } from "../../errors/index.mjs";
|
|
6
7
|
const MAX_PER_PAGE = 100;
|
|
7
8
|
const sanitizeAttributesForSAPI = ({
|
|
@@ -34,10 +35,13 @@ export async function resolveCategoryIdFromParams(context, params) {
|
|
|
34
35
|
return { category, categoryId };
|
|
35
36
|
}
|
|
36
37
|
export const getProductById = async function getProductById2(options, { sapiClient, cached, campaignKey, withParams }) {
|
|
37
|
-
return await cached(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
return await cached(
|
|
39
|
+
mapSAPIFetchErrorToResponse(sapiClient.products.getById),
|
|
40
|
+
{
|
|
41
|
+
cacheKeyPrefix: `getById-product-${options.id}`,
|
|
42
|
+
ttl: 5 * MINUTE
|
|
43
|
+
}
|
|
44
|
+
)(options.id, {
|
|
41
45
|
with: options.with ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
42
46
|
campaignKey,
|
|
43
47
|
pricePromotionKey: options.pricePromotionKey,
|
|
@@ -45,20 +49,26 @@ export const getProductById = async function getProductById2(options, { sapiClie
|
|
|
45
49
|
});
|
|
46
50
|
};
|
|
47
51
|
export const getProductsByIds = async function getProductsByIds2(options, { sapiClient, cached, campaignKey, withParams }) {
|
|
48
|
-
return await cached(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
return await cached(
|
|
53
|
+
mapSAPIFetchErrorToResponse(sapiClient.products.getByIds),
|
|
54
|
+
{
|
|
55
|
+
cacheKeyPrefix: "getByIds-products",
|
|
56
|
+
ttl: 5 * MINUTE
|
|
57
|
+
}
|
|
58
|
+
)(options.ids, {
|
|
52
59
|
with: options.with ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
53
60
|
campaignKey,
|
|
54
61
|
pricePromotionKey: options.pricePromotionKey
|
|
55
62
|
});
|
|
56
63
|
};
|
|
57
64
|
export const getProductsByReferenceKeys = async function getProductsByReferenceKeys2(options, { sapiClient, cached, campaignKey, withParams }) {
|
|
58
|
-
return await cached(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
return await cached(
|
|
66
|
+
mapSAPIFetchErrorToResponse(sapiClient.products.getByReferenceKeys),
|
|
67
|
+
{
|
|
68
|
+
cacheKeyPrefix: "getByReferenceKeys-products",
|
|
69
|
+
ttl: 5 * MINUTE
|
|
70
|
+
}
|
|
71
|
+
)(options.referenceKeys, {
|
|
62
72
|
with: options.with ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
63
73
|
campaignKey,
|
|
64
74
|
pricePromotionKey: options.pricePromotionKey
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getPromotionsByIds = exports.getPromotions = exports.getCurrentPromotions = void 0;
|
|
7
7
|
var _constants = require("../../constants/index.cjs");
|
|
8
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
8
9
|
const setPaginationDefault = pagination => {
|
|
9
10
|
return {
|
|
10
11
|
page: pagination?.page || _constants.PROMOTION_PAGE_DEFAULT,
|
|
@@ -16,7 +17,7 @@ const getPromotions = exports.getPromotions = async function getPromotions2(para
|
|
|
16
17
|
sapiClient,
|
|
17
18
|
cached
|
|
18
19
|
} = context;
|
|
19
|
-
return await cached(sapiClient.promotions.get, {
|
|
20
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.promotions.get), {
|
|
20
21
|
cacheKeyPrefix: "getPromotions"
|
|
21
22
|
})({
|
|
22
23
|
...params,
|
|
@@ -31,7 +32,7 @@ const getCurrentPromotions = exports.getCurrentPromotions = async function getCu
|
|
|
31
32
|
const now = /* @__PURE__ */new Date();
|
|
32
33
|
now.setSeconds(0, 0);
|
|
33
34
|
const activeAt = now.toISOString();
|
|
34
|
-
return await cached(sapiClient.promotions.get, {
|
|
35
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.promotions.get), {
|
|
35
36
|
cacheKeyPrefix: "getPromotions"
|
|
36
37
|
})({
|
|
37
38
|
...params,
|
|
@@ -44,7 +45,7 @@ const getPromotionsByIds = exports.getPromotionsByIds = async function getPromot
|
|
|
44
45
|
sapiClient,
|
|
45
46
|
cached
|
|
46
47
|
} = context;
|
|
47
|
-
return await cached(sapiClient.promotions.getByIds, {
|
|
48
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.promotions.getByIds), {
|
|
48
49
|
cacheKeyPrefix: "getByIds-promotions"
|
|
49
50
|
})(ids);
|
|
50
51
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { PromotionsParams, PromotionsResponseData } from '../../types';
|
|
2
|
-
export declare const getPromotions: (params: Omit<PromotionsParams, "ids"> | undefined, context: import("../../types").RpcContext) => Promise<PromotionsResponseData>;
|
|
3
|
-
export declare const getCurrentPromotions: (params: Omit<PromotionsParams, "ids" | "activeAt"> | undefined, context: import("../../types").RpcContext) => Promise<PromotionsResponseData>;
|
|
4
|
-
export declare const getPromotionsByIds: (ids: string[], context: import("../../types").RpcContext) => Promise<PromotionsResponseData>;
|
|
2
|
+
export declare const getPromotions: (params: Omit<PromotionsParams, "ids"> | undefined, context: import("../../types").RpcContext) => Promise<Response | PromotionsResponseData>;
|
|
3
|
+
export declare const getCurrentPromotions: (params: Omit<PromotionsParams, "ids" | "activeAt"> | undefined, context: import("../../types").RpcContext) => Promise<Response | PromotionsResponseData>;
|
|
4
|
+
export declare const getPromotionsByIds: (ids: string[], context: import("../../types").RpcContext) => Promise<Response | PromotionsResponseData>;
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
PROMOTION_PAGE_DEFAULT,
|
|
3
3
|
PROMOTION_PER_PAGE_DEFAULT
|
|
4
4
|
} from "../../constants/index.mjs";
|
|
5
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
5
6
|
const setPaginationDefault = (pagination) => {
|
|
6
7
|
return {
|
|
7
8
|
page: pagination?.page || PROMOTION_PAGE_DEFAULT,
|
|
@@ -10,7 +11,7 @@ const setPaginationDefault = (pagination) => {
|
|
|
10
11
|
};
|
|
11
12
|
export const getPromotions = async function getPromotions2(params = {}, context) {
|
|
12
13
|
const { sapiClient, cached } = context;
|
|
13
|
-
return await cached(sapiClient.promotions.get, {
|
|
14
|
+
return await cached(mapSAPIFetchErrorToResponse(sapiClient.promotions.get), {
|
|
14
15
|
cacheKeyPrefix: "getPromotions"
|
|
15
16
|
})({
|
|
16
17
|
...params,
|
|
@@ -22,7 +23,7 @@ export const getCurrentPromotions = async function getCurrentPromotions2(params
|
|
|
22
23
|
const now = /* @__PURE__ */ new Date();
|
|
23
24
|
now.setSeconds(0, 0);
|
|
24
25
|
const activeAt = now.toISOString();
|
|
25
|
-
return await cached(sapiClient.promotions.get, {
|
|
26
|
+
return await cached(mapSAPIFetchErrorToResponse(sapiClient.promotions.get), {
|
|
26
27
|
cacheKeyPrefix: "getPromotions"
|
|
27
28
|
})({
|
|
28
29
|
...params,
|
|
@@ -32,7 +33,10 @@ export const getCurrentPromotions = async function getCurrentPromotions2(params
|
|
|
32
33
|
};
|
|
33
34
|
export const getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
|
|
34
35
|
const { sapiClient, cached } = context;
|
|
35
|
-
return await cached(
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
return await cached(
|
|
37
|
+
mapSAPIFetchErrorToResponse(sapiClient.promotions.getByIds),
|
|
38
|
+
{
|
|
39
|
+
cacheKeyPrefix: "getByIds-promotions"
|
|
40
|
+
}
|
|
41
|
+
)(ids);
|
|
38
42
|
};
|
|
@@ -3,38 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var
|
|
8
|
-
var _stringHelpers = require("../../helpers/stringHelpers.cjs");
|
|
9
|
-
const getCategoryId = async (cached, sapiClient, slug) => {
|
|
10
|
-
if (!slug) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const sanitizedPath = (0, _stringHelpers.splitAndRemoveEmpty)(slug);
|
|
14
|
-
const result = await cached(sapiClient.categories.getByPath, {
|
|
15
|
-
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
16
|
-
})(sanitizedPath);
|
|
17
|
-
return result.id;
|
|
18
|
-
};
|
|
19
|
-
const searchProducts = exports.searchProducts = async function searchProducts2({
|
|
20
|
-
term,
|
|
21
|
-
slug,
|
|
22
|
-
with: _with,
|
|
23
|
-
productLimit
|
|
24
|
-
}, {
|
|
25
|
-
cached,
|
|
26
|
-
sapiClient,
|
|
27
|
-
withParams
|
|
28
|
-
}) {
|
|
29
|
-
const categoryId = await getCategoryId(cached, sapiClient, slug);
|
|
30
|
-
return await cached(sapiClient.typeahead.suggestions, {
|
|
31
|
-
cacheKeyPrefix: `typeahead-suggestions-${term}`
|
|
32
|
-
})(term, {
|
|
33
|
-
productLimit,
|
|
34
|
-
categoryId,
|
|
35
|
-
with: _with ?? withParams?.search ?? _constants.MIN_WITH_PARAMS_SEARCH
|
|
36
|
-
});
|
|
37
|
-
};
|
|
6
|
+
exports.resolveSearch = exports.getSearchSuggestions = void 0;
|
|
7
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
38
8
|
const getSearchSuggestions = exports.getSearchSuggestions = async function getSearchSuggestions2({
|
|
39
9
|
term,
|
|
40
10
|
with: _with,
|
|
@@ -43,7 +13,7 @@ const getSearchSuggestions = exports.getSearchSuggestions = async function getSe
|
|
|
43
13
|
sapiClient,
|
|
44
14
|
withParams
|
|
45
15
|
}) {
|
|
46
|
-
return await sapiClient.searchv2.suggestions(term, {
|
|
16
|
+
return await (0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.searchv2.suggestions)(term, {
|
|
47
17
|
categoryId,
|
|
48
18
|
with: _with ?? withParams?.searchV2
|
|
49
19
|
});
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import type { TypeaheadSuggestionsEndpointRequestParameters, TypeaheadSuggestionsEndpointResponseData } from '@scayle/storefront-api';
|
|
2
1
|
import type { SearchV2ResolveEndpointParameters, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
|
|
3
|
-
|
|
4
|
-
/** @deprecated `searchProducts` is deprecated. Please, use `getSuggestions` or `resolve` RPC methods */
|
|
5
|
-
export declare const searchProducts: ({ term, slug, with: _with, productLimit }: {
|
|
6
|
-
term: string;
|
|
7
|
-
slug?: string;
|
|
8
|
-
with?: SearchWith;
|
|
9
|
-
productLimit?: number;
|
|
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>;
|
|
2
|
+
export declare const getSearchSuggestions: ({ term, with: _with, categoryId }: SearchV2SuggestionsEndpointParameters, { sapiClient, withParams }: import("../../types").RpcContext) => Promise<Response | SearchV2SuggestionsEndpointResponseData>;
|
|
12
3
|
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, { cached, sapiClient, withParams }: import("../../types").RpcContext) => Promise<import("@scayle/storefront-api").SearchEntity | null>;
|
|
13
|
-
export {};
|
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { splitAndRemoveEmpty } from "../../helpers/stringHelpers.mjs";
|
|
3
|
-
const getCategoryId = async (cached, sapiClient, slug) => {
|
|
4
|
-
if (!slug) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
const sanitizedPath = splitAndRemoveEmpty(slug);
|
|
8
|
-
const result = await cached(sapiClient.categories.getByPath, {
|
|
9
|
-
cacheKeyPrefix: `getByPath-categories-${sanitizedPath}`
|
|
10
|
-
})(sanitizedPath);
|
|
11
|
-
return result.id;
|
|
12
|
-
};
|
|
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
|
-
cacheKeyPrefix: `typeahead-suggestions-${term}`
|
|
17
|
-
})(term, {
|
|
18
|
-
productLimit,
|
|
19
|
-
categoryId,
|
|
20
|
-
with: _with ?? withParams?.search ?? MIN_WITH_PARAMS_SEARCH
|
|
21
|
-
});
|
|
22
|
-
};
|
|
1
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
23
2
|
export const getSearchSuggestions = async function getSearchSuggestions2({ term, with: _with, categoryId }, { sapiClient, withParams }) {
|
|
24
|
-
return await sapiClient.searchv2.suggestions(
|
|
3
|
+
return await mapSAPIFetchErrorToResponse(sapiClient.searchv2.suggestions)(
|
|
25
4
|
term,
|
|
26
5
|
{
|
|
27
6
|
categoryId,
|
|
@@ -4,11 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getShopConfiguration = void 0;
|
|
7
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
7
8
|
const getShopConfiguration = exports.getShopConfiguration = async function getShopConfiguration2({
|
|
8
9
|
cached,
|
|
9
10
|
sapiClient
|
|
10
11
|
}) {
|
|
11
|
-
return await cached(sapiClient.shopConfiguration.get, {
|
|
12
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.shopConfiguration.get), {
|
|
12
13
|
cacheKeyPrefix: "get-shopConfigurations"
|
|
13
14
|
})();
|
|
14
15
|
};
|
|
@@ -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, sapiClient }: RpcContext) => Promise<ShopConfiguration>;
|
|
3
|
+
declare const getShopConfiguration: ({ cached, sapiClient }: RpcContext) => Promise<Response | ShopConfiguration>;
|
|
4
4
|
export { getShopConfiguration };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
1
2
|
const getShopConfiguration = async function getShopConfiguration2({ cached, sapiClient }) {
|
|
2
|
-
return await cached(
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
return await cached(
|
|
4
|
+
mapSAPIFetchErrorToResponse(sapiClient.shopConfiguration.get),
|
|
5
|
+
{
|
|
6
|
+
cacheKeyPrefix: "get-shopConfigurations"
|
|
7
|
+
}
|
|
8
|
+
)();
|
|
5
9
|
};
|
|
6
10
|
export { getShopConfiguration };
|