@faststore/api 1.8.33 → 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 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.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
+
17
+ ## 1.8.35 (2022-05-26)
18
+
19
+
20
+ ### Features
21
+
22
+ * Add OutOfStock component ([#1314](https://github.com/vtex/faststore/issues/1314)) ([37eac86](https://github.com/vtex/faststore/commit/37eac86ede448ef68aef426f65f2d224694b2cfc))
23
+
24
+
25
+
26
+
27
+
28
+ ## 1.8.34 (2022-05-25)
29
+
30
+ **Note:** Version bump only for package @faststore/api
31
+
32
+
33
+
34
+
35
+
6
36
  ## 1.8.33 (2022-05-24)
7
37
 
8
38
 
@@ -427,6 +427,8 @@ export declare type StorePropertyValue = {
427
427
  __typename?: 'StorePropertyValue';
428
428
  /** Property name. */
429
429
  name: Scalars['String'];
430
+ /** Property id. This propert changes according to the content of the object. */
431
+ propertyID: Scalars['String'];
430
432
  /** Property value. May hold a string or the string representation of an object. */
431
433
  value: Scalars['ObjectOrString'];
432
434
  /** Specifies the nature of the value */
@@ -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 => fetchAPI(`${base}/_v/api/intelligent-search/product_search?query=${args.query}`);
222
+ const suggestedProducts = 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/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 = () => fetchAPI(`${base}/_v/api/intelligent-search/top_searches`);
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'
@@ -634,10 +656,19 @@ const StoreFacetValue = {
634
656
  const md5 = payload => crypto.createHash('md5').update(payload).digest('hex');
635
657
 
636
658
  const VALUE_REFERENCES = {
637
- variation: 'VARIATION',
638
659
  attachment: 'ATTACHMENT',
639
660
  specification: 'SPECIFICATION'
640
661
  };
662
+ function attachmentToPropertyValue(attachment) {
663
+ return {
664
+ name: attachment.name,
665
+ value: attachment.content,
666
+ valueReference: VALUE_REFERENCES.attachment
667
+ };
668
+ }
669
+ function getPropertyId(item) {
670
+ return md5(`${item.name}:${JSON.stringify(item.value)}:${item.valueReference}`);
671
+ }
641
672
 
642
673
  const getAttachments = item => {
643
674
  var _item$itemOffered$add;
@@ -645,18 +676,12 @@ const getAttachments = item => {
645
676
  return (_item$itemOffered$add = item.itemOffered.additionalProperty) == null ? void 0 : _item$itemOffered$add.filter(i => i.valueReference === VALUE_REFERENCES.attachment);
646
677
  };
647
678
 
648
- const serializeAttachment = item => {
649
- const attachments = getAttachments(item);
650
-
651
- if ((attachments == null ? void 0 : attachments.length) === 0) {
652
- return null;
653
- }
679
+ const getId = item => {
680
+ var _item$itemOffered$add2;
654
681
 
655
- return attachments == null ? void 0 : attachments.map(attachment => `${attachment.name}:${JSON.stringify(attachment.value)}`).join('-');
682
+ return [item.itemOffered.sku, item.seller.identifier, item.price, (_item$itemOffered$add2 = item.itemOffered.additionalProperty) == null ? void 0 : _item$itemOffered$add2.map(getPropertyId).join('-')].filter(Boolean).join('::');
656
683
  };
657
684
 
658
- const getId = item => [item.itemOffered.sku, item.seller.identifier, item.price, serializeAttachment(item)].filter(Boolean).join('::');
659
-
660
685
  const orderFormItemToOffer = (item, index) => ({
661
686
  listPrice: item.listPrice / 100,
662
687
  price: item.sellingPrice / 100,
@@ -667,7 +692,8 @@ const orderFormItemToOffer = (item, index) => ({
667
692
  itemOffered: {
668
693
  sku: item.id,
669
694
  image: [],
670
- name: item.name
695
+ name: item.name,
696
+ additionalProperty: item.attachments.map(attachmentToPropertyValue)
671
697
  },
672
698
  index
673
699
  });
@@ -680,7 +706,7 @@ const offerToOrderItemInput = offer => {
680
706
  seller: offer.seller.identifier,
681
707
  id: offer.itemOffered.sku,
682
708
  index: offer.index,
683
- attachments: (_getAttachments = getAttachments(offer)) == null ? void 0 : _getAttachments.map(attachment => ({
709
+ attachments: ((_getAttachments = getAttachments(offer)) != null ? _getAttachments : []).map(attachment => ({
684
710
  name: attachment.name,
685
711
  content: attachment.value
686
712
  }))
@@ -893,9 +919,6 @@ class ChannelMarshal {
893
919
  }
894
920
 
895
921
  }
896
- const mutateChannelContext = (ctx, channelString) => {
897
- ctx.storage.channel = ChannelMarshal.parse(channelString);
898
- };
899
922
 
900
923
  const updateSession = async (_, {
901
924
  session
@@ -1145,23 +1168,20 @@ const StoreProduct = {
1145
1168
  })).sort(bestOfferFirst),
1146
1169
  isVariantOf: root => root,
1147
1170
  additionalProperty: ({
1148
- variations = [],
1149
- attachmentsValues
1171
+ // Search uses the name variations for specifications
1172
+ variations: specifications = [],
1173
+ attachmentsValues = []
1150
1174
  }) => {
1151
- const propertyValueVariations = variations.flatMap(({
1175
+ const propertyValueSpecifications = specifications.flatMap(({
1152
1176
  name,
1153
1177
  values
1154
1178
  }) => values.map(value => ({
1155
1179
  name,
1156
1180
  value,
1157
- valueReference: VALUE_REFERENCES.variation
1181
+ valueReference: VALUE_REFERENCES.specification
1158
1182
  })));
1159
- const propertyValueAttachments = (attachmentsValues != null ? attachmentsValues : []).map(attachment => ({
1160
- name: attachment.name,
1161
- value: attachment.content,
1162
- valueReference: VALUE_REFERENCES.attachment
1163
- }));
1164
- return [...propertyValueVariations, ...propertyValueAttachments];
1183
+ const propertyValueAttachments = attachmentsValues.map(attachmentToPropertyValue);
1184
+ return [...propertyValueSpecifications, ...propertyValueAttachments];
1165
1185
  }
1166
1186
  };
1167
1187
 
@@ -1192,6 +1212,13 @@ const StoreProductGroup = {
1192
1212
  }))))
1193
1213
  };
1194
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
+
1195
1222
  /**
1196
1223
  * Transform facets from the store to VTEX platform facets.
1197
1224
  * For instance, the channel in Store becomes trade-policy and regionId in VTEX's realm
@@ -1220,6 +1247,11 @@ const transformSelectedFacet = ({
1220
1247
  return channelFacets;
1221
1248
  }
1222
1249
 
1250
+ case 'locale':
1251
+ {
1252
+ return []; // remove this facet from search
1253
+ }
1254
+
1223
1255
  default:
1224
1256
  return {
1225
1257
  key,
@@ -1227,6 +1259,16 @@ const transformSelectedFacet = ({
1227
1259
  };
1228
1260
  }
1229
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
+ };
1230
1272
 
1231
1273
  const SORT_MAP = {
1232
1274
  price_desc: 'price:desc',
@@ -1243,13 +1285,16 @@ const Query = {
1243
1285
  product: async (_, {
1244
1286
  locator
1245
1287
  }, ctx) => {
1246
- var _locator$find;
1247
-
1248
1288
  // Insert channel in context for later usage
1249
- const channelString = (_locator$find = locator.find(facet => facet.key === 'channel')) == null ? void 0 : _locator$find.value;
1289
+ const channel = findChannel(locator);
1290
+ const locale = findLocale(locator);
1291
+
1292
+ if (channel) {
1293
+ mutateChannelContext(ctx, channel);
1294
+ }
1250
1295
 
1251
- if (channelString) {
1252
- mutateChannelContext(ctx, channelString);
1296
+ if (locale) {
1297
+ mutateLocaleContext(ctx, locale);
1253
1298
  }
1254
1299
 
1255
1300
  const {
@@ -1276,13 +1321,18 @@ const Query = {
1276
1321
  term,
1277
1322
  selectedFacets
1278
1323
  }, ctx) => {
1279
- var _selectedFacets$find, _selectedFacets$flatM;
1324
+ var _selectedFacets$flatM;
1280
1325
 
1281
1326
  // Insert channel in context for later usage
1282
- const channelString = selectedFacets == null ? void 0 : (_selectedFacets$find = selectedFacets.find(facet => facet.key === 'channel')) == null ? void 0 : _selectedFacets$find.value;
1327
+ const channel = findChannel(selectedFacets);
1328
+ const locale = findLocale(selectedFacets);
1329
+
1330
+ if (channel) {
1331
+ mutateChannelContext(ctx, channel);
1332
+ }
1283
1333
 
1284
- if (channelString) {
1285
- mutateChannelContext(ctx, channelString);
1334
+ if (locale) {
1335
+ mutateLocaleContext(ctx, locale);
1286
1336
  }
1287
1337
 
1288
1338
  const after = maybeAfter ? Number(maybeAfter) : 0;
@@ -1559,6 +1609,19 @@ function stringify(value) {
1559
1609
  return null;
1560
1610
  }
1561
1611
 
1612
+ const StorePropertyValue = {
1613
+ propertyID: root => getPropertyId(root),
1614
+ name: ({
1615
+ name
1616
+ }) => name,
1617
+ value: ({
1618
+ value
1619
+ }) => value,
1620
+ valueReference: ({
1621
+ valueReference
1622
+ }) => valueReference
1623
+ };
1624
+
1562
1625
  const Resolvers = {
1563
1626
  StoreCollection,
1564
1627
  StoreAggregateOffer,
@@ -1571,6 +1634,7 @@ const Resolvers = {
1571
1634
  StoreReview,
1572
1635
  StoreProductGroup,
1573
1636
  StoreSearchResult,
1637
+ StorePropertyValue,
1574
1638
  ObjectOrString,
1575
1639
  Query,
1576
1640
  Mutation
@@ -1580,7 +1644,8 @@ const getContextFactory = options => ctx => {
1580
1644
 
1581
1645
  ctx.storage = {
1582
1646
  channel: ChannelMarshal.parse(options.channel),
1583
- flags: (_options$flags = options.flags) != null ? _options$flags : {}
1647
+ flags: (_options$flags = options.flags) != null ? _options$flags : {},
1648
+ locale: options.locale
1584
1649
  };
1585
1650
  ctx.clients = getClients(options, ctx);
1586
1651
  ctx.loaders = getLoaders(options, ctx);
@@ -1648,8 +1713,8 @@ var doc$i = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","de
1648
1713
  var doc$j = {"kind":"Document","definitions":[{"kind":"EnumTypeDefinition","description":{"kind":"StringValue","value":"Status used to indicate type of message. For instance, in shopping cart messages.","block":true},"name":{"kind":"Name","value":"StoreStatus"},"directives":[],"values":[{"kind":"EnumValueDefinition","name":{"kind":"Name","value":"INFO"},"directives":[]},{"kind":"EnumValueDefinition","name":{"kind":"Name","value":"WARNING"},"directives":[]},{"kind":"EnumValueDefinition","name":{"kind":"Name","value":"ERROR"},"directives":[]}]}],"loc":{"start":0,"end":136}};
1649
1714
  doc$j.loc.source = {"body":"\"\"\"\nStatus used to indicate type of message. For instance, in shopping cart messages.\n\"\"\"\nenum StoreStatus {\n INFO\n WARNING\n ERROR\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
1650
1715
 
1651
- var doc$k = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Properties that can be associated with products and products groups.","block":true},"name":{"kind":"Name","value":"StorePropertyValue"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Property value. May hold a string or the string representation of an object.","block":true},"name":{"kind":"Name","value":"value"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ObjectOrString"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Property name.","block":true},"name":{"kind":"Name","value":"name"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Specifies the nature of the value","block":true},"name":{"kind":"Name","value":"valueReference"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]},{"kind":"InputObjectTypeDefinition","name":{"kind":"Name","value":"IStorePropertyValue"},"directives":[],"fields":[{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Property value. May hold a string or the string representation of an object.","block":true},"name":{"kind":"Name","value":"value"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ObjectOrString"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Property name.","block":true},"name":{"kind":"Name","value":"name"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Specifies the nature of the value","block":true},"name":{"kind":"Name","value":"valueReference"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]}],"loc":{"start":0,"end":606}};
1652
- doc$k.loc.source = {"body":"\"\"\"\nProperties that can be associated with products and products groups.\n\"\"\"\ntype StorePropertyValue {\n \"\"\"\n Property value. May hold a string or the string representation of an object.\n \"\"\"\n value: ObjectOrString!\n \"\"\"\n Property name.\n \"\"\"\n name: String!\n \"\"\"\n Specifies the nature of the value\n \"\"\"\n valueReference: String!\n}\n\ninput IStorePropertyValue {\n \"\"\"\n Property value. May hold a string or the string representation of an object.\n \"\"\"\n value: ObjectOrString!\n \"\"\"\n Property name.\n \"\"\"\n name: String!\n \"\"\"\n Specifies the nature of the value\n \"\"\"\n valueReference: String!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
1716
+ var doc$k = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Properties that can be associated with products and products groups.","block":true},"name":{"kind":"Name","value":"StorePropertyValue"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Property id. This propert changes according to the content of the object.","block":true},"name":{"kind":"Name","value":"propertyID"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Property value. May hold a string or the string representation of an object.","block":true},"name":{"kind":"Name","value":"value"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ObjectOrString"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Property name.","block":true},"name":{"kind":"Name","value":"name"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Specifies the nature of the value","block":true},"name":{"kind":"Name","value":"valueReference"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]},{"kind":"InputObjectTypeDefinition","name":{"kind":"Name","value":"IStorePropertyValue"},"directives":[],"fields":[{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Property value. May hold a string or the string representation of an object.","block":true},"name":{"kind":"Name","value":"value"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ObjectOrString"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Property name.","block":true},"name":{"kind":"Name","value":"name"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"InputValueDefinition","description":{"kind":"StringValue","value":"Specifies the nature of the value","block":true},"name":{"kind":"Name","value":"valueReference"},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]}],"loc":{"start":0,"end":716}};
1717
+ doc$k.loc.source = {"body":"\"\"\"\nProperties that can be associated with products and products groups.\n\"\"\"\ntype StorePropertyValue {\n \"\"\"\n Property id. This propert changes according to the content of the object.\n \"\"\"\n propertyID: String!\n \"\"\"\n Property value. May hold a string or the string representation of an object.\n \"\"\"\n value: ObjectOrString!\n \"\"\"\n Property name.\n \"\"\"\n name: String!\n \"\"\"\n Specifies the nature of the value\n \"\"\"\n valueReference: String!\n}\n\ninput IStorePropertyValue {\n \"\"\"\n Property value. May hold a string or the string representation of an object.\n \"\"\"\n value: ObjectOrString!\n \"\"\"\n Property name.\n \"\"\"\n name: String!\n \"\"\"\n Specifies the nature of the value\n \"\"\"\n valueReference: String!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};
1653
1718
 
1654
1719
  var doc$l = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","description":{"kind":"StringValue","value":"Client profile data.","block":true},"name":{"kind":"Name","value":"StorePerson"},"interfaces":[],"directives":[],"fields":[{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Client ID.","block":true},"name":{"kind":"Name","value":"id"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Client email.","block":true},"name":{"kind":"Name","value":"email"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Client first name.","block":true},"name":{"kind":"Name","value":"givenName"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]},{"kind":"FieldDefinition","description":{"kind":"StringValue","value":"Client last name.","block":true},"name":{"kind":"Name","value":"familyName"},"arguments":[],"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},"directives":[]}]}],"loc":{"start":0,"end":242}};
1655
1720
  doc$l.loc.source = {"body":"\"\"\"\nClient profile data.\n\"\"\"\ntype StorePerson {\n \"\"\"\n Client ID.\n \"\"\"\n id: String!\n \"\"\"\n Client email.\n \"\"\"\n email: String!\n \"\"\"\n Client first name.\n \"\"\"\n givenName: String!\n \"\"\"\n Client last name.\n \"\"\"\n familyName: String!\n}\n","name":"GraphQL request","locationOffset":{"line":1,"column":1}};