@faststore/api 1.10.6 → 1.10.8

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,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.10.8](https://github.com/vtex/faststore/compare/v1.10.7...v1.10.8) (2022-07-07)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add priceCurrency to Offer ([#1399](https://github.com/vtex/faststore/issues/1399)) ([7ca846a](https://github.com/vtex/faststore/commit/7ca846af9b157707c71422b0d7e3e481edfbe5e6))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 1.10.6 (2022-07-05)
7
18
 
8
19
 
@@ -36,6 +36,7 @@ const VtexCommerce = ({
36
36
  const base = `https://${account}.${environment}.com.br`;
37
37
  return {
38
38
  catalog: {
39
+ salesChannel: sc => fetchAPI(`${base}/api/catalog_system/pub/saleschannel/${sc}`),
39
40
  brand: {
40
41
  list: () => fetchAPI(`${base}/api/catalog_system/pub/brand/list`)
41
42
  },
@@ -326,6 +327,12 @@ const getClients = (options, ctx) => {
326
327
  };
327
328
  };
328
329
 
330
+ const getSalesChannelLoader = (_, clients) => {
331
+ const loader = async channels => Promise.all(channels.map(sc => clients.commerce.catalog.salesChannel(sc)));
332
+
333
+ return new DataLoader(loader);
334
+ };
335
+
329
336
  const CONCURRENT_REQUESTS_MAX = 1;
330
337
  const getSimulationLoader = (_, clients) => {
331
338
  const limit = pLimit(CONCURRENT_REQUESTS_MAX);
@@ -463,10 +470,12 @@ const getLoaders = (options, {
463
470
  const skuLoader = getSkuLoader(options, clients);
464
471
  const simulationLoader = getSimulationLoader(options, clients);
465
472
  const collectionLoader = getCollectionLoader(options, clients);
473
+ const salesChannelLoader = getSalesChannelLoader(options, clients);
466
474
  return {
467
475
  skuLoader,
468
476
  simulationLoader,
469
- collectionLoader
477
+ collectionLoader,
478
+ salesChannelLoader
470
479
  };
471
480
  };
472
481
 
@@ -507,7 +516,20 @@ const StoreAggregateOffer = {
507
516
  return lowOffer ? price(lowOffer) : 0;
508
517
  },
509
518
  offerCount: offers => offers.length,
510
- priceCurrency: () => '',
519
+ priceCurrency: async (_, __, ctx) => {
520
+ var _sc$CurrencyCode;
521
+
522
+ const {
523
+ loaders: {
524
+ salesChannelLoader
525
+ },
526
+ storage: {
527
+ channel
528
+ }
529
+ } = ctx;
530
+ const sc = await salesChannelLoader.load(channel.salesChannel);
531
+ return (_sc$CurrencyCode = sc.CurrencyCode) != null ? _sc$CurrencyCode : '';
532
+ },
511
533
  offers: offers => offers
512
534
  };
513
535
 
@@ -1202,7 +1224,20 @@ const isSearchItem = item => 'Price' in item && 'seller' in item && 'product' in
1202
1224
  const isOrderFormItem = item => 'skuName' in item;
1203
1225
 
1204
1226
  const StoreOffer = {
1205
- priceCurrency: () => '',
1227
+ priceCurrency: async (_, __, ctx) => {
1228
+ var _sc$CurrencyCode;
1229
+
1230
+ const {
1231
+ loaders: {
1232
+ salesChannelLoader
1233
+ },
1234
+ storage: {
1235
+ channel
1236
+ }
1237
+ } = ctx;
1238
+ const sc = await salesChannelLoader.load(channel.salesChannel);
1239
+ return (_sc$CurrencyCode = sc.CurrencyCode) != null ? _sc$CurrencyCode : '';
1240
+ },
1206
1241
  priceValidUntil: root => {
1207
1242
  if (isSearchItem(root)) {
1208
1243
  var _root$PriceValidUntil;