@scayle/storefront-core 8.61.0 → 8.61.2
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-V7.md +1 -11
- package/CHANGELOG.md +100 -103
- package/dist/api/customer.mjs +1 -3
- package/dist/api/oauth.mjs +9 -6
- package/dist/cache/providers/unstorage.mjs +1 -3
- package/dist/constants/withParameters.mjs +2 -16
- package/dist/helpers/attributeHelpers.mjs +3 -1
- package/dist/helpers/filterHelper.mjs +11 -8
- package/dist/helpers/productHelpers.mjs +1 -3
- package/dist/helpers/sanitizationHelpers.mjs +1 -4
- package/dist/helpers/sortingHelper.mjs +1 -3
- package/dist/rpc/methods/basket/basket.d.ts +2 -2
- package/dist/rpc/methods/basket/basket.mjs +334 -321
- package/dist/rpc/methods/brands.mjs +26 -20
- package/dist/rpc/methods/campaign.mjs +32 -23
- package/dist/rpc/methods/categories.mjs +156 -135
- package/dist/rpc/methods/cbd.mjs +52 -49
- package/dist/rpc/methods/checkout/checkout.mjs +42 -39
- package/dist/rpc/methods/checkout/order.mjs +46 -40
- package/dist/rpc/methods/checkout/shopUser.mjs +112 -106
- package/dist/rpc/methods/navigationTrees.mjs +50 -32
- package/dist/rpc/methods/oauth/idp.mjs +64 -55
- package/dist/rpc/methods/products.mjs +224 -212
- package/dist/rpc/methods/promotion.mjs +46 -31
- package/dist/rpc/methods/search.mjs +26 -20
- package/dist/rpc/methods/session.mjs +289 -260
- package/dist/rpc/methods/shopConfiguration.mjs +12 -9
- package/dist/rpc/methods/user.mjs +87 -78
- package/dist/rpc/methods/variants.mjs +17 -14
- package/dist/rpc/methods/wishlist.mjs +71 -62
- package/dist/utils/hash.mjs +2 -7
- package/dist/utils/sapi.mjs +10 -7
- package/package.json +4 -4
|
@@ -33,52 +33,61 @@ export async function resolveCategoryIdFromParams(context, params) {
|
|
|
33
33
|
}
|
|
34
34
|
return { category, categoryId };
|
|
35
35
|
}
|
|
36
|
-
export const getProductById = defineRpcHandler(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
36
|
+
export const getProductById = defineRpcHandler(
|
|
37
|
+
async (options, context) => {
|
|
38
|
+
const { sapiClient, cached, withParams } = context;
|
|
39
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
40
|
+
return await cached(
|
|
41
|
+
mapSAPIFetchErrorToResponse(sapiClient.products.getById),
|
|
42
|
+
{
|
|
43
|
+
cacheKeyPrefix: `getById-product-${options.id}`,
|
|
44
|
+
ttl: 5 * MINUTE
|
|
45
|
+
}
|
|
46
|
+
)(options.id, {
|
|
47
|
+
with: options.with ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
48
|
+
campaignKey,
|
|
49
|
+
pricePromotionKey: options.pricePromotionKey,
|
|
50
|
+
includeSellableForFree: options.includeSellableForFree
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
{ method: "GET" }
|
|
54
|
+
);
|
|
55
|
+
export const getProductsByIds = defineRpcHandler(
|
|
56
|
+
async (options, context) => {
|
|
57
|
+
const { sapiClient, cached, withParams } = context;
|
|
58
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
59
|
+
return await cached(
|
|
60
|
+
mapSAPIFetchErrorToResponse(sapiClient.products.getByIds),
|
|
61
|
+
{
|
|
62
|
+
cacheKeyPrefix: "getByIds-products",
|
|
63
|
+
ttl: 5 * MINUTE
|
|
64
|
+
}
|
|
65
|
+
)(options.ids, {
|
|
66
|
+
with: options.with ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
67
|
+
campaignKey,
|
|
68
|
+
pricePromotionKey: options.pricePromotionKey
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
{ method: "GET" }
|
|
72
|
+
);
|
|
73
|
+
export const getProductsByReferenceKeys = defineRpcHandler(
|
|
74
|
+
async (options, context) => {
|
|
75
|
+
const { sapiClient, cached, withParams } = context;
|
|
76
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
77
|
+
return await cached(
|
|
78
|
+
mapSAPIFetchErrorToResponse(sapiClient.products.getByReferenceKeys),
|
|
79
|
+
{
|
|
80
|
+
cacheKeyPrefix: "getByReferenceKeys-products",
|
|
81
|
+
ttl: 5 * MINUTE
|
|
82
|
+
}
|
|
83
|
+
)(options.referenceKeys, {
|
|
84
|
+
with: options.with ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
85
|
+
campaignKey,
|
|
86
|
+
pricePromotionKey: options.pricePromotionKey
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
{ method: "GET" }
|
|
90
|
+
);
|
|
82
91
|
export const getProductsCount = defineRpcHandler(
|
|
83
92
|
async (params, context) => {
|
|
84
93
|
const {
|
|
@@ -112,10 +121,7 @@ export const getProductsCount = defineRpcHandler(
|
|
|
112
121
|
where: {
|
|
113
122
|
...filter,
|
|
114
123
|
categoryId,
|
|
115
|
-
attributes: [
|
|
116
|
-
...sanitizedAttributes,
|
|
117
|
-
...whitelistAttributes || []
|
|
118
|
-
]
|
|
124
|
+
attributes: [...sanitizedAttributes, ...whitelistAttributes || []]
|
|
119
125
|
},
|
|
120
126
|
pagination: {
|
|
121
127
|
perPage: 1
|
|
@@ -131,32 +137,35 @@ export const getProductsCount = defineRpcHandler(
|
|
|
131
137
|
},
|
|
132
138
|
{ method: "GET" }
|
|
133
139
|
);
|
|
134
|
-
export const fetchAllFiltersForCategory = defineRpcHandler(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
140
|
+
export const fetchAllFiltersForCategory = defineRpcHandler(
|
|
141
|
+
async ({
|
|
142
|
+
includedFilters = [],
|
|
143
|
+
category,
|
|
144
|
+
includeSoldOut,
|
|
145
|
+
includeSellableForFree,
|
|
146
|
+
orFiltersOperator
|
|
147
|
+
}, context) => {
|
|
148
|
+
const { cached, sapiClient } = context;
|
|
149
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
150
|
+
const fetchAndMapFiltersToSlugs = async () => {
|
|
151
|
+
const filtersFromSAPI = await cached(sapiClient.filters.get)({
|
|
152
|
+
where: { categoryId: category.id },
|
|
153
|
+
campaignKey,
|
|
154
|
+
including: includedFilters,
|
|
155
|
+
includeSoldOut,
|
|
156
|
+
includeSellableForFree,
|
|
157
|
+
orFiltersOperator
|
|
158
|
+
});
|
|
159
|
+
return mapFiltersToSlugs(filtersFromSAPI);
|
|
160
|
+
};
|
|
161
|
+
return await cached(fetchAndMapFiltersToSlugs, {
|
|
162
|
+
ttl: 4 * 60 * 60,
|
|
163
|
+
// cached for 4 hours
|
|
164
|
+
cacheKey: `filters-for-category-${category.id}`
|
|
165
|
+
})();
|
|
166
|
+
},
|
|
167
|
+
{ method: "GET" }
|
|
168
|
+
);
|
|
160
169
|
async function getSanitizedAttributes(context, categoryId, attributes, includedFilters, includeSoldOut, includeSellableForFree, orFiltersOperator) {
|
|
161
170
|
const response = await fetchAllFiltersForCategory(
|
|
162
171
|
{
|
|
@@ -178,151 +187,154 @@ async function getSanitizedAttributes(context, categoryId, attributes, includedF
|
|
|
178
187
|
includedFilters
|
|
179
188
|
});
|
|
180
189
|
}
|
|
181
|
-
export const getFilters = defineRpcHandler(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
includeSellableForFree,
|
|
203
|
-
orFiltersOperator
|
|
204
|
-
);
|
|
205
|
-
if (response instanceof ErrorResponse) {
|
|
206
|
-
return response;
|
|
207
|
-
}
|
|
208
|
-
const sanitizedAttributes = response;
|
|
209
|
-
const [filters, productCount] = await Promise.all([
|
|
210
|
-
cached(sapiClient.filters.get, {
|
|
211
|
-
cacheKeyPrefix: `get-filters-${categoryId}`
|
|
212
|
-
})({
|
|
213
|
-
where: {
|
|
214
|
-
...filter,
|
|
215
|
-
categoryId,
|
|
216
|
-
attributes: [
|
|
217
|
-
...sanitizedAttributes,
|
|
218
|
-
...whitelistAttributes || []
|
|
219
|
-
]
|
|
220
|
-
},
|
|
190
|
+
export const getFilters = defineRpcHandler(
|
|
191
|
+
async (params, context) => {
|
|
192
|
+
const {
|
|
193
|
+
includedFilters,
|
|
194
|
+
where = void 0,
|
|
195
|
+
includeSoldOut = false,
|
|
196
|
+
includeSellableForFree = false,
|
|
197
|
+
orFiltersOperator
|
|
198
|
+
} = params;
|
|
199
|
+
const { cached, sapiClient } = context;
|
|
200
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
201
|
+
const { category, categoryId } = await resolveCategoryIdFromParams(
|
|
202
|
+
context,
|
|
203
|
+
params
|
|
204
|
+
);
|
|
205
|
+
const { attributes, whitelistAttributes, ...filter } = where || {};
|
|
206
|
+
const response = await getSanitizedAttributes(
|
|
207
|
+
context,
|
|
208
|
+
categoryId,
|
|
209
|
+
attributes || [],
|
|
210
|
+
includedFilters,
|
|
221
211
|
includeSoldOut,
|
|
222
212
|
includeSellableForFree,
|
|
223
|
-
campaignKey,
|
|
224
|
-
including: includedFilters,
|
|
225
213
|
orFiltersOperator
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
214
|
+
);
|
|
215
|
+
if (response instanceof ErrorResponse) {
|
|
216
|
+
return response;
|
|
217
|
+
}
|
|
218
|
+
const sanitizedAttributes = response;
|
|
219
|
+
const [filters, productCount] = await Promise.all([
|
|
220
|
+
cached(sapiClient.filters.get, {
|
|
221
|
+
cacheKeyPrefix: `get-filters-${categoryId}`
|
|
222
|
+
})({
|
|
223
|
+
where: {
|
|
224
|
+
...filter,
|
|
225
|
+
categoryId,
|
|
226
|
+
attributes: [
|
|
227
|
+
...sanitizedAttributes,
|
|
228
|
+
...whitelistAttributes || []
|
|
229
|
+
]
|
|
230
|
+
},
|
|
231
|
+
includeSoldOut,
|
|
232
|
+
includeSellableForFree,
|
|
233
|
+
campaignKey,
|
|
234
|
+
including: includedFilters,
|
|
235
|
+
orFiltersOperator
|
|
236
|
+
}),
|
|
237
|
+
cached(sapiClient.products.query, {
|
|
238
|
+
ttl: 15 * MINUTE,
|
|
239
|
+
cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : categoryId}`
|
|
240
|
+
})({
|
|
241
|
+
where: {
|
|
242
|
+
...filter,
|
|
243
|
+
categoryId,
|
|
244
|
+
attributes: [
|
|
245
|
+
...sanitizedAttributes,
|
|
246
|
+
...whitelistAttributes || []
|
|
247
|
+
]
|
|
248
|
+
},
|
|
249
|
+
pagination: {
|
|
250
|
+
perPage: 1
|
|
251
|
+
},
|
|
252
|
+
campaignKey,
|
|
253
|
+
includeSellableForFree,
|
|
254
|
+
includeSoldOut,
|
|
255
|
+
orFiltersOperator
|
|
256
|
+
})
|
|
257
|
+
]);
|
|
258
|
+
return {
|
|
259
|
+
filters,
|
|
260
|
+
unfilteredCount: productCount?.pagination.total
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
{ method: "GET" }
|
|
264
|
+
);
|
|
265
|
+
export const getProductsByCategory = defineRpcHandler(
|
|
266
|
+
async (params, context) => {
|
|
267
|
+
const {
|
|
268
|
+
includedFilters,
|
|
269
|
+
cache,
|
|
270
|
+
with: _with,
|
|
271
|
+
perPage = 20,
|
|
272
|
+
page = 1,
|
|
273
|
+
where = void 0,
|
|
274
|
+
sort = void 0,
|
|
275
|
+
pricePromotionKey = "",
|
|
276
|
+
includeSellableForFree = void 0,
|
|
277
|
+
includeSoldOut = void 0,
|
|
278
|
+
orFiltersOperator = void 0,
|
|
279
|
+
trackSearchAnalyticsEvent = void 0
|
|
280
|
+
} = params;
|
|
281
|
+
const { cached, sapiClient } = context;
|
|
282
|
+
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
283
|
+
const { category, categoryId } = await resolveCategoryIdFromParams(
|
|
284
|
+
context,
|
|
285
|
+
params
|
|
286
|
+
);
|
|
287
|
+
const { attributes, whitelistAttributes, ...filter } = where || {};
|
|
288
|
+
const response = await getSanitizedAttributes(
|
|
289
|
+
context,
|
|
290
|
+
categoryId,
|
|
291
|
+
attributes || [],
|
|
292
|
+
includedFilters,
|
|
293
|
+
includeSoldOut,
|
|
294
|
+
includeSellableForFree,
|
|
295
|
+
orFiltersOperator
|
|
296
|
+
);
|
|
297
|
+
if (response instanceof ErrorResponse) {
|
|
298
|
+
return response;
|
|
299
|
+
}
|
|
300
|
+
const sanitizedAttributes = response;
|
|
301
|
+
const { entities: products, pagination } = await cached(
|
|
302
|
+
sapiClient.products.query,
|
|
303
|
+
{
|
|
304
|
+
...cache,
|
|
305
|
+
ttl: cache?.ttl ?? 15 * MINUTE,
|
|
306
|
+
cacheKeyPrefix: cache?.cacheKeyPrefix || `products-query-category-${category === "/" ? "root" : categoryId}`
|
|
307
|
+
}
|
|
308
|
+
)({
|
|
231
309
|
where: {
|
|
232
310
|
...filter,
|
|
233
311
|
categoryId,
|
|
234
|
-
attributes: [
|
|
235
|
-
...sanitizedAttributes,
|
|
236
|
-
...whitelistAttributes || []
|
|
237
|
-
]
|
|
312
|
+
attributes: [...sanitizedAttributes, ...whitelistAttributes || []]
|
|
238
313
|
},
|
|
239
314
|
pagination: {
|
|
240
|
-
perPage:
|
|
315
|
+
perPage: Math.min(perPage, MAX_PER_PAGE),
|
|
316
|
+
page
|
|
241
317
|
},
|
|
242
318
|
campaignKey,
|
|
243
319
|
includeSellableForFree,
|
|
244
320
|
includeSoldOut,
|
|
245
|
-
orFiltersOperator
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
orFiltersOperator = void 0,
|
|
266
|
-
trackSearchAnalyticsEvent = void 0
|
|
267
|
-
} = params;
|
|
268
|
-
const { cached, sapiClient } = context;
|
|
269
|
-
const campaignKey = await context.callRpc?.("getCampaignKey");
|
|
270
|
-
const { category, categoryId } = await resolveCategoryIdFromParams(
|
|
271
|
-
context,
|
|
272
|
-
params
|
|
273
|
-
);
|
|
274
|
-
const { attributes, whitelistAttributes, ...filter } = where || {};
|
|
275
|
-
const response = await getSanitizedAttributes(
|
|
276
|
-
context,
|
|
277
|
-
categoryId,
|
|
278
|
-
attributes || [],
|
|
279
|
-
includedFilters,
|
|
280
|
-
includeSoldOut,
|
|
281
|
-
includeSellableForFree,
|
|
282
|
-
orFiltersOperator
|
|
283
|
-
);
|
|
284
|
-
if (response instanceof ErrorResponse) {
|
|
285
|
-
return response;
|
|
286
|
-
}
|
|
287
|
-
const sanitizedAttributes = response;
|
|
288
|
-
const { entities: products, pagination } = await cached(
|
|
289
|
-
sapiClient.products.query,
|
|
290
|
-
{
|
|
291
|
-
...cache,
|
|
292
|
-
ttl: cache?.ttl ?? 15 * MINUTE,
|
|
293
|
-
cacheKeyPrefix: cache?.cacheKeyPrefix || `products-query-category-${category === "/" ? "root" : categoryId}`
|
|
294
|
-
}
|
|
295
|
-
)({
|
|
296
|
-
where: {
|
|
297
|
-
...filter,
|
|
298
|
-
categoryId,
|
|
299
|
-
attributes: [
|
|
300
|
-
...sanitizedAttributes,
|
|
301
|
-
...whitelistAttributes || []
|
|
302
|
-
]
|
|
303
|
-
},
|
|
304
|
-
pagination: {
|
|
305
|
-
perPage: Math.min(perPage, MAX_PER_PAGE),
|
|
306
|
-
page
|
|
307
|
-
},
|
|
308
|
-
campaignKey,
|
|
309
|
-
includeSellableForFree,
|
|
310
|
-
includeSoldOut,
|
|
311
|
-
orFiltersOperator,
|
|
312
|
-
pricePromotionKey,
|
|
313
|
-
with: _with ?? context.withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
314
|
-
sort,
|
|
315
|
-
// NOTE: We only pass the parameter value through and don't implement a custom check.
|
|
316
|
-
// The consuming project should not include trackSearchAnalyticsEvent parameter when paginating through
|
|
317
|
-
// results with the page parameter, as this logs the search term on every page request.
|
|
318
|
-
// Instead, log the term only once, when the search is first performed.
|
|
319
|
-
// https://scayle.dev/en/core-documentation/the-basics/shops/search#scayle-search-analytics
|
|
320
|
-
trackSearchAnalyticsEvent
|
|
321
|
-
});
|
|
322
|
-
return {
|
|
323
|
-
products,
|
|
324
|
-
pagination: {
|
|
325
|
-
...pagination
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
}, { method: "GET" });
|
|
321
|
+
orFiltersOperator,
|
|
322
|
+
pricePromotionKey,
|
|
323
|
+
with: _with ?? context.withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
|
|
324
|
+
sort,
|
|
325
|
+
// NOTE: We only pass the parameter value through and don't implement a custom check.
|
|
326
|
+
// The consuming project should not include trackSearchAnalyticsEvent parameter when paginating through
|
|
327
|
+
// results with the page parameter, as this logs the search term on every page request.
|
|
328
|
+
// Instead, log the term only once, when the search is first performed.
|
|
329
|
+
// https://scayle.dev/en/core-documentation/the-basics/shops/search#scayle-search-analytics
|
|
330
|
+
trackSearchAnalyticsEvent
|
|
331
|
+
});
|
|
332
|
+
return {
|
|
333
|
+
products,
|
|
334
|
+
pagination: {
|
|
335
|
+
...pagination
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
},
|
|
339
|
+
{ method: "GET" }
|
|
340
|
+
);
|
|
@@ -10,34 +10,49 @@ const setPaginationDefault = (pagination) => {
|
|
|
10
10
|
perPage: pagination?.perPage || PROMOTION_PER_PAGE_DEFAULT
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
export const getPromotions = defineRpcHandler(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
13
|
+
export const getPromotions = defineRpcHandler(
|
|
14
|
+
async (params = {}, context) => {
|
|
15
|
+
const { sapiClient, cached } = context;
|
|
16
|
+
return await cached(
|
|
17
|
+
mapSAPIFetchErrorToResponse(sapiClient.promotions.get),
|
|
18
|
+
{
|
|
19
|
+
cacheKeyPrefix: "getPromotions"
|
|
20
|
+
}
|
|
21
|
+
)({
|
|
22
|
+
...params,
|
|
23
|
+
pagination: setPaginationDefault(params.pagination)
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
{ method: "GET" }
|
|
27
|
+
);
|
|
28
|
+
export const getCurrentPromotions = defineRpcHandler(
|
|
29
|
+
async (params = {}, context) => {
|
|
30
|
+
const { sapiClient, cached } = context;
|
|
31
|
+
const now = /* @__PURE__ */ new Date();
|
|
32
|
+
now.setSeconds(0, 0);
|
|
33
|
+
const activeAt = now.toISOString();
|
|
34
|
+
return await cached(
|
|
35
|
+
mapSAPIFetchErrorToResponse(sapiClient.promotions.get),
|
|
36
|
+
{
|
|
37
|
+
cacheKeyPrefix: "getPromotions"
|
|
38
|
+
}
|
|
39
|
+
)({
|
|
40
|
+
...params,
|
|
41
|
+
activeAt,
|
|
42
|
+
pagination: setPaginationDefault(params.pagination)
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
{ method: "GET" }
|
|
46
|
+
);
|
|
47
|
+
export const getPromotionsByIds = defineRpcHandler(
|
|
48
|
+
async (ids, context) => {
|
|
49
|
+
const { sapiClient, cached } = context;
|
|
50
|
+
return await cached(
|
|
51
|
+
mapSAPIFetchErrorToResponse(sapiClient.promotions.getByIds),
|
|
52
|
+
{
|
|
53
|
+
cacheKeyPrefix: "getByIds-promotions"
|
|
54
|
+
}
|
|
55
|
+
)(ids);
|
|
56
|
+
},
|
|
57
|
+
{ method: "GET" }
|
|
58
|
+
);
|
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
import { mapSAPIFetchErrorToResponse } from "../../utils/sapi.mjs";
|
|
2
2
|
import { defineRpcHandler } from "../../utils/index.mjs";
|
|
3
|
-
export const getSearchSuggestions = defineRpcHandler(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export const getSearchSuggestions = defineRpcHandler(
|
|
4
|
+
async ({ term, with: _with, categoryId }, context) => {
|
|
5
|
+
const { sapiClient, withParams } = context;
|
|
6
|
+
return await mapSAPIFetchErrorToResponse(sapiClient.searchv2.suggestions)(
|
|
7
|
+
term,
|
|
8
|
+
{
|
|
9
|
+
categoryId,
|
|
10
|
+
with: _with ?? withParams?.searchV2
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
},
|
|
14
|
+
{ method: "GET" }
|
|
15
|
+
);
|
|
16
|
+
export const resolveSearch = defineRpcHandler(
|
|
17
|
+
async ({ term, with: _with, categoryId }, context) => {
|
|
18
|
+
const { cached, sapiClient, withParams } = context;
|
|
19
|
+
const resolvedEntity = await cached(sapiClient.searchv2.resolve, {
|
|
20
|
+
cacheKeyPrefix: `resolve-${term}`
|
|
21
|
+
})(term, {
|
|
8
22
|
categoryId,
|
|
9
23
|
with: _with ?? withParams?.searchV2
|
|
24
|
+
});
|
|
25
|
+
if (!resolvedEntity) {
|
|
26
|
+
return null;
|
|
10
27
|
}
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const resolvedEntity = await cached(sapiClient.searchv2.resolve, {
|
|
16
|
-
cacheKeyPrefix: `resolve-${term}`
|
|
17
|
-
})(term, {
|
|
18
|
-
categoryId,
|
|
19
|
-
with: _with ?? withParams?.searchV2
|
|
20
|
-
});
|
|
21
|
-
if (!resolvedEntity) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
return resolvedEntity;
|
|
25
|
-
}, { method: "GET" });
|
|
28
|
+
return resolvedEntity;
|
|
29
|
+
},
|
|
30
|
+
{ method: "GET" }
|
|
31
|
+
);
|