@faststore/api 2.1.53 → 2.1.68

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.
@@ -22,7 +22,7 @@ var api = require('@opentelemetry/api');
22
22
  var apiLogs = require('@opentelemetry/api-logs');
23
23
 
24
24
  var name = "@faststore/api";
25
- var version = "2.1.38";
25
+ var version = "2.1.66";
26
26
  var license = "MIT";
27
27
  var main = "dist/index.js";
28
28
  var typings = "dist/index.d.ts";
@@ -58,8 +58,8 @@ var dependencies = {
58
58
  };
59
59
  var devDependencies = {
60
60
  "@envelop/core": "^2.6.0",
61
- "@faststore/eslint-config": "^2.1.33",
62
- "@faststore/shared": "^2.1.33",
61
+ "@faststore/eslint-config": "^2.1.53",
62
+ "@faststore/shared": "^2.1.53",
63
63
  "@graphql-codegen/cli": "2.2.0",
64
64
  "@graphql-codegen/typescript": "2.2.2",
65
65
  "@types/express": "^4.17.16",
@@ -196,7 +196,11 @@ const VtexCommerce = ({
196
196
  };
197
197
  return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, {
198
198
  ...BASE_INIT,
199
- body: JSON.stringify(mappedBody)
199
+ body: JSON.stringify(mappedBody),
200
+ headers: {
201
+ 'content-type': 'application/json',
202
+ cookie: ctx.headers.cookie
203
+ }
200
204
  });
201
205
  },
202
206
  orderForm: ({
@@ -1372,14 +1376,20 @@ async function getOrderNumberFromSession(headers = {}, commerce) {
1372
1376
  return;
1373
1377
  }
1374
1378
  // Returns the regionalized orderForm
1375
- const getOrderForm = async (id, session, {
1379
+ const getOrderForm = async (id, {
1376
1380
  clients: {
1377
1381
  commerce
1378
1382
  }
1379
1383
  }) => {
1380
- const orderForm = await commerce.checkout.orderForm({
1384
+ return commerce.checkout.orderForm({
1381
1385
  id
1382
1386
  });
1387
+ };
1388
+ const updateOrderFormShippingData = async (orderForm, session, {
1389
+ clients: {
1390
+ commerce
1391
+ }
1392
+ }) => {
1383
1393
  // Stores that are not yet providing the session while validating the cart
1384
1394
  // should not be able to update the shipping data
1385
1395
  //
@@ -1462,7 +1472,7 @@ const validateCart = async (_, {
1462
1472
  const orderNumberFromSession = await getOrderNumberFromSession(headers, commerce);
1463
1473
  const orderNumber = (_ref = orderNumberFromSession != null ? orderNumberFromSession : orderNumberFromCart) != null ? _ref : '';
1464
1474
  // Step1: Get OrderForm from VTEX Commerce
1465
- const orderForm = await getOrderForm(orderNumber, session, ctx);
1475
+ const orderForm = await getOrderForm(orderNumber, ctx);
1466
1476
  // Step1.1: Checks if the orderForm id has changed. There are three cases for this:
1467
1477
  // Social Selling: the vtex_session cookie contains a new orderForm id with Social Selling data
1468
1478
  // My Orders: the customer clicks on reordering through generating a new cart and when returning to the faststore, this information needs to be returned by vtex_session cookie.
@@ -1529,6 +1539,8 @@ const validateCart = async (_, {
1529
1539
  orderItems: changes,
1530
1540
  shouldSplitItem
1531
1541
  })
1542
+ // update orderForm shippingData
1543
+ .then(form => updateOrderFormShippingData(form, session, ctx))
1532
1544
  // update orderForm etag so we know last time we touched this orderForm
1533
1545
  .then(form => setOrderFormEtag(form, commerce)).then(joinItems);
1534
1546
  // Step5: If no changes detected before/after updating orderForm, the order is validated