@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.
package/dist/api.esm.js CHANGED
@@ -18,7 +18,7 @@ import { trace, context, SpanKind } from '@opentelemetry/api';
18
18
  import { SeverityNumber } from '@opentelemetry/api-logs';
19
19
 
20
20
  var name = "@faststore/api";
21
- var version = "2.1.38";
21
+ var version = "2.1.66";
22
22
  var license = "MIT";
23
23
  var main = "dist/index.js";
24
24
  var typings = "dist/index.d.ts";
@@ -54,8 +54,8 @@ var dependencies = {
54
54
  };
55
55
  var devDependencies = {
56
56
  "@envelop/core": "^2.6.0",
57
- "@faststore/eslint-config": "^2.1.33",
58
- "@faststore/shared": "^2.1.33",
57
+ "@faststore/eslint-config": "^2.1.53",
58
+ "@faststore/shared": "^2.1.53",
59
59
  "@graphql-codegen/cli": "2.2.0",
60
60
  "@graphql-codegen/typescript": "2.2.2",
61
61
  "@types/express": "^4.17.16",
@@ -192,7 +192,11 @@ const VtexCommerce = ({
192
192
  };
193
193
  return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, {
194
194
  ...BASE_INIT,
195
- body: JSON.stringify(mappedBody)
195
+ body: JSON.stringify(mappedBody),
196
+ headers: {
197
+ 'content-type': 'application/json',
198
+ cookie: ctx.headers.cookie
199
+ }
196
200
  });
197
201
  },
198
202
  orderForm: ({
@@ -1368,14 +1372,20 @@ async function getOrderNumberFromSession(headers = {}, commerce) {
1368
1372
  return;
1369
1373
  }
1370
1374
  // Returns the regionalized orderForm
1371
- const getOrderForm = async (id, session, {
1375
+ const getOrderForm = async (id, {
1372
1376
  clients: {
1373
1377
  commerce
1374
1378
  }
1375
1379
  }) => {
1376
- const orderForm = await commerce.checkout.orderForm({
1380
+ return commerce.checkout.orderForm({
1377
1381
  id
1378
1382
  });
1383
+ };
1384
+ const updateOrderFormShippingData = async (orderForm, session, {
1385
+ clients: {
1386
+ commerce
1387
+ }
1388
+ }) => {
1379
1389
  // Stores that are not yet providing the session while validating the cart
1380
1390
  // should not be able to update the shipping data
1381
1391
  //
@@ -1458,7 +1468,7 @@ const validateCart = async (_, {
1458
1468
  const orderNumberFromSession = await getOrderNumberFromSession(headers, commerce);
1459
1469
  const orderNumber = (_ref = orderNumberFromSession != null ? orderNumberFromSession : orderNumberFromCart) != null ? _ref : '';
1460
1470
  // Step1: Get OrderForm from VTEX Commerce
1461
- const orderForm = await getOrderForm(orderNumber, session, ctx);
1471
+ const orderForm = await getOrderForm(orderNumber, ctx);
1462
1472
  // Step1.1: Checks if the orderForm id has changed. There are three cases for this:
1463
1473
  // Social Selling: the vtex_session cookie contains a new orderForm id with Social Selling data
1464
1474
  // 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.
@@ -1525,6 +1535,8 @@ const validateCart = async (_, {
1525
1535
  orderItems: changes,
1526
1536
  shouldSplitItem
1527
1537
  })
1538
+ // update orderForm shippingData
1539
+ .then(form => updateOrderFormShippingData(form, session, ctx))
1528
1540
  // update orderForm etag so we know last time we touched this orderForm
1529
1541
  .then(form => setOrderFormEtag(form, commerce)).then(joinItems);
1530
1542
  // Step5: If no changes detected before/after updating orderForm, the order is validated