@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/dist/api.esm.js CHANGED
@@ -194,7 +194,8 @@ const IntelligentSearch = ({
194
194
  count: count.toString(),
195
195
  query,
196
196
  sort,
197
- fuzzy
197
+ fuzzy,
198
+ locale: ctx.storage.locale
198
199
  });
199
200
 
200
201
  if (hideUnavailableItems !== undefined) {
@@ -212,11 +213,32 @@ const IntelligentSearch = ({
212
213
  type: 'product_search'
213
214
  });
214
215
 
215
- const suggestedProducts = args => fetchAPI(`${base}/_v/api/intelligent-search/product_search?query=${args.query}`);
216
+ const suggestedProducts = args => {
217
+ var _args$query$toString, _args$query;
216
218
 
217
- const suggestedTerms = args => fetchAPI(`${base}/_v/api/intelligent-search/search_suggestions?query=${args.query}`);
219
+ const params = new URLSearchParams({
220
+ query: (_args$query$toString = (_args$query = args.query) == null ? void 0 : _args$query.toString()) != null ? _args$query$toString : '',
221
+ locale: ctx.storage.locale
222
+ });
223
+ return fetchAPI(`${base}/_v/api/intelligent-search/product_search?${params.toString()}`);
224
+ };
225
+
226
+ const suggestedTerms = args => {
227
+ var _args$query$toString2, _args$query2;
228
+
229
+ const params = new URLSearchParams({
230
+ query: (_args$query$toString2 = (_args$query2 = args.query) == null ? void 0 : _args$query2.toString()) != null ? _args$query$toString2 : '',
231
+ locale: ctx.storage.locale
232
+ });
233
+ return fetchAPI(`${base}/_v/api/intelligent-search/search_suggestions?${params.toString()}`);
234
+ };
218
235
 
219
- const topSearches = () => fetchAPI(`${base}/_v/api/intelligent-search/top_searches`);
236
+ const topSearches = () => {
237
+ const params = new URLSearchParams({
238
+ locale: ctx.storage.locale
239
+ });
240
+ return fetchAPI(`${base}/_v/api/intelligent-search/top_searches?${params.toString()}`);
241
+ };
220
242
 
221
243
  const facets = args => search({ ...args,
222
244
  type: 'facets'
@@ -628,10 +650,19 @@ const StoreFacetValue = {
628
650
  const md5 = payload => crypto.createHash('md5').update(payload).digest('hex');
629
651
 
630
652
  const VALUE_REFERENCES = {
631
- variation: 'VARIATION',
632
653
  attachment: 'ATTACHMENT',
633
654
  specification: 'SPECIFICATION'
634
655
  };
656
+ function attachmentToPropertyValue(attachment) {
657
+ return {
658
+ name: attachment.name,
659
+ value: attachment.content,
660
+ valueReference: VALUE_REFERENCES.attachment
661
+ };
662
+ }
663
+ function getPropertyId(item) {
664
+ return md5(`${item.name}:${JSON.stringify(item.value)}:${item.valueReference}`);
665
+ }
635
666
 
636
667
  const getAttachments = item => {
637
668
  var _item$itemOffered$add;
@@ -639,18 +670,12 @@ const getAttachments = item => {
639
670
  return (_item$itemOffered$add = item.itemOffered.additionalProperty) == null ? void 0 : _item$itemOffered$add.filter(i => i.valueReference === VALUE_REFERENCES.attachment);
640
671
  };
641
672
 
642
- const serializeAttachment = item => {
643
- const attachments = getAttachments(item);
644
-
645
- if ((attachments == null ? void 0 : attachments.length) === 0) {
646
- return null;
647
- }
673
+ const getId = item => {
674
+ var _item$itemOffered$add2;
648
675
 
649
- return attachments == null ? void 0 : attachments.map(attachment => `${attachment.name}:${JSON.stringify(attachment.value)}`).join('-');
676
+ 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('::');
650
677
  };
651
678
 
652
- const getId = item => [item.itemOffered.sku, item.seller.identifier, item.price, serializeAttachment(item)].filter(Boolean).join('::');
653
-
654
679
  const orderFormItemToOffer = (item, index) => ({
655
680
  listPrice: item.listPrice / 100,
656
681
  price: item.sellingPrice / 100,
@@ -661,7 +686,8 @@ const orderFormItemToOffer = (item, index) => ({
661
686
  itemOffered: {
662
687
  sku: item.id,
663
688
  image: [],
664
- name: item.name
689
+ name: item.name,
690
+ additionalProperty: item.attachments.map(attachmentToPropertyValue)
665
691
  },
666
692
  index
667
693
  });
@@ -674,7 +700,7 @@ const offerToOrderItemInput = offer => {
674
700
  seller: offer.seller.identifier,
675
701
  id: offer.itemOffered.sku,
676
702
  index: offer.index,
677
- attachments: (_getAttachments = getAttachments(offer)) == null ? void 0 : _getAttachments.map(attachment => ({
703
+ attachments: ((_getAttachments = getAttachments(offer)) != null ? _getAttachments : []).map(attachment => ({
678
704
  name: attachment.name,
679
705
  content: attachment.value
680
706
  }))
@@ -887,9 +913,6 @@ class ChannelMarshal {
887
913
  }
888
914
 
889
915
  }
890
- const mutateChannelContext = (ctx, channelString) => {
891
- ctx.storage.channel = ChannelMarshal.parse(channelString);
892
- };
893
916
 
894
917
  const updateSession = async (_, {
895
918
  session
@@ -1139,23 +1162,20 @@ const StoreProduct = {
1139
1162
  })).sort(bestOfferFirst),
1140
1163
  isVariantOf: root => root,
1141
1164
  additionalProperty: ({
1142
- variations = [],
1143
- attachmentsValues
1165
+ // Search uses the name variations for specifications
1166
+ variations: specifications = [],
1167
+ attachmentsValues = []
1144
1168
  }) => {
1145
- const propertyValueVariations = variations.flatMap(({
1169
+ const propertyValueSpecifications = specifications.flatMap(({
1146
1170
  name,
1147
1171
  values
1148
1172
  }) => values.map(value => ({
1149
1173
  name,
1150
1174
  value,
1151
- valueReference: VALUE_REFERENCES.variation
1175
+ valueReference: VALUE_REFERENCES.specification
1152
1176
  })));
1153
- const propertyValueAttachments = (attachmentsValues != null ? attachmentsValues : []).map(attachment => ({
1154
- name: attachment.name,
1155
- value: attachment.content,
1156
- valueReference: VALUE_REFERENCES.attachment
1157
- }));
1158
- return [...propertyValueVariations, ...propertyValueAttachments];
1177
+ const propertyValueAttachments = attachmentsValues.map(attachmentToPropertyValue);
1178
+ return [...propertyValueSpecifications, ...propertyValueAttachments];
1159
1179
  }
1160
1180
  };
1161
1181
 
@@ -1186,6 +1206,13 @@ const StoreProductGroup = {
1186
1206
  }))))
1187
1207
  };
1188
1208
 
1209
+ const mutateChannelContext = (ctx, channelString) => {
1210
+ ctx.storage.channel = ChannelMarshal.parse(channelString);
1211
+ };
1212
+ const mutateLocaleContext = (ctx, locale) => {
1213
+ ctx.storage.locale = locale;
1214
+ };
1215
+
1189
1216
  /**
1190
1217
  * Transform facets from the store to VTEX platform facets.
1191
1218
  * For instance, the channel in Store becomes trade-policy and regionId in VTEX's realm
@@ -1214,6 +1241,11 @@ const transformSelectedFacet = ({
1214
1241
  return channelFacets;
1215
1242
  }
1216
1243
 
1244
+ case 'locale':
1245
+ {
1246
+ return []; // remove this facet from search
1247
+ }
1248
+
1217
1249
  default:
1218
1250
  return {
1219
1251
  key,
@@ -1221,6 +1253,16 @@ const transformSelectedFacet = ({
1221
1253
  };
1222
1254
  }
1223
1255
  };
1256
+ const findLocale = facets => {
1257
+ var _facets$find$value, _facets$find;
1258
+
1259
+ 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;
1260
+ };
1261
+ const findChannel = facets => {
1262
+ var _facets$find$value2, _facets$find2;
1263
+
1264
+ 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;
1265
+ };
1224
1266
 
1225
1267
  const SORT_MAP = {
1226
1268
  price_desc: 'price:desc',
@@ -1237,13 +1279,16 @@ const Query = {
1237
1279
  product: async (_, {
1238
1280
  locator
1239
1281
  }, ctx) => {
1240
- var _locator$find;
1241
-
1242
1282
  // Insert channel in context for later usage
1243
- const channelString = (_locator$find = locator.find(facet => facet.key === 'channel')) == null ? void 0 : _locator$find.value;
1283
+ const channel = findChannel(locator);
1284
+ const locale = findLocale(locator);
1285
+
1286
+ if (channel) {
1287
+ mutateChannelContext(ctx, channel);
1288
+ }
1244
1289
 
1245
- if (channelString) {
1246
- mutateChannelContext(ctx, channelString);
1290
+ if (locale) {
1291
+ mutateLocaleContext(ctx, locale);
1247
1292
  }
1248
1293
 
1249
1294
  const {
@@ -1270,13 +1315,18 @@ const Query = {
1270
1315
  term,
1271
1316
  selectedFacets
1272
1317
  }, ctx) => {
1273
- var _selectedFacets$find, _selectedFacets$flatM;
1318
+ var _selectedFacets$flatM;
1274
1319
 
1275
1320
  // Insert channel in context for later usage
1276
- const channelString = selectedFacets == null ? void 0 : (_selectedFacets$find = selectedFacets.find(facet => facet.key === 'channel')) == null ? void 0 : _selectedFacets$find.value;
1321
+ const channel = findChannel(selectedFacets);
1322
+ const locale = findLocale(selectedFacets);
1323
+
1324
+ if (channel) {
1325
+ mutateChannelContext(ctx, channel);
1326
+ }
1277
1327
 
1278
- if (channelString) {
1279
- mutateChannelContext(ctx, channelString);
1328
+ if (locale) {
1329
+ mutateLocaleContext(ctx, locale);
1280
1330
  }
1281
1331
 
1282
1332
  const after = maybeAfter ? Number(maybeAfter) : 0;
@@ -1553,6 +1603,19 @@ function stringify(value) {
1553
1603
  return null;
1554
1604
  }
1555
1605
 
1606
+ const StorePropertyValue = {
1607
+ propertyID: root => getPropertyId(root),
1608
+ name: ({
1609
+ name
1610
+ }) => name,
1611
+ value: ({
1612
+ value
1613
+ }) => value,
1614
+ valueReference: ({
1615
+ valueReference
1616
+ }) => valueReference
1617
+ };
1618
+
1556
1619
  const Resolvers = {
1557
1620
  StoreCollection,
1558
1621
  StoreAggregateOffer,
@@ -1565,6 +1628,7 @@ const Resolvers = {
1565
1628
  StoreReview,
1566
1629
  StoreProductGroup,
1567
1630
  StoreSearchResult,
1631
+ StorePropertyValue,
1568
1632
  ObjectOrString,
1569
1633
  Query,
1570
1634
  Mutation
@@ -1574,7 +1638,8 @@ const getContextFactory = options => ctx => {
1574
1638
 
1575
1639
  ctx.storage = {
1576
1640
  channel: ChannelMarshal.parse(options.channel),
1577
- flags: (_options$flags = options.flags) != null ? _options$flags : {}
1641
+ flags: (_options$flags = options.flags) != null ? _options$flags : {},
1642
+ locale: options.locale
1578
1643
  };
1579
1644
  ctx.clients = getClients(options, ctx);
1580
1645
  ctx.loaders = getLoaders(options, ctx);
@@ -1642,8 +1707,8 @@ var doc$i = {"kind":"Document","definitions":[{"kind":"ObjectTypeDefinition","de
1642
1707
  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}};
1643
1708
  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}};
1644
1709
 
1645
- 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}};
1646
- 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}};
1710
+ 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}};
1711
+ 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}};
1647
1712
 
1648
1713
  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}};
1649
1714
  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}};