@scayle/storefront-core 8.0.0 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- 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/checkout/checkout.cjs +1 -1
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- 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 +2 -1
- package/dist/rpc/methods/search.d.ts +1 -1
- package/dist/rpc/methods/search.mjs +2 -1
- 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/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/types/sapi/product.d.ts +1 -1
- 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 +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @scayle/storefront-core
|
|
2
2
|
|
|
3
|
+
## 8.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Make the `sort` parameter optional for the `FetchProductsByCategoryParams`
|
|
8
|
+
|
|
9
|
+
## 8.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- **RPC Methods:** Propogate SAPI response codes through RPC methods. This addresses an issue introduced in Storefront Core v8 where specific status codes were incorrectly reported as generic 500 errors. The following RPC methods are impacted:
|
|
14
|
+
|
|
15
|
+
- `getBrands`
|
|
16
|
+
- `getBrandById`
|
|
17
|
+
- `getCategoryByPath`
|
|
18
|
+
- `getCategoryById`
|
|
19
|
+
- `getProductById`
|
|
20
|
+
- `getProductsByIds`
|
|
21
|
+
- `getProductsByReferenceKeys`
|
|
22
|
+
- `getPromotions`
|
|
23
|
+
- `getCurrentPromotions`
|
|
24
|
+
- `getPromotionsByIds`
|
|
25
|
+
- `getSearchSuggestions`
|
|
26
|
+
- `getShopConfiguration`
|
|
27
|
+
- `getVariantById`
|
|
28
|
+
- `getWishlist`
|
|
29
|
+
- `removeItemFromWishlist`
|
|
30
|
+
|
|
3
31
|
## 8.0.0
|
|
4
32
|
|
|
5
33
|
### Major Changes
|
|
@@ -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",
|
|
@@ -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"}@${"8.
|
|
40
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.1.1"}`).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"}@${"8.
|
|
38
|
+
}).setIssuedAt(now).setNotBefore(now).setExpirationTime("1h").setIssuer(`${"@scayle/storefront-core"}@${"8.1.1"}`).setProtectedHeader({ alg: "HS256", typ: "JWT" }).sign(secret);
|
|
39
39
|
return {
|
|
40
40
|
accessToken: refreshedAccessToken,
|
|
41
41
|
checkoutJwt
|
|
@@ -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
|
};
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.resolveSearch = exports.getSearchSuggestions = void 0;
|
|
7
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
7
8
|
const getSearchSuggestions = exports.getSearchSuggestions = async function getSearchSuggestions2({
|
|
8
9
|
term,
|
|
9
10
|
with: _with,
|
|
@@ -12,7 +13,7 @@ const getSearchSuggestions = exports.getSearchSuggestions = async function getSe
|
|
|
12
13
|
sapiClient,
|
|
13
14
|
withParams
|
|
14
15
|
}) {
|
|
15
|
-
return await sapiClient.searchv2.suggestions(term, {
|
|
16
|
+
return await (0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.searchv2.suggestions)(term, {
|
|
16
17
|
categoryId,
|
|
17
18
|
with: _with ?? withParams?.searchV2
|
|
18
19
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SearchV2ResolveEndpointParameters, SearchV2SuggestionsEndpointParameters, SearchV2SuggestionsEndpointResponseData } from '../../types/sapi/search';
|
|
2
|
-
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>;
|
|
3
3
|
export declare const resolveSearch: ({ term, with: _with, categoryId }: SearchV2ResolveEndpointParameters, { cached, sapiClient, withParams }: import("../../types").RpcContext) => Promise<import("@scayle/storefront-api").SearchEntity | null>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
1
2
|
export const getSearchSuggestions = async function getSearchSuggestions2({ term, with: _with, categoryId }, { sapiClient, withParams }) {
|
|
2
|
-
return await sapiClient.searchv2.suggestions(
|
|
3
|
+
return await mapSAPIFetchErrorToResponse(sapiClient.searchv2.suggestions)(
|
|
3
4
|
term,
|
|
4
5
|
{
|
|
5
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 };
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getVariantById = void 0;
|
|
7
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
7
8
|
const defaultWith = {
|
|
8
9
|
attributes: "all"
|
|
9
10
|
};
|
|
@@ -18,7 +19,7 @@ const getVariantById = exports.getVariantById = async function getVariantById2({
|
|
|
18
19
|
withParams
|
|
19
20
|
}) {
|
|
20
21
|
const resolvedWith = include ?? withParams?.variant ?? defaultWith;
|
|
21
|
-
return await cached(sapiClient.variants.getByIds, {
|
|
22
|
+
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.variants.getByIds), {
|
|
22
23
|
cacheKeyPrefix: "getByIds-variants"
|
|
23
24
|
})(ids, include ? {
|
|
24
25
|
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, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<VariantDetail[]>;
|
|
8
|
+
export declare const getVariantById: ({ ids, include, pricePromotionKey }: FetchVariantsParams, { sapiClient, cached, campaignKey, withParams }: RpcContext) => Promise<Response | VariantDetail[]>;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
1
2
|
const defaultWith = {
|
|
2
3
|
attributes: "all"
|
|
3
4
|
};
|
|
4
5
|
export const getVariantById = async function getVariantById2({ ids, include = defaultWith, pricePromotionKey = "default" }, { sapiClient, cached, campaignKey, withParams }) {
|
|
5
6
|
const resolvedWith = include ?? withParams?.variant ?? defaultWith;
|
|
6
|
-
return await cached(
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
return await cached(
|
|
8
|
+
mapSAPIFetchErrorToResponse(sapiClient.variants.getByIds),
|
|
9
|
+
{
|
|
10
|
+
cacheKeyPrefix: "getByIds-variants"
|
|
11
|
+
}
|
|
12
|
+
)(
|
|
9
13
|
ids,
|
|
10
14
|
include ? { with: resolvedWith, campaignKey, pricePromotionKey } : void 0
|
|
11
15
|
);
|
|
@@ -8,6 +8,7 @@ var _types = require("../../types/index.cjs");
|
|
|
8
8
|
var _constants = require("../../constants/index.cjs");
|
|
9
9
|
var _response = require("../../utils/response.cjs");
|
|
10
10
|
var _errors = require("../../errors/index.cjs");
|
|
11
|
+
var _sapi = require("../../utils/sapi.cjs");
|
|
11
12
|
function getWithParams(params, context) {
|
|
12
13
|
return params.with ?? context.withParams?.wishlist ?? _constants.MIN_WITH_PARAMS_WISHLIST;
|
|
13
14
|
}
|
|
@@ -23,7 +24,7 @@ const getWishlist = exports.getWishlist = async function getWishlist2(options, c
|
|
|
23
24
|
const resolvedWith = getWithParams({
|
|
24
25
|
with: options
|
|
25
26
|
}, context);
|
|
26
|
-
return await sapiClient.wishlist.get(wishlistKey, {
|
|
27
|
+
return await (0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.wishlist.get)(wishlistKey, {
|
|
27
28
|
with: resolvedWith,
|
|
28
29
|
campaignKey,
|
|
29
30
|
pricePromotionKey: resolvedWith?.pricePromotionKey ?? ""
|
|
@@ -83,7 +84,7 @@ const removeItemFromWishlist = exports.removeItemFromWishlist = async function r
|
|
|
83
84
|
wishlistKey
|
|
84
85
|
} = context;
|
|
85
86
|
const resolvedWith = getWithParams(options, context);
|
|
86
|
-
return await sapiClient.wishlist.deleteItem(wishlistKey, options.itemKey, {
|
|
87
|
+
return await (0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.wishlist.deleteItem)(wishlistKey, options.itemKey, {
|
|
87
88
|
with: resolvedWith,
|
|
88
89
|
campaignKey
|
|
89
90
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Wishlist } from '@scayle/storefront-api';
|
|
2
2
|
import type { RpcContext, WishlistWithOptions } from '../../types';
|
|
3
|
-
|
|
4
|
-
export declare const getWishlist: (options: WishlistWithOptions | undefined, context: RpcContext) => Promise<ErrorResponse | Wishlist>;
|
|
3
|
+
export declare const getWishlist: (options: WishlistWithOptions | undefined, context: RpcContext) => Promise<Response | Wishlist>;
|
|
5
4
|
export declare const addItemToWishlist: (options: {
|
|
6
5
|
variantId?: number;
|
|
7
6
|
productId?: number;
|
|
@@ -10,5 +9,5 @@ export declare const addItemToWishlist: (options: {
|
|
|
10
9
|
export declare const removeItemFromWishlist: (options: {
|
|
11
10
|
itemKey: string;
|
|
12
11
|
with?: WishlistWithOptions;
|
|
13
|
-
}, context: RpcContext) => Promise<
|
|
14
|
-
export declare const clearWishlist: (context: RpcContext) => Promise<
|
|
12
|
+
}, context: RpcContext) => Promise<Response | Wishlist>;
|
|
13
|
+
export declare const clearWishlist: (context: RpcContext) => Promise<Response | Wishlist>;
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "../../constants/index.mjs";
|
|
7
7
|
import { unwrap } from "../../utils/response.mjs";
|
|
8
8
|
import { ErrorResponse } from "../../errors/index.mjs";
|
|
9
|
+
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
9
10
|
function getWithParams(params, context) {
|
|
10
11
|
return params.with ?? context.withParams?.wishlist ?? MIN_WITH_PARAMS_WISHLIST;
|
|
11
12
|
}
|
|
@@ -19,11 +20,14 @@ export const getWishlist = async function getWishlist2(options, context) {
|
|
|
19
20
|
}
|
|
20
21
|
const { sapiClient, campaignKey, wishlistKey } = context;
|
|
21
22
|
const resolvedWith = getWithParams({ with: options }, context);
|
|
22
|
-
return await sapiClient.wishlist.get(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
return await mapSAPIFetchErrorToResponse(sapiClient.wishlist.get)(
|
|
24
|
+
wishlistKey,
|
|
25
|
+
{
|
|
26
|
+
with: resolvedWith,
|
|
27
|
+
campaignKey,
|
|
28
|
+
pricePromotionKey: resolvedWith?.pricePromotionKey ?? ""
|
|
29
|
+
}
|
|
30
|
+
);
|
|
27
31
|
};
|
|
28
32
|
export const addItemToWishlist = async function addItemToWishlist2(options, context) {
|
|
29
33
|
if (!hasSession(context)) {
|
|
@@ -71,10 +75,14 @@ export const removeItemFromWishlist = async function removeItemFromWishlist2(opt
|
|
|
71
75
|
}
|
|
72
76
|
const { sapiClient, campaignKey, wishlistKey } = context;
|
|
73
77
|
const resolvedWith = getWithParams(options, context);
|
|
74
|
-
return await sapiClient.wishlist.deleteItem(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
return await mapSAPIFetchErrorToResponse(sapiClient.wishlist.deleteItem)(
|
|
79
|
+
wishlistKey,
|
|
80
|
+
options.itemKey,
|
|
81
|
+
{
|
|
82
|
+
with: resolvedWith,
|
|
83
|
+
campaignKey
|
|
84
|
+
}
|
|
85
|
+
);
|
|
78
86
|
};
|
|
79
87
|
export const clearWishlist = async function clearWishlist2(context) {
|
|
80
88
|
const wishlistResponse = await getWishlist({}, context);
|
|
@@ -57,7 +57,7 @@ export type FetchProductsByCategoryParams = {
|
|
|
57
57
|
disableFuzziness?: ProductSearchQuery['disableFuzziness'];
|
|
58
58
|
whitelistAttributes?: ProductSearchQuery['attributes'];
|
|
59
59
|
};
|
|
60
|
-
sort
|
|
60
|
+
sort?: FilterParams['sort'];
|
|
61
61
|
pricePromotionKey?: string;
|
|
62
62
|
includeSellableForFree?: boolean;
|
|
63
63
|
includeSoldOut?: boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mapSAPIFetchErrorToResponse = mapSAPIFetchErrorToResponse;
|
|
7
|
+
var _storefrontApi = require("@scayle/storefront-api");
|
|
8
|
+
function mapSAPIFetchErrorToResponse(func) {
|
|
9
|
+
return async (...args) => {
|
|
10
|
+
try {
|
|
11
|
+
return await func(...args);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
if (e instanceof _storefrontApi.FetchError) {
|
|
14
|
+
return e.response;
|
|
15
|
+
}
|
|
16
|
+
throw e;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap a SAPI API function, catching any SAPI FetchErrors thrown
|
|
3
|
+
* and translating them to a Response return
|
|
4
|
+
*/
|
|
5
|
+
export declare function mapSAPIFetchErrorToResponse<T extends (...args: any) => any>(func: T): (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>> | Response>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FetchError } from "@scayle/storefront-api";
|
|
2
|
+
export function mapSAPIFetchErrorToResponse(func) {
|
|
3
|
+
return async (...args) => {
|
|
4
|
+
try {
|
|
5
|
+
return await func(...args);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
if (e instanceof FetchError) {
|
|
8
|
+
return e.response;
|
|
9
|
+
}
|
|
10
|
+
throw e;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|