@faststore/api 1.8.35 → 1.8.36
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 +11 -0
- package/dist/api.cjs.development.js +67 -17
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +67 -17
- package/dist/api.esm.js.map +1 -1
- package/dist/platforms/vtex/index.d.ts +2 -0
- package/dist/platforms/vtex/utils/channel.d.ts +0 -2
- package/dist/platforms/vtex/utils/contex.d.ts +3 -0
- package/dist/platforms/vtex/utils/facets.d.ts +2 -0
- package/package.json +2 -2
- package/src/platforms/vtex/clients/search/index.ts +28 -8
- package/src/platforms/vtex/index.ts +3 -0
- package/src/platforms/vtex/resolvers/query.ts +22 -11
- package/src/platforms/vtex/utils/channel.ts +0 -6
- package/src/platforms/vtex/utils/contex.ts +10 -0
- package/src/platforms/vtex/utils/facets.ts +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.8.36 (2022-05-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Top searches ([#1321](https://github.com/vtex/faststore/issues/1321)) ([e2ab99d](https://github.com/vtex/faststore/commit/e2ab99d4f443e013f3fd024fc83bb612fcb27f41))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 1.8.35 (2022-05-26)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -200,7 +200,8 @@ const IntelligentSearch = ({
|
|
|
200
200
|
count: count.toString(),
|
|
201
201
|
query,
|
|
202
202
|
sort,
|
|
203
|
-
fuzzy
|
|
203
|
+
fuzzy,
|
|
204
|
+
locale: ctx.storage.locale
|
|
204
205
|
});
|
|
205
206
|
|
|
206
207
|
if (hideUnavailableItems !== undefined) {
|
|
@@ -218,11 +219,32 @@ const IntelligentSearch = ({
|
|
|
218
219
|
type: 'product_search'
|
|
219
220
|
});
|
|
220
221
|
|
|
221
|
-
const suggestedProducts = args =>
|
|
222
|
+
const suggestedProducts = args => {
|
|
223
|
+
var _args$query$toString, _args$query;
|
|
222
224
|
|
|
223
|
-
|
|
225
|
+
const params = new URLSearchParams({
|
|
226
|
+
query: (_args$query$toString = (_args$query = args.query) == null ? void 0 : _args$query.toString()) != null ? _args$query$toString : '',
|
|
227
|
+
locale: ctx.storage.locale
|
|
228
|
+
});
|
|
229
|
+
return fetchAPI(`${base}/_v/api/intelligent-search/product_search?${params.toString()}`);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const suggestedTerms = args => {
|
|
233
|
+
var _args$query$toString2, _args$query2;
|
|
234
|
+
|
|
235
|
+
const params = new URLSearchParams({
|
|
236
|
+
query: (_args$query$toString2 = (_args$query2 = args.query) == null ? void 0 : _args$query2.toString()) != null ? _args$query$toString2 : '',
|
|
237
|
+
locale: ctx.storage.locale
|
|
238
|
+
});
|
|
239
|
+
return fetchAPI(`${base}/_v/api/intelligent-search/search_suggestions?${params.toString()}`);
|
|
240
|
+
};
|
|
224
241
|
|
|
225
|
-
const topSearches = () =>
|
|
242
|
+
const topSearches = () => {
|
|
243
|
+
const params = new URLSearchParams({
|
|
244
|
+
locale: ctx.storage.locale
|
|
245
|
+
});
|
|
246
|
+
return fetchAPI(`${base}/_v/api/intelligent-search/top_searches?${params.toString()}`);
|
|
247
|
+
};
|
|
226
248
|
|
|
227
249
|
const facets = args => search({ ...args,
|
|
228
250
|
type: 'facets'
|
|
@@ -897,9 +919,6 @@ class ChannelMarshal {
|
|
|
897
919
|
}
|
|
898
920
|
|
|
899
921
|
}
|
|
900
|
-
const mutateChannelContext = (ctx, channelString) => {
|
|
901
|
-
ctx.storage.channel = ChannelMarshal.parse(channelString);
|
|
902
|
-
};
|
|
903
922
|
|
|
904
923
|
const updateSession = async (_, {
|
|
905
924
|
session
|
|
@@ -1193,6 +1212,13 @@ const StoreProductGroup = {
|
|
|
1193
1212
|
}))))
|
|
1194
1213
|
};
|
|
1195
1214
|
|
|
1215
|
+
const mutateChannelContext = (ctx, channelString) => {
|
|
1216
|
+
ctx.storage.channel = ChannelMarshal.parse(channelString);
|
|
1217
|
+
};
|
|
1218
|
+
const mutateLocaleContext = (ctx, locale) => {
|
|
1219
|
+
ctx.storage.locale = locale;
|
|
1220
|
+
};
|
|
1221
|
+
|
|
1196
1222
|
/**
|
|
1197
1223
|
* Transform facets from the store to VTEX platform facets.
|
|
1198
1224
|
* For instance, the channel in Store becomes trade-policy and regionId in VTEX's realm
|
|
@@ -1221,6 +1247,11 @@ const transformSelectedFacet = ({
|
|
|
1221
1247
|
return channelFacets;
|
|
1222
1248
|
}
|
|
1223
1249
|
|
|
1250
|
+
case 'locale':
|
|
1251
|
+
{
|
|
1252
|
+
return []; // remove this facet from search
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1224
1255
|
default:
|
|
1225
1256
|
return {
|
|
1226
1257
|
key,
|
|
@@ -1228,6 +1259,16 @@ const transformSelectedFacet = ({
|
|
|
1228
1259
|
};
|
|
1229
1260
|
}
|
|
1230
1261
|
};
|
|
1262
|
+
const findLocale = facets => {
|
|
1263
|
+
var _facets$find$value, _facets$find;
|
|
1264
|
+
|
|
1265
|
+
return (_facets$find$value = facets == null ? void 0 : (_facets$find = facets.find(x => x.key === 'locale')) == null ? void 0 : _facets$find.value) != null ? _facets$find$value : null;
|
|
1266
|
+
};
|
|
1267
|
+
const findChannel = facets => {
|
|
1268
|
+
var _facets$find$value2, _facets$find2;
|
|
1269
|
+
|
|
1270
|
+
return (_facets$find$value2 = facets == null ? void 0 : (_facets$find2 = facets.find(facet => facet.key === 'channel')) == null ? void 0 : _facets$find2.value) != null ? _facets$find$value2 : null;
|
|
1271
|
+
};
|
|
1231
1272
|
|
|
1232
1273
|
const SORT_MAP = {
|
|
1233
1274
|
price_desc: 'price:desc',
|
|
@@ -1244,13 +1285,16 @@ const Query = {
|
|
|
1244
1285
|
product: async (_, {
|
|
1245
1286
|
locator
|
|
1246
1287
|
}, ctx) => {
|
|
1247
|
-
var _locator$find;
|
|
1248
|
-
|
|
1249
1288
|
// Insert channel in context for later usage
|
|
1250
|
-
const
|
|
1289
|
+
const channel = findChannel(locator);
|
|
1290
|
+
const locale = findLocale(locator);
|
|
1251
1291
|
|
|
1252
|
-
if (
|
|
1253
|
-
mutateChannelContext(ctx,
|
|
1292
|
+
if (channel) {
|
|
1293
|
+
mutateChannelContext(ctx, channel);
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
if (locale) {
|
|
1297
|
+
mutateLocaleContext(ctx, locale);
|
|
1254
1298
|
}
|
|
1255
1299
|
|
|
1256
1300
|
const {
|
|
@@ -1277,13 +1321,18 @@ const Query = {
|
|
|
1277
1321
|
term,
|
|
1278
1322
|
selectedFacets
|
|
1279
1323
|
}, ctx) => {
|
|
1280
|
-
var _selectedFacets$
|
|
1324
|
+
var _selectedFacets$flatM;
|
|
1281
1325
|
|
|
1282
1326
|
// Insert channel in context for later usage
|
|
1283
|
-
const
|
|
1327
|
+
const channel = findChannel(selectedFacets);
|
|
1328
|
+
const locale = findLocale(selectedFacets);
|
|
1329
|
+
|
|
1330
|
+
if (channel) {
|
|
1331
|
+
mutateChannelContext(ctx, channel);
|
|
1332
|
+
}
|
|
1284
1333
|
|
|
1285
|
-
if (
|
|
1286
|
-
|
|
1334
|
+
if (locale) {
|
|
1335
|
+
mutateLocaleContext(ctx, locale);
|
|
1287
1336
|
}
|
|
1288
1337
|
|
|
1289
1338
|
const after = maybeAfter ? Number(maybeAfter) : 0;
|
|
@@ -1595,7 +1644,8 @@ const getContextFactory = options => ctx => {
|
|
|
1595
1644
|
|
|
1596
1645
|
ctx.storage = {
|
|
1597
1646
|
channel: ChannelMarshal.parse(options.channel),
|
|
1598
|
-
flags: (_options$flags = options.flags) != null ? _options$flags : {}
|
|
1647
|
+
flags: (_options$flags = options.flags) != null ? _options$flags : {},
|
|
1648
|
+
locale: options.locale
|
|
1599
1649
|
};
|
|
1600
1650
|
ctx.clients = getClients(options, ctx);
|
|
1601
1651
|
ctx.loaders = getLoaders(options, ctx);
|