@faststore/api 2.2.30 → 2.2.33

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.30";
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.30",
60
+ "@faststore/shared": "^2.2.30",
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