@faststore/api 2.1.83 → 2.1.90

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.82";
21
+ var version = "2.1.83";
22
22
  var license = "MIT";
23
23
  var main = "dist/index.js";
24
24
  var typings = "dist/index.d.ts";
@@ -107,16 +107,6 @@ const fetchAPI = async (info, init) => {
107
107
  throw new Error(text);
108
108
  };
109
109
 
110
- const getCookie = (name, cookie) => {
111
- const value = `; ${cookie}`;
112
- const parts = value.split(`; ${name}=`);
113
- if (parts.length === 2) {
114
- var _parts$pop$split$shif, _parts$pop;
115
- return (_parts$pop$split$shif = parts == null ? void 0 : (_parts$pop = parts.pop()) == null ? void 0 : _parts$pop.split(';').shift()) != null ? _parts$pop$split$shif : '';
116
- }
117
- return '';
118
- };
119
-
120
110
  const BASE_INIT = {
121
111
  method: 'POST',
122
112
  headers: {
@@ -271,34 +261,13 @@ const VtexCommerce = ({
271
261
  session: search => {
272
262
  const params = new URLSearchParams(search);
273
263
  params.set('items', 'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol');
274
- if (getCookie('vtex_session', ctx.headers.cookie)) {
275
- // cookie set
276
- return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
277
- method: 'GET',
278
- headers: {
279
- 'content-type': 'application/json',
280
- cookie: ctx.headers.cookie
281
- }
282
- });
283
- } else {
284
- // cookie unset -> create session
285
- return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
286
- method: 'POST',
287
- headers: {
288
- 'content-type': 'application/json',
289
- cookie: ctx.headers.cookie
290
- },
291
- body: '{}'
292
- });
293
- }
294
- },
295
- getSessionOrder: () => {
296
- return fetchAPI(`${base}/api/sessions?items=public.orderFormId`, {
297
- method: 'GET',
264
+ return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
265
+ method: 'POST',
298
266
  headers: {
299
267
  'content-type': 'application/json',
300
268
  cookie: ctx.headers.cookie
301
- }
269
+ },
270
+ body: '{}'
302
271
  });
303
272
  },
304
273
  subscribeToNewsletter: data => {
@@ -1363,17 +1332,6 @@ const isOrderFormStale = form => {
1363
1332
  const newEtag = getOrderFormEtag(form);
1364
1333
  return newEtag !== oldEtag;
1365
1334
  };
1366
- async function getOrderNumberFromSession(headers = {}, commerce) {
1367
- const cookieSession = getCookie('vtex_session', headers.cookie);
1368
- if (cookieSession) {
1369
- var _namespaces$public$or, _namespaces$public, _namespaces$public$or2;
1370
- const {
1371
- namespaces
1372
- } = await commerce.getSessionOrder();
1373
- return (_namespaces$public$or = (_namespaces$public = namespaces.public) == null ? void 0 : (_namespaces$public$or2 = _namespaces$public.orderFormId) == null ? void 0 : _namespaces$public$or2.value) != null ? _namespaces$public$or : undefined;
1374
- }
1375
- return;
1376
- }
1377
1335
  // Returns the regionalized orderForm
1378
1336
  const getOrderForm = async (id, {
1379
1337
  clients: {
@@ -1445,9 +1403,8 @@ const validateCart = async (_, {
1445
1403
  },
1446
1404
  session
1447
1405
  }, ctx) => {
1448
- var _ref;
1449
1406
  const {
1450
- orderNumber: orderNumberFromCart,
1407
+ orderNumber,
1451
1408
  acceptedOffer,
1452
1409
  shouldSplitItem
1453
1410
  } = order;
@@ -1457,8 +1414,7 @@ const validateCart = async (_, {
1457
1414
  },
1458
1415
  loaders: {
1459
1416
  skuLoader
1460
- },
1461
- headers
1417
+ }
1462
1418
  } = ctx;
1463
1419
  const channel = session == null ? void 0 : session.channel;
1464
1420
  const locale = session == null ? void 0 : session.locale;
@@ -1468,19 +1424,9 @@ const validateCart = async (_, {
1468
1424
  if (locale) {
1469
1425
  mutateLocaleContext(ctx, locale);
1470
1426
  }
1471
- const orderNumberFromSession = await getOrderNumberFromSession(headers, commerce);
1472
- const orderNumber = (_ref = orderNumberFromSession != null ? orderNumberFromSession : orderNumberFromCart) != null ? _ref : '';
1473
1427
  // Step1: Get OrderForm from VTEX Commerce
1474
1428
  const orderForm = await getOrderForm(orderNumber, ctx);
1475
- // Step1.1: Checks if the orderForm id has changed. There are three cases for this:
1476
- // Social Selling: the vtex_session cookie contains a new orderForm id with Social Selling data
1477
- // 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.
1478
- // New session: a new user enters the website and has no orderForm attributed to it (has no relation to the vtex_session cookie).
1479
- // In all cases, the origin orderForm should replace the copy that's in the browser
1480
- if (orderForm.orderFormId != orderNumberFromCart) {
1481
- return orderFormToCart(orderForm, skuLoader);
1482
- }
1483
- // Step1.2: Check if another system changed the orderForm with this orderNumber
1429
+ // Step1.5: Check if another system changed the orderForm with this orderNumber
1484
1430
  // If so, this means the user interacted with this cart elsewhere and expects
1485
1431
  // to see this new cart state instead of what's stored on the user's browser.
1486
1432
  const isStale = isOrderFormStale(orderForm);