@faststore/api 1.8.35 → 1.8.38

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 CHANGED
@@ -3,6 +3,36 @@
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.38 (2022-05-27)
7
+
8
+ **Note:** Version bump only for package @faststore/api
9
+
10
+
11
+
12
+
13
+
14
+ ## 1.8.37 (2022-05-27)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * Increase NodeJS version ([#1323](https://github.com/vtex/faststore/issues/1323)) ([3a6fbe7](https://github.com/vtex/faststore/commit/3a6fbe7c230b7056582c783464bfb45cc5717bed))
20
+
21
+
22
+
23
+
24
+
25
+ ## 1.8.36 (2022-05-26)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * Top searches ([#1321](https://github.com/vtex/faststore/issues/1321)) ([e2ab99d](https://github.com/vtex/faststore/commit/e2ab99d4f443e013f3fd024fc83bb612fcb27f41))
31
+
32
+
33
+
34
+
35
+
6
36
  ## 1.8.35 (2022-05-26)
7
37
 
8
38
 
@@ -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,22 @@ const IntelligentSearch = ({
218
219
  type: 'product_search'
219
220
  });
220
221
 
221
- const suggestedProducts = args => fetchAPI(`${base}/_v/api/intelligent-search/product_search?query=${args.query}`);
222
+ const suggestedTerms = args => {
223
+ var _args$query$toString, _args$query;
222
224
 
223
- const suggestedTerms = args => fetchAPI(`${base}/_v/api/intelligent-search/search_suggestions?query=${args.query}`);
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/search_suggestions?${params.toString()}`);
230
+ };
224
231
 
225
- const topSearches = () => fetchAPI(`${base}/_v/api/intelligent-search/top_searches`);
232
+ const topSearches = () => {
233
+ const params = new URLSearchParams({
234
+ locale: ctx.storage.locale
235
+ });
236
+ return fetchAPI(`${base}/_v/api/intelligent-search/top_searches?${params.toString()}`);
237
+ };
226
238
 
227
239
  const facets = args => search({ ...args,
228
240
  type: 'facets'
@@ -232,7 +244,6 @@ const IntelligentSearch = ({
232
244
  facets,
233
245
  products,
234
246
  suggestedTerms,
235
- suggestedProducts,
236
247
  topSearches
237
248
  };
238
249
  };
@@ -897,9 +908,6 @@ class ChannelMarshal {
897
908
  }
898
909
 
899
910
  }
900
- const mutateChannelContext = (ctx, channelString) => {
901
- ctx.storage.channel = ChannelMarshal.parse(channelString);
902
- };
903
911
 
904
912
  const updateSession = async (_, {
905
913
  session
@@ -1193,6 +1201,13 @@ const StoreProductGroup = {
1193
1201
  }))))
1194
1202
  };
1195
1203
 
1204
+ const mutateChannelContext = (ctx, channelString) => {
1205
+ ctx.storage.channel = ChannelMarshal.parse(channelString);
1206
+ };
1207
+ const mutateLocaleContext = (ctx, locale) => {
1208
+ ctx.storage.locale = locale;
1209
+ };
1210
+
1196
1211
  /**
1197
1212
  * Transform facets from the store to VTEX platform facets.
1198
1213
  * For instance, the channel in Store becomes trade-policy and regionId in VTEX's realm
@@ -1221,6 +1236,11 @@ const transformSelectedFacet = ({
1221
1236
  return channelFacets;
1222
1237
  }
1223
1238
 
1239
+ case 'locale':
1240
+ {
1241
+ return []; // remove this facet from search
1242
+ }
1243
+
1224
1244
  default:
1225
1245
  return {
1226
1246
  key,
@@ -1228,6 +1248,16 @@ const transformSelectedFacet = ({
1228
1248
  };
1229
1249
  }
1230
1250
  };
1251
+ const findLocale = facets => {
1252
+ var _facets$find$value, _facets$find;
1253
+
1254
+ 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;
1255
+ };
1256
+ const findChannel = facets => {
1257
+ var _facets$find$value2, _facets$find2;
1258
+
1259
+ 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;
1260
+ };
1231
1261
 
1232
1262
  const SORT_MAP = {
1233
1263
  price_desc: 'price:desc',
@@ -1244,13 +1274,16 @@ const Query = {
1244
1274
  product: async (_, {
1245
1275
  locator
1246
1276
  }, ctx) => {
1247
- var _locator$find;
1248
-
1249
1277
  // Insert channel in context for later usage
1250
- const channelString = (_locator$find = locator.find(facet => facet.key === 'channel')) == null ? void 0 : _locator$find.value;
1278
+ const channel = findChannel(locator);
1279
+ const locale = findLocale(locator);
1280
+
1281
+ if (channel) {
1282
+ mutateChannelContext(ctx, channel);
1283
+ }
1251
1284
 
1252
- if (channelString) {
1253
- mutateChannelContext(ctx, channelString);
1285
+ if (locale) {
1286
+ mutateLocaleContext(ctx, locale);
1254
1287
  }
1255
1288
 
1256
1289
  const {
@@ -1277,13 +1310,18 @@ const Query = {
1277
1310
  term,
1278
1311
  selectedFacets
1279
1312
  }, ctx) => {
1280
- var _selectedFacets$find, _selectedFacets$flatM;
1313
+ var _selectedFacets$flatM;
1281
1314
 
1282
1315
  // Insert channel in context for later usage
1283
- const channelString = selectedFacets == null ? void 0 : (_selectedFacets$find = selectedFacets.find(facet => facet.key === 'channel')) == null ? void 0 : _selectedFacets$find.value;
1316
+ const channel = findChannel(selectedFacets);
1317
+ const locale = findLocale(selectedFacets);
1318
+
1319
+ if (channel) {
1320
+ mutateChannelContext(ctx, channel);
1321
+ }
1284
1322
 
1285
- if (channelString) {
1286
- mutateChannelContext(ctx, channelString);
1323
+ if (locale) {
1324
+ mutateLocaleContext(ctx, locale);
1287
1325
  }
1288
1326
 
1289
1327
  const after = maybeAfter ? Number(maybeAfter) : 0;
@@ -1422,7 +1460,7 @@ const StoreSearchResult = {
1422
1460
  }
1423
1461
 
1424
1462
  const terms = await search.suggestedTerms(searchArgs);
1425
- const products = await search.suggestedProducts(searchArgs);
1463
+ const products = await search.products(searchArgs);
1426
1464
  const skus = products.products.map(product => {
1427
1465
  const [maybeSku] = product.items;
1428
1466
  return maybeSku && enhanceSku(maybeSku, product);
@@ -1595,7 +1633,8 @@ const getContextFactory = options => ctx => {
1595
1633
 
1596
1634
  ctx.storage = {
1597
1635
  channel: ChannelMarshal.parse(options.channel),
1598
- flags: (_options$flags = options.flags) != null ? _options$flags : {}
1636
+ flags: (_options$flags = options.flags) != null ? _options$flags : {},
1637
+ locale: options.locale
1599
1638
  };
1600
1639
  ctx.clients = getClients(options, ctx);
1601
1640
  ctx.loaders = getLoaders(options, ctx);