@faststore/api 2.2.30 → 2.2.35

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
@@ -19,7 +19,7 @@ import { trace, context, SpanKind } from '@opentelemetry/api';
19
19
  import { SeverityNumber } from '@opentelemetry/api-logs';
20
20
 
21
21
  var name = "@faststore/api";
22
- var version = "2.2.22";
22
+ var version = "2.2.33";
23
23
  var license = "MIT";
24
24
  var main = "dist/index.js";
25
25
  var typings = "dist/index.d.ts";
@@ -56,8 +56,8 @@ var dependencies = {
56
56
  };
57
57
  var devDependencies = {
58
58
  "@envelop/core": "^2.6.0",
59
- "@faststore/eslint-config": "^2.2.22",
60
- "@faststore/shared": "^2.2.22",
59
+ "@faststore/eslint-config": "^2.2.33",
60
+ "@faststore/shared": "^2.2.33",
61
61
  "@graphql-codegen/cli": "2.2.0",
62
62
  "@graphql-codegen/typescript": "2.2.2",
63
63
  "@types/express": "^4.17.16",
@@ -213,6 +213,14 @@ const VtexCommerce = ({
213
213
  } : BASE_INIT;
214
214
  return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, requestInit);
215
215
  },
216
+ clearOrderFormMessages: ({
217
+ id
218
+ }) => {
219
+ return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/messages/clear`, {
220
+ ...BASE_INIT,
221
+ body: '{}'
222
+ });
223
+ },
216
224
  updateOrderFormItems: ({
217
225
  id,
218
226
  orderItems,
@@ -1325,6 +1333,15 @@ const getOrderForm = async (id, {
1325
1333
  id
1326
1334
  });
1327
1335
  };
1336
+ const clearOrderFormMessages = async (id, {
1337
+ clients: {
1338
+ commerce
1339
+ }
1340
+ }) => {
1341
+ return commerce.checkout.clearOrderFormMessages({
1342
+ id
1343
+ });
1344
+ };
1328
1345
  const updateOrderFormShippingData = async (orderForm, session, {
1329
1346
  clients: {
1330
1347
  commerce
@@ -1409,6 +1426,11 @@ const validateCart = async (_, {
1409
1426
  }
1410
1427
  // Step1: Get OrderForm from VTEX Commerce
1411
1428
  const orderForm = await getOrderForm(orderNumber, ctx);
1429
+ // Clear messages so it doesn't keep populating toasts on a loop
1430
+ // In the next validateCart mutation it will only have messages if a new message is created on orderForm
1431
+ if (orderForm.messages.length !== 0) {
1432
+ await clearOrderFormMessages(orderNumber, ctx);
1433
+ }
1412
1434
  // Step1.5: Check if another system changed the orderForm with this orderNumber
1413
1435
  // If so, this means the user interacted with this cart elsewhere and expects
1414
1436
  // to see this new cart state instead of what's stored on the user's browser.
@@ -1471,8 +1493,9 @@ const validateCart = async (_, {
1471
1493
  .then(form => updateOrderFormShippingData(form, session, ctx))
1472
1494
  // update orderForm etag so we know last time we touched this orderForm
1473
1495
  .then(form => setOrderFormEtag(form, commerce)).then(joinItems);
1496
+ const equalMessages = deepEquals(orderForm.messages, updatedOrderForm.messages);
1474
1497
  // Step5: If no changes detected before/after updating orderForm, the order is validated
1475
- if (equals(order, updatedOrderForm)) {
1498
+ if (equals(order, updatedOrderForm) && equalMessages) {
1476
1499
  return null;
1477
1500
  }
1478
1501
  // Step6: There were changes, convert orderForm to StoreCart
@@ -2161,7 +2184,7 @@ const StoreReview = {
2161
2184
  })
2162
2185
  };
2163
2186
 
2164
- const isRootFacet = facet => facet.key === 'category-1';
2187
+ const isRootFacet = (facet, isDepartment, isBrand) => isDepartment ? facet.key === 'category-1' : isBrand ? facet.key === 'brand' : false;
2165
2188
  const StoreSearchResult = {
2166
2189
  suggestions: async (root, _, ctx) => {
2167
2190
  const {
@@ -2227,6 +2250,7 @@ const StoreSearchResult = {
2227
2250
  facets: async ({
2228
2251
  searchArgs
2229
2252
  }, _, ctx) => {
2253
+ var _searchArgs$selectedF, _searchArgs$selectedF2;
2230
2254
  const {
2231
2255
  clients: {
2232
2256
  search: is
@@ -2237,9 +2261,12 @@ const StoreSearchResult = {
2237
2261
  facets = []
2238
2262
  } = await is.facets(searchArgs);
2239
2263
  const isCollectionPage = !searchArgs.query;
2264
+ const isDepartment = (_searchArgs$selectedF = searchArgs.selectedFacets) != null && _searchArgs$selectedF.length ? searchArgs.selectedFacets[0].key === 'category-1' : false;
2265
+ const isBrand = (_searchArgs$selectedF2 = searchArgs.selectedFacets) != null && _searchArgs$selectedF2.length ? searchArgs.selectedFacets[0].key === 'brand' : false;
2240
2266
  const filteredFacets = facets
2241
- // Remove root facet on category pages
2242
- .filter(facet => !isCollectionPage || !isRootFacet(facet));
2267
+ // Remove root facet on category and brand pages
2268
+ // TODO: Hide category filters for category pages. E.g. /office/desks
2269
+ .filter(facet => !isCollectionPage || !isRootFacet(facet, isDepartment, isBrand));
2243
2270
  return filteredFacets;
2244
2271
  },
2245
2272
  metadata: async ({