@faststore/api 1.8.17 → 1.8.20

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,30 @@
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.20 (2022-05-16)
7
+
8
+ **Note:** Version bump only for package @faststore/api
9
+
10
+
11
+
12
+
13
+
14
+ ## 1.8.19 (2022-05-14)
15
+
16
+ **Note:** Version bump only for package @faststore/api
17
+
18
+
19
+
20
+
21
+
22
+ ## 1.8.18 (2022-05-14)
23
+
24
+ **Note:** Version bump only for package @faststore/api
25
+
26
+
27
+
28
+
29
+
6
30
  ## 1.8.17 (2022-05-13)
7
31
 
8
32
 
@@ -107,27 +107,68 @@ const VtexCommerce = ({
107
107
  };
108
108
  };
109
109
 
110
+ const POLICY_KEY = 'trade-policy';
111
+ const REGION_KEY = 'region-id';
112
+ const CHANNEL_KEYS = /*#__PURE__*/new Set([POLICY_KEY, REGION_KEY]);
110
113
  const IntelligentSearch = ({
111
114
  account,
112
115
  environment,
113
116
  hideUnavailableItems
114
117
  }, ctx) => {
115
118
  const base = `https://${account}.${environment}.com.br/api/io`;
116
- const policyFacet = {
117
- key: 'trade-policy',
118
- value: ctx.storage.channel.salesChannel
119
+
120
+ const getPolicyFacet = () => {
121
+ const {
122
+ salesChannel
123
+ } = ctx.storage.channel;
124
+
125
+ if (!salesChannel) {
126
+ return null;
127
+ }
128
+
129
+ return {
130
+ key: POLICY_KEY,
131
+ value: salesChannel
132
+ };
133
+ };
134
+
135
+ const getRegionFacet = () => {
136
+ const {
137
+ regionId
138
+ } = ctx.storage.channel;
139
+
140
+ if (!regionId) {
141
+ return null;
142
+ }
143
+
144
+ return {
145
+ key: REGION_KEY,
146
+ value: regionId
147
+ };
119
148
  };
120
149
 
121
150
  const addDefaultFacets = facets => {
122
- const facet = facets.find(({
151
+ var _facets$find, _facets$find2;
152
+
153
+ const withDefaltFacets = facets.filter(({
154
+ key
155
+ }) => !CHANNEL_KEYS.has(key));
156
+ const policyFacet = (_facets$find = facets.find(({
157
+ key
158
+ }) => key === POLICY_KEY)) != null ? _facets$find : getPolicyFacet();
159
+ const regionFacet = (_facets$find2 = facets.find(({
123
160
  key
124
- }) => key === policyFacet.key);
161
+ }) => key === REGION_KEY)) != null ? _facets$find2 : getRegionFacet();
125
162
 
126
- if (facet === undefined) {
127
- return [...facets, policyFacet];
163
+ if (policyFacet !== null) {
164
+ withDefaltFacets.push(policyFacet);
128
165
  }
129
166
 
130
- return facets;
167
+ if (regionFacet !== null) {
168
+ withDefaltFacets.push(regionFacet);
169
+ }
170
+
171
+ return withDefaltFacets;
131
172
  };
132
173
 
133
174
  const search = ({
@@ -166,6 +207,8 @@ const IntelligentSearch = ({
166
207
 
167
208
  const suggestedTerms = args => fetchAPI(`${base}/_v/api/intelligent-search/search_suggestions?query=${args.query}`);
168
209
 
210
+ const topSearches = () => fetchAPI(`${base}/_v/api/intelligent-search/top_searches`);
211
+
169
212
  const facets = args => search({ ...args,
170
213
  type: 'facets'
171
214
  });
@@ -174,7 +217,8 @@ const IntelligentSearch = ({
174
217
  facets,
175
218
  products,
176
219
  suggestedTerms,
177
- suggestedProducts
220
+ suggestedProducts,
221
+ topSearches
178
222
  };
179
223
  };
180
224
 
@@ -743,9 +787,7 @@ class ChannelMarshal {
743
787
 
744
788
  }
745
789
  const mutateChannelContext = (ctx, channelString) => {
746
- ctx.storage = { ...ctx.storage,
747
- channel: ChannelMarshal.parse(channelString)
748
- };
790
+ ctx.storage.channel = ChannelMarshal.parse(channelString);
749
791
  };
750
792
 
751
793
  const updateSession = async (_, {
@@ -1087,7 +1129,7 @@ const Query = {
1087
1129
  skuLoader
1088
1130
  }
1089
1131
  } = ctx;
1090
- return skuLoader.load(locator.flatMap(transformSelectedFacet));
1132
+ return skuLoader.load(locator);
1091
1133
  },
1092
1134
  collection: (_, {
1093
1135
  slug
@@ -1240,7 +1282,16 @@ const StoreSearchResult = {
1240
1282
  clients: {
1241
1283
  search
1242
1284
  }
1243
- } = ctx;
1285
+ } = ctx; // If there's no search query, suggest the most popular searches.
1286
+
1287
+ if (!searchArgs.query) {
1288
+ const topSearches = await search.topSearches();
1289
+ return {
1290
+ terms: topSearches.searches.map(item => item.term),
1291
+ products: []
1292
+ };
1293
+ }
1294
+
1244
1295
  const terms = await search.suggestedTerms(searchArgs);
1245
1296
  const products = await search.suggestedProducts(searchArgs);
1246
1297
  const skus = products.products.map(product => {