@scayle/storefront-core 8.4.0 → 8.6.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 +40 -0
- package/dist/constants/index.d.ts +0 -1
- package/dist/constants/index.mjs +0 -1
- package/dist/helpers/filterHelper.d.ts +11 -11
- package/dist/helpers/sortingHelper.d.ts +22 -23
- package/dist/helpers/sortingHelper.mjs +11 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +6 -0
- package/dist/rpc/methods/basket/basket.d.ts +1 -1
- package/dist/rpc/methods/basket/basket.mjs +3 -3
- package/dist/rpc/methods/checkout/checkout.mjs +1 -1
- package/dist/rpc/methods/search.d.ts +22 -0
- package/dist/utils/basket.mjs +2 -2
- package/dist/utils/user.d.ts +3 -3
- package/dist/utils/user.mjs +2 -2
- package/package.json +9 -24
- package/dist/api/customer.cjs +0 -164
- package/dist/api/oauth.cjs +0 -238
- package/dist/cache/cache.cjs +0 -1
- package/dist/cache/cached.cjs +0 -90
- package/dist/cache/index.cjs +0 -27
- package/dist/cache/providers/unstorage.cjs +0 -55
- package/dist/constants/basket.cjs +0 -26
- package/dist/constants/basket.d.ts +0 -24
- package/dist/constants/basket.mjs +0 -20
- package/dist/constants/cache.cjs +0 -7
- package/dist/constants/hash.cjs +0 -11
- package/dist/constants/httpStatus.cjs +0 -634
- package/dist/constants/index.cjs +0 -93
- package/dist/constants/product.cjs +0 -10
- package/dist/constants/promotion.cjs +0 -12
- package/dist/constants/sorting.cjs +0 -22
- package/dist/constants/withParameters.cjs +0 -132
- package/dist/errors/errorResponse.cjs +0 -27
- package/dist/errors/index.cjs +0 -16
- package/dist/helpers/advancedAttributeHelpers.cjs +0 -30
- package/dist/helpers/arrayHelpers.cjs +0 -10
- package/dist/helpers/attributeHelpers.cjs +0 -24
- package/dist/helpers/basketHelpers.cjs +0 -12
- package/dist/helpers/categoryHelper.cjs +0 -61
- package/dist/helpers/filterHelper.cjs +0 -185
- package/dist/helpers/formHelpers.cjs +0 -114
- package/dist/helpers/imageHelpers.cjs +0 -20
- package/dist/helpers/index.cjs +0 -181
- package/dist/helpers/localization.cjs +0 -13
- package/dist/helpers/objectHelpers.cjs +0 -19
- package/dist/helpers/orderHelpers.cjs +0 -10
- package/dist/helpers/product.fixture.cjs +0 -766
- package/dist/helpers/productDisruptorHelper.cjs +0 -37
- package/dist/helpers/productHelpers.cjs +0 -156
- package/dist/helpers/sanitizationHelpers.cjs +0 -35
- package/dist/helpers/sortingHelper.cjs +0 -68
- package/dist/helpers/stringHelpers.cjs +0 -8
- package/dist/index.cjs +0 -100
- package/dist/rpc/methods/basket/basket.cjs +0 -270
- package/dist/rpc/methods/brands.cjs +0 -33
- package/dist/rpc/methods/categories.cjs +0 -129
- package/dist/rpc/methods/cbd.cjs +0 -38
- package/dist/rpc/methods/checkout/checkout.cjs +0 -48
- package/dist/rpc/methods/checkout/index.cjs +0 -49
- package/dist/rpc/methods/checkout/order.cjs +0 -42
- package/dist/rpc/methods/checkout/shopUser.cjs +0 -110
- package/dist/rpc/methods/checkout/shopUserAddresses.cjs +0 -12
- package/dist/rpc/methods/index.cjs +0 -225
- package/dist/rpc/methods/navigationTrees.cjs +0 -54
- package/dist/rpc/methods/oauth/idp.cjs +0 -59
- package/dist/rpc/methods/products.cjs +0 -309
- package/dist/rpc/methods/promotion.cjs +0 -51
- package/dist/rpc/methods/search.cjs +0 -40
- package/dist/rpc/methods/session.cjs +0 -257
- package/dist/rpc/methods/shopConfiguration.cjs +0 -15
- package/dist/rpc/methods/user.cjs +0 -103
- package/dist/rpc/methods/variants.cjs +0 -29
- package/dist/rpc/methods/wishlist.cjs +0 -104
- package/dist/server.cjs +0 -47
- package/dist/test/factories/index.cjs +0 -16
- package/dist/types/api/auth.cjs +0 -1
- package/dist/types/api/context.cjs +0 -15
- package/dist/types/api/rpc.cjs +0 -1
- package/dist/types/breadcrumb.cjs +0 -1
- package/dist/types/index.cjs +0 -267
- package/dist/types/promises.cjs +0 -1
- package/dist/types/sapi/basket.cjs +0 -1
- package/dist/types/sapi/brand.cjs +0 -1
- package/dist/types/sapi/campaign.cjs +0 -1
- package/dist/types/sapi/category.cjs +0 -1
- package/dist/types/sapi/filter.cjs +0 -1
- package/dist/types/sapi/navigation.cjs +0 -1
- package/dist/types/sapi/order.cjs +0 -1
- package/dist/types/sapi/product.cjs +0 -1
- package/dist/types/sapi/productFilter.cjs +0 -1
- package/dist/types/sapi/promotion.cjs +0 -1
- package/dist/types/sapi/redirects.cjs +0 -1
- package/dist/types/sapi/router.cjs +0 -1
- package/dist/types/sapi/search.cjs +0 -1
- package/dist/types/sapi/sorting.cjs +0 -1
- package/dist/types/sapi/variant.cjs +0 -1
- package/dist/types/sapi/wishlist.cjs +0 -1
- package/dist/types/user.cjs +0 -1
- package/dist/utils/basket.cjs +0 -14
- package/dist/utils/fetch.cjs +0 -19
- package/dist/utils/hash.cjs +0 -72
- package/dist/utils/index.cjs +0 -49
- package/dist/utils/keys.cjs +0 -67
- package/dist/utils/log.cjs +0 -93
- package/dist/utils/response.cjs +0 -13
- package/dist/utils/sapi.cjs +0 -26
- package/dist/utils/timeout.cjs +0 -18
- package/dist/utils/user.cjs +0 -90
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fetchNavigationTreeByName = exports.fetchNavigationTreeById = exports.fetchAllNavigationTrees = void 0;
|
|
7
|
-
var _errors = require("../../errors/index.cjs");
|
|
8
|
-
var _constants = require("../../constants/index.cjs");
|
|
9
|
-
const fetchAllNavigationTrees = exports.fetchAllNavigationTrees = async function fetchAllNavigationTrees2({
|
|
10
|
-
params
|
|
11
|
-
}, {
|
|
12
|
-
sapiClient: {
|
|
13
|
-
navigation
|
|
14
|
-
},
|
|
15
|
-
cached
|
|
16
|
-
}) {
|
|
17
|
-
return await cached(navigation.getAll, {
|
|
18
|
-
cacheKeyPrefix: "getAll-navigation-trees"
|
|
19
|
-
})(params);
|
|
20
|
-
};
|
|
21
|
-
const fetchNavigationTreeById = exports.fetchNavigationTreeById = async function fetchNavigationTreeById2({
|
|
22
|
-
treeId,
|
|
23
|
-
params
|
|
24
|
-
}, {
|
|
25
|
-
sapiClient: {
|
|
26
|
-
navigation
|
|
27
|
-
},
|
|
28
|
-
cached
|
|
29
|
-
}) {
|
|
30
|
-
return await cached(navigation.getById, {
|
|
31
|
-
cacheKeyPrefix: `getById-navigation-trees-${treeId}`
|
|
32
|
-
})(treeId, params);
|
|
33
|
-
};
|
|
34
|
-
const fetchNavigationTreeByName = exports.fetchNavigationTreeByName = async function fetchNavigationTreeByName2({
|
|
35
|
-
treeName,
|
|
36
|
-
params
|
|
37
|
-
}, {
|
|
38
|
-
sapiClient: {
|
|
39
|
-
navigation
|
|
40
|
-
},
|
|
41
|
-
cached
|
|
42
|
-
}) {
|
|
43
|
-
return await cached(async (name, params2) => {
|
|
44
|
-
const navigationTree = (await navigation.getAll(params2)).find(nav => nav.name === treeName);
|
|
45
|
-
if (!navigationTree) {
|
|
46
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.NOT_FOUND, `No navigation tree with name "${treeName}" found.`, _constants.HttpStatusMessage.NOT_FOUND, {
|
|
47
|
-
name
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
return navigationTree;
|
|
51
|
-
}, {
|
|
52
|
-
cacheKeyPrefix: `getByName-navigation-trees-${treeName}`
|
|
53
|
-
})(treeName, params);
|
|
54
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.handleIDPLoginCallback = exports.getExternalIdpRedirect = void 0;
|
|
7
|
-
var _jose = require("jose");
|
|
8
|
-
var _errors = require("../../../errors/index.cjs");
|
|
9
|
-
var _constants = require("../../../constants/index.cjs");
|
|
10
|
-
var _types = require("../../../types/index.cjs");
|
|
11
|
-
var _oauth = require("../../../api/oauth.cjs");
|
|
12
|
-
var _session = require("../session.cjs");
|
|
13
|
-
const getExternalIdpRedirect = exports.getExternalIdpRedirect = async function getExternalIdpRedirect2({
|
|
14
|
-
queryParams
|
|
15
|
-
}, context) {
|
|
16
|
-
if (!context.idp?.enabled) {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
if (context.idp.idpKeys.length === 0) {
|
|
20
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No IDP keys are configured");
|
|
21
|
-
}
|
|
22
|
-
if (!context.idp.idpRedirectURL) {
|
|
23
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No IDP redirect url is configured");
|
|
24
|
-
}
|
|
25
|
-
const OAuthClient = (0, _oauth.getOAuthClient)(context);
|
|
26
|
-
const redirectUrl = new URL(context.idp.idpRedirectURL);
|
|
27
|
-
if (queryParams) {
|
|
28
|
-
for (const [key, value] of Object.entries(queryParams)) {
|
|
29
|
-
redirectUrl.searchParams.set(key, value);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const secret = new TextEncoder().encode(context.checkout.secret);
|
|
33
|
-
const results = await Promise.all(context.idp.idpKeys.map(async idpKey => {
|
|
34
|
-
const jwtPayload = await new _jose.SignJWT({
|
|
35
|
-
idpKey,
|
|
36
|
-
callbackUrl: redirectUrl.toString(),
|
|
37
|
-
clientId: OAuthClient.clientId.toString()
|
|
38
|
-
}).setProtectedHeader({
|
|
39
|
-
alg: "HS256",
|
|
40
|
-
typ: "JWT"
|
|
41
|
-
}).setIssuedAt().setExpirationTime("2h").sign(secret);
|
|
42
|
-
const url = new URL(`${OAuthClient.baseURL}/auth/external/redirect`);
|
|
43
|
-
url.searchParams.set("shopId", `${context.shopId}`);
|
|
44
|
-
url.searchParams.set("jwt", jwtPayload);
|
|
45
|
-
return [idpKey, url.toString()];
|
|
46
|
-
}));
|
|
47
|
-
return Object.fromEntries(results);
|
|
48
|
-
};
|
|
49
|
-
const handleIDPLoginCallback = exports.handleIDPLoginCallback = async function handleIDPLoginCallback2(payload, context) {
|
|
50
|
-
if (!(0, _types.hasSession)(context)) {
|
|
51
|
-
return new _errors.ErrorResponse(_constants.HttpStatusCode.BAD_REQUEST, _constants.HttpStatusMessage.BAD_REQUEST, "No Session found");
|
|
52
|
-
}
|
|
53
|
-
const OAuthClient = (0, _oauth.getOAuthClient)(context);
|
|
54
|
-
const tokens = await OAuthClient.generateToken(payload.code);
|
|
55
|
-
await (0, _session.postLogin)(context, tokens);
|
|
56
|
-
return {
|
|
57
|
-
message: "success"
|
|
58
|
-
};
|
|
59
|
-
};
|
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getProductsCount = exports.getProductsByReferenceKeys = exports.getProductsByIds = exports.getProductsByCategory = exports.getProductById = exports.getFilters = exports.fetchAllFiltersForCategory = void 0;
|
|
7
|
-
exports.resolveCategoryIdFromParams = resolveCategoryIdFromParams;
|
|
8
|
-
var _helpers = require("../../helpers/index.cjs");
|
|
9
|
-
var _constants = require("../../constants/index.cjs");
|
|
10
|
-
var _cache = require("../../cache/index.cjs");
|
|
11
|
-
var _response = require("../../utils/response.cjs");
|
|
12
|
-
var _sapi = require("../../utils/sapi.cjs");
|
|
13
|
-
var _errors = require("../../errors/index.cjs");
|
|
14
|
-
const MAX_PER_PAGE = 100;
|
|
15
|
-
const sanitizeAttributesForSAPI = ({
|
|
16
|
-
attributes,
|
|
17
|
-
filterKeys,
|
|
18
|
-
includedFilters = []
|
|
19
|
-
}) => {
|
|
20
|
-
return attributes.filter(({
|
|
21
|
-
key
|
|
22
|
-
}) => key && filterKeys.includes(key.toLowerCase()) && !includedFilters?.includes(key.toLowerCase()));
|
|
23
|
-
};
|
|
24
|
-
const mapFiltersToSlugs = (filters = []) => filters.map(({
|
|
25
|
-
slug
|
|
26
|
-
}) => slug.toLowerCase());
|
|
27
|
-
async function resolveCategoryIdFromParams(context, params) {
|
|
28
|
-
let category;
|
|
29
|
-
let categoryId;
|
|
30
|
-
if ("categoryId" in params) {
|
|
31
|
-
categoryId = params.categoryId;
|
|
32
|
-
} else if (params.category && params.category !== "/") {
|
|
33
|
-
category = params.category;
|
|
34
|
-
const result = await context.cached(context.sapiClient.categories.getByPath, {
|
|
35
|
-
cacheKeyPrefix: `getByPath-categories-${category}`
|
|
36
|
-
})((0, _helpers.splitAndRemoveEmpty)(category));
|
|
37
|
-
categoryId = result.id;
|
|
38
|
-
} else {
|
|
39
|
-
category = "/";
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
category,
|
|
43
|
-
categoryId
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
const getProductById = exports.getProductById = async function getProductById2(options, {
|
|
47
|
-
sapiClient,
|
|
48
|
-
cached,
|
|
49
|
-
campaignKey,
|
|
50
|
-
withParams
|
|
51
|
-
}) {
|
|
52
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.products.getById), {
|
|
53
|
-
cacheKeyPrefix: `getById-product-${options.id}`,
|
|
54
|
-
ttl: 5 * _cache.MINUTE
|
|
55
|
-
})(options.id, {
|
|
56
|
-
with: options.with ?? withParams?.product ?? _constants.MIN_WITH_PARAMS_PRODUCT,
|
|
57
|
-
campaignKey,
|
|
58
|
-
pricePromotionKey: options.pricePromotionKey,
|
|
59
|
-
includeSellableForFree: options.includeSellableForFree
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
const getProductsByIds = exports.getProductsByIds = async function getProductsByIds2(options, {
|
|
63
|
-
sapiClient,
|
|
64
|
-
cached,
|
|
65
|
-
campaignKey,
|
|
66
|
-
withParams
|
|
67
|
-
}) {
|
|
68
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.products.getByIds), {
|
|
69
|
-
cacheKeyPrefix: "getByIds-products",
|
|
70
|
-
ttl: 5 * _cache.MINUTE
|
|
71
|
-
})(options.ids, {
|
|
72
|
-
with: options.with ?? withParams?.product ?? _constants.MIN_WITH_PARAMS_PRODUCT,
|
|
73
|
-
campaignKey,
|
|
74
|
-
pricePromotionKey: options.pricePromotionKey
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
const getProductsByReferenceKeys = exports.getProductsByReferenceKeys = async function getProductsByReferenceKeys2(options, {
|
|
78
|
-
sapiClient,
|
|
79
|
-
cached,
|
|
80
|
-
campaignKey,
|
|
81
|
-
withParams
|
|
82
|
-
}) {
|
|
83
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.products.getByReferenceKeys), {
|
|
84
|
-
cacheKeyPrefix: "getByReferenceKeys-products",
|
|
85
|
-
ttl: 5 * _cache.MINUTE
|
|
86
|
-
})(options.referenceKeys, {
|
|
87
|
-
with: options.with ?? withParams?.product ?? _constants.MIN_WITH_PARAMS_PRODUCT,
|
|
88
|
-
campaignKey,
|
|
89
|
-
pricePromotionKey: options.pricePromotionKey
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
const getProductsCount = exports.getProductsCount = async function getProductsCount2(params, context) {
|
|
93
|
-
const {
|
|
94
|
-
includedFilters,
|
|
95
|
-
where = void 0,
|
|
96
|
-
includeSoldOut = false,
|
|
97
|
-
includeSellableForFree = false,
|
|
98
|
-
orFiltersOperator = void 0
|
|
99
|
-
} = params;
|
|
100
|
-
const {
|
|
101
|
-
cached,
|
|
102
|
-
sapiClient,
|
|
103
|
-
campaignKey
|
|
104
|
-
} = context;
|
|
105
|
-
const {
|
|
106
|
-
categoryId
|
|
107
|
-
} = await resolveCategoryIdFromParams(context, params);
|
|
108
|
-
const response = await getSanitizedAttributes(context, categoryId, where?.attributes || [], includedFilters);
|
|
109
|
-
if (response instanceof _errors.ErrorResponse) {
|
|
110
|
-
return response;
|
|
111
|
-
}
|
|
112
|
-
const sanitizedAttributes = response;
|
|
113
|
-
const productCount = await cached(sapiClient.products.query, {
|
|
114
|
-
ttl: 15 * _cache.MINUTE,
|
|
115
|
-
cacheKeyPrefix: "products-query"
|
|
116
|
-
})({
|
|
117
|
-
where: {
|
|
118
|
-
categoryId,
|
|
119
|
-
minPrice: where?.minPrice,
|
|
120
|
-
maxPrice: where?.maxPrice,
|
|
121
|
-
term: where?.term,
|
|
122
|
-
attributes: [...sanitizedAttributes, ...(where?.whitelistAttributes || [])],
|
|
123
|
-
disableFuzziness: where?.disableFuzziness
|
|
124
|
-
},
|
|
125
|
-
pagination: {
|
|
126
|
-
perPage: 1
|
|
127
|
-
},
|
|
128
|
-
campaignKey,
|
|
129
|
-
includeSellableForFree,
|
|
130
|
-
includeSoldOut,
|
|
131
|
-
orFiltersOperator
|
|
132
|
-
});
|
|
133
|
-
return {
|
|
134
|
-
count: productCount?.pagination.total
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
const fetchAllFiltersForCategory = exports.fetchAllFiltersForCategory = async function fetchAllFiltersForCategory2({
|
|
138
|
-
includedFilters = [],
|
|
139
|
-
category
|
|
140
|
-
}, {
|
|
141
|
-
cached,
|
|
142
|
-
sapiClient,
|
|
143
|
-
campaignKey
|
|
144
|
-
}) {
|
|
145
|
-
const fetchAndMapFiltersToSlugs = async () => {
|
|
146
|
-
const filtersFromSAPI = await cached(sapiClient.filters.get)({
|
|
147
|
-
where: {
|
|
148
|
-
categoryId: category.id
|
|
149
|
-
},
|
|
150
|
-
campaignKey,
|
|
151
|
-
including: includedFilters
|
|
152
|
-
});
|
|
153
|
-
return mapFiltersToSlugs(filtersFromSAPI);
|
|
154
|
-
};
|
|
155
|
-
return await cached(fetchAndMapFiltersToSlugs, {
|
|
156
|
-
ttl: 4 * 60 * 60,
|
|
157
|
-
// cached for 4 hours
|
|
158
|
-
cacheKey: `filters-for-category-${category.id}`
|
|
159
|
-
})();
|
|
160
|
-
};
|
|
161
|
-
async function getSanitizedAttributes(context, categoryId, attributes, includedFilters) {
|
|
162
|
-
const response = await fetchAllFiltersForCategory({
|
|
163
|
-
category: {
|
|
164
|
-
id: categoryId
|
|
165
|
-
},
|
|
166
|
-
includedFilters
|
|
167
|
-
}, context);
|
|
168
|
-
if (response instanceof _errors.ErrorResponse) {
|
|
169
|
-
return response;
|
|
170
|
-
}
|
|
171
|
-
const allFiltersForCategory = await (0, _response.unwrap)(response);
|
|
172
|
-
return sanitizeAttributesForSAPI({
|
|
173
|
-
attributes: attributes || [],
|
|
174
|
-
filterKeys: allFiltersForCategory,
|
|
175
|
-
includedFilters
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
const getFilters = exports.getFilters = async function getFilters2(params, context) {
|
|
179
|
-
const {
|
|
180
|
-
includedFilters,
|
|
181
|
-
where = void 0,
|
|
182
|
-
includeSoldOut = false,
|
|
183
|
-
includeSellableForFree = false,
|
|
184
|
-
orFiltersOperator
|
|
185
|
-
} = params;
|
|
186
|
-
const {
|
|
187
|
-
cached,
|
|
188
|
-
sapiClient,
|
|
189
|
-
campaignKey
|
|
190
|
-
} = context;
|
|
191
|
-
const {
|
|
192
|
-
category,
|
|
193
|
-
categoryId
|
|
194
|
-
} = await resolveCategoryIdFromParams(context, params);
|
|
195
|
-
const response = await getSanitizedAttributes(context, categoryId, where?.attributes || [], includedFilters);
|
|
196
|
-
if (response instanceof _errors.ErrorResponse) {
|
|
197
|
-
return response;
|
|
198
|
-
}
|
|
199
|
-
const sanitizedAttributes = response;
|
|
200
|
-
const [filters, productCount] = await Promise.all([cached(sapiClient.filters.get, {
|
|
201
|
-
cacheKeyPrefix: `get-filters-${categoryId}`
|
|
202
|
-
})({
|
|
203
|
-
where: {
|
|
204
|
-
categoryId,
|
|
205
|
-
minPrice: where?.minPrice,
|
|
206
|
-
maxPrice: where?.maxPrice,
|
|
207
|
-
term: where?.term,
|
|
208
|
-
attributes: [...sanitizedAttributes, ...(where?.whitelistAttributes || [])]
|
|
209
|
-
},
|
|
210
|
-
includeSoldOut,
|
|
211
|
-
includeSellableForFree,
|
|
212
|
-
campaignKey,
|
|
213
|
-
including: includedFilters,
|
|
214
|
-
orFiltersOperator
|
|
215
|
-
}), cached(sapiClient.products.query, {
|
|
216
|
-
ttl: 15 * _cache.MINUTE,
|
|
217
|
-
cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : categoryId}`
|
|
218
|
-
})({
|
|
219
|
-
where: {
|
|
220
|
-
categoryId,
|
|
221
|
-
minPrice: where?.minPrice,
|
|
222
|
-
maxPrice: where?.maxPrice,
|
|
223
|
-
term: where?.term,
|
|
224
|
-
attributes: [...sanitizedAttributes, ...(where?.whitelistAttributes || [])],
|
|
225
|
-
disableFuzziness: where?.disableFuzziness
|
|
226
|
-
},
|
|
227
|
-
pagination: {
|
|
228
|
-
perPage: 1
|
|
229
|
-
},
|
|
230
|
-
campaignKey,
|
|
231
|
-
includeSellableForFree,
|
|
232
|
-
includeSoldOut,
|
|
233
|
-
orFiltersOperator
|
|
234
|
-
})]);
|
|
235
|
-
return {
|
|
236
|
-
filters,
|
|
237
|
-
unfilteredCount: productCount?.pagination.total
|
|
238
|
-
};
|
|
239
|
-
};
|
|
240
|
-
const getProductsByCategory = exports.getProductsByCategory = async function getProductsByCategory2(params, context) {
|
|
241
|
-
const {
|
|
242
|
-
includedFilters,
|
|
243
|
-
cache,
|
|
244
|
-
with: _with,
|
|
245
|
-
perPage = 20,
|
|
246
|
-
page = 1,
|
|
247
|
-
where = void 0,
|
|
248
|
-
sort = void 0,
|
|
249
|
-
pricePromotionKey = "",
|
|
250
|
-
includeSellableForFree = void 0,
|
|
251
|
-
includeSoldOut = void 0,
|
|
252
|
-
orFiltersOperator = void 0,
|
|
253
|
-
trackSearchAnalyticsEvent = void 0
|
|
254
|
-
} = params;
|
|
255
|
-
const {
|
|
256
|
-
cached,
|
|
257
|
-
sapiClient,
|
|
258
|
-
campaignKey
|
|
259
|
-
} = context;
|
|
260
|
-
const {
|
|
261
|
-
category,
|
|
262
|
-
categoryId
|
|
263
|
-
} = await resolveCategoryIdFromParams(context, params);
|
|
264
|
-
const response = await getSanitizedAttributes(context, categoryId, where?.attributes || [], includedFilters);
|
|
265
|
-
if (response instanceof _errors.ErrorResponse) {
|
|
266
|
-
return response;
|
|
267
|
-
}
|
|
268
|
-
const sanitizedAttributes = response;
|
|
269
|
-
const {
|
|
270
|
-
entities: products,
|
|
271
|
-
pagination
|
|
272
|
-
} = await cached(sapiClient.products.query, {
|
|
273
|
-
...cache,
|
|
274
|
-
ttl: cache?.ttl ?? 15 * _cache.MINUTE,
|
|
275
|
-
cacheKeyPrefix: cache?.cacheKeyPrefix || `products-query-category-${category === "/" ? "root" : categoryId}`
|
|
276
|
-
})({
|
|
277
|
-
where: {
|
|
278
|
-
categoryId,
|
|
279
|
-
minPrice: where?.minPrice,
|
|
280
|
-
maxPrice: where?.maxPrice,
|
|
281
|
-
term: where?.term,
|
|
282
|
-
attributes: [...sanitizedAttributes, ...(where?.whitelistAttributes || [])],
|
|
283
|
-
disableFuzziness: where?.disableFuzziness
|
|
284
|
-
},
|
|
285
|
-
pagination: {
|
|
286
|
-
perPage: Math.min(perPage, MAX_PER_PAGE),
|
|
287
|
-
page
|
|
288
|
-
},
|
|
289
|
-
campaignKey,
|
|
290
|
-
includeSellableForFree,
|
|
291
|
-
includeSoldOut,
|
|
292
|
-
orFiltersOperator,
|
|
293
|
-
pricePromotionKey,
|
|
294
|
-
with: _with ?? context.withParams?.product ?? _constants.MIN_WITH_PARAMS_PRODUCT,
|
|
295
|
-
sort,
|
|
296
|
-
// NOTE: We only pass the parameter value through and don't implement a custom check.
|
|
297
|
-
// The consuming project should not include trackSearchAnalyticsEvent parameter when paginating through
|
|
298
|
-
// results with the page parameter, as this logs the search term on every page request.
|
|
299
|
-
// Instead, log the term only once, when the search is first performed.
|
|
300
|
-
// https://scayle.dev/en/developer-guide/products/search#scayle-search-analytics
|
|
301
|
-
trackSearchAnalyticsEvent
|
|
302
|
-
});
|
|
303
|
-
return {
|
|
304
|
-
products,
|
|
305
|
-
pagination: {
|
|
306
|
-
...pagination
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getPromotionsByIds = exports.getPromotions = exports.getCurrentPromotions = void 0;
|
|
7
|
-
var _constants = require("../../constants/index.cjs");
|
|
8
|
-
var _sapi = require("../../utils/sapi.cjs");
|
|
9
|
-
const setPaginationDefault = pagination => {
|
|
10
|
-
return {
|
|
11
|
-
page: pagination?.page || _constants.PROMOTION_PAGE_DEFAULT,
|
|
12
|
-
perPage: pagination?.perPage || _constants.PROMOTION_PER_PAGE_DEFAULT
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
const getPromotions = exports.getPromotions = async function getPromotions2(params = {}, context) {
|
|
16
|
-
const {
|
|
17
|
-
sapiClient,
|
|
18
|
-
cached
|
|
19
|
-
} = context;
|
|
20
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.promotions.get), {
|
|
21
|
-
cacheKeyPrefix: "getPromotions"
|
|
22
|
-
})({
|
|
23
|
-
...params,
|
|
24
|
-
pagination: setPaginationDefault(params.pagination)
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
const getCurrentPromotions = exports.getCurrentPromotions = async function getCurrentPromotions2(params = {}, context) {
|
|
28
|
-
const {
|
|
29
|
-
sapiClient,
|
|
30
|
-
cached
|
|
31
|
-
} = context;
|
|
32
|
-
const now = /* @__PURE__ */new Date();
|
|
33
|
-
now.setSeconds(0, 0);
|
|
34
|
-
const activeAt = now.toISOString();
|
|
35
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.promotions.get), {
|
|
36
|
-
cacheKeyPrefix: "getPromotions"
|
|
37
|
-
})({
|
|
38
|
-
...params,
|
|
39
|
-
activeAt,
|
|
40
|
-
pagination: setPaginationDefault(params.pagination)
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
const getPromotionsByIds = exports.getPromotionsByIds = async function getPromotionsByIds2(ids, context) {
|
|
44
|
-
const {
|
|
45
|
-
sapiClient,
|
|
46
|
-
cached
|
|
47
|
-
} = context;
|
|
48
|
-
return await cached((0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.promotions.getByIds), {
|
|
49
|
-
cacheKeyPrefix: "getByIds-promotions"
|
|
50
|
-
})(ids);
|
|
51
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.resolveSearch = exports.getSearchSuggestions = void 0;
|
|
7
|
-
var _sapi = require("../../utils/sapi.cjs");
|
|
8
|
-
const getSearchSuggestions = exports.getSearchSuggestions = async function getSearchSuggestions2({
|
|
9
|
-
term,
|
|
10
|
-
with: _with,
|
|
11
|
-
categoryId
|
|
12
|
-
}, {
|
|
13
|
-
sapiClient,
|
|
14
|
-
withParams
|
|
15
|
-
}) {
|
|
16
|
-
return await (0, _sapi.mapSAPIFetchErrorToResponse)(sapiClient.searchv2.suggestions)(term, {
|
|
17
|
-
categoryId,
|
|
18
|
-
with: _with ?? withParams?.searchV2
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
const resolveSearch = exports.resolveSearch = async function resolveSearch2({
|
|
22
|
-
term,
|
|
23
|
-
with: _with,
|
|
24
|
-
categoryId
|
|
25
|
-
}, {
|
|
26
|
-
cached,
|
|
27
|
-
sapiClient,
|
|
28
|
-
withParams
|
|
29
|
-
}) {
|
|
30
|
-
const resolvedEntity = await cached(sapiClient.searchv2.resolve, {
|
|
31
|
-
cacheKeyPrefix: `resolve-${term}`
|
|
32
|
-
})(term, {
|
|
33
|
-
categoryId,
|
|
34
|
-
with: _with ?? withParams?.searchV2
|
|
35
|
-
});
|
|
36
|
-
if (!resolvedEntity) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
return resolvedEntity;
|
|
40
|
-
};
|