@faststore/api 2.2.22 → 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.
@@ -23,7 +23,7 @@ var api = require('@opentelemetry/api');
23
23
  var apiLogs = require('@opentelemetry/api-logs');
24
24
 
25
25
  var name = "@faststore/api";
26
- var version = "2.2.20";
26
+ var version = "2.2.30";
27
27
  var license = "MIT";
28
28
  var main = "dist/index.js";
29
29
  var typings = "dist/index.d.ts";
@@ -60,8 +60,8 @@ var dependencies = {
60
60
  };
61
61
  var devDependencies = {
62
62
  "@envelop/core": "^2.6.0",
63
- "@faststore/eslint-config": "^2.2.20",
64
- "@faststore/shared": "^2.2.20",
63
+ "@faststore/eslint-config": "^2.2.30",
64
+ "@faststore/shared": "^2.2.30",
65
65
  "@graphql-codegen/cli": "2.2.0",
66
66
  "@graphql-codegen/typescript": "2.2.2",
67
67
  "@types/express": "^4.17.16",
@@ -217,6 +217,14 @@ const VtexCommerce = ({
217
217
  } : BASE_INIT;
218
218
  return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, requestInit);
219
219
  },
220
+ clearOrderFormMessages: ({
221
+ id
222
+ }) => {
223
+ return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/messages/clear`, {
224
+ ...BASE_INIT,
225
+ body: '{}'
226
+ });
227
+ },
220
228
  updateOrderFormItems: ({
221
229
  id,
222
230
  orderItems,
@@ -1329,6 +1337,15 @@ const getOrderForm = async (id, {
1329
1337
  id
1330
1338
  });
1331
1339
  };
1340
+ const clearOrderFormMessages = async (id, {
1341
+ clients: {
1342
+ commerce
1343
+ }
1344
+ }) => {
1345
+ return commerce.checkout.clearOrderFormMessages({
1346
+ id
1347
+ });
1348
+ };
1332
1349
  const updateOrderFormShippingData = async (orderForm, session, {
1333
1350
  clients: {
1334
1351
  commerce
@@ -1413,6 +1430,11 @@ const validateCart = async (_, {
1413
1430
  }
1414
1431
  // Step1: Get OrderForm from VTEX Commerce
1415
1432
  const orderForm = await getOrderForm(orderNumber, ctx);
1433
+ // Clear messages so it doesn't keep populating toasts on a loop
1434
+ // In the next validateCart mutation it will only have messages if a new message is created on orderForm
1435
+ if (orderForm.messages.length !== 0) {
1436
+ await clearOrderFormMessages(orderNumber, ctx);
1437
+ }
1416
1438
  // Step1.5: Check if another system changed the orderForm with this orderNumber
1417
1439
  // If so, this means the user interacted with this cart elsewhere and expects
1418
1440
  // to see this new cart state instead of what's stored on the user's browser.
@@ -1475,8 +1497,9 @@ const validateCart = async (_, {
1475
1497
  .then(form => updateOrderFormShippingData(form, session, ctx))
1476
1498
  // update orderForm etag so we know last time we touched this orderForm
1477
1499
  .then(form => setOrderFormEtag(form, commerce)).then(joinItems);
1500
+ const equalMessages = deepEquals(orderForm.messages, updatedOrderForm.messages);
1478
1501
  // Step5: If no changes detected before/after updating orderForm, the order is validated
1479
- if (equals(order, updatedOrderForm)) {
1502
+ if (equals(order, updatedOrderForm) && equalMessages) {
1480
1503
  return null;
1481
1504
  }
1482
1505
  // Step6: There were changes, convert orderForm to StoreCart