@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.cjs.development.js +8 -62
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +8 -62
- package/dist/api.esm.js.map +1 -1
- package/dist/platforms/vtex/clients/commerce/index.d.ts +0 -1
- package/dist/platforms/vtex/clients/index.d.ts +0 -1
- package/package.json +2 -2
- package/src/platforms/vtex/clients/commerce/index.ts +4 -26
- package/src/platforms/vtex/resolvers/validateCart.ts +4 -37
- package/dist/platforms/vtex/utils/getCookies.d.ts +0 -1
- package/src/platforms/vtex/utils/getCookies.ts +0 -8
|
@@ -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.
|
|
25
|
+
var version = "2.1.83";
|
|
26
26
|
var license = "MIT";
|
|
27
27
|
var main = "dist/index.js";
|
|
28
28
|
var typings = "dist/index.d.ts";
|
|
@@ -111,16 +111,6 @@ const fetchAPI = async (info, init) => {
|
|
|
111
111
|
throw new Error(text);
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
const getCookie = (name, cookie) => {
|
|
115
|
-
const value = `; ${cookie}`;
|
|
116
|
-
const parts = value.split(`; ${name}=`);
|
|
117
|
-
if (parts.length === 2) {
|
|
118
|
-
var _parts$pop$split$shif, _parts$pop;
|
|
119
|
-
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 : '';
|
|
120
|
-
}
|
|
121
|
-
return '';
|
|
122
|
-
};
|
|
123
|
-
|
|
124
114
|
const BASE_INIT = {
|
|
125
115
|
method: 'POST',
|
|
126
116
|
headers: {
|
|
@@ -275,34 +265,13 @@ const VtexCommerce = ({
|
|
|
275
265
|
session: search => {
|
|
276
266
|
const params = new URLSearchParams(search);
|
|
277
267
|
params.set('items', 'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol');
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
281
|
-
method: 'GET',
|
|
282
|
-
headers: {
|
|
283
|
-
'content-type': 'application/json',
|
|
284
|
-
cookie: ctx.headers.cookie
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
} else {
|
|
288
|
-
// cookie unset -> create session
|
|
289
|
-
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
290
|
-
method: 'POST',
|
|
291
|
-
headers: {
|
|
292
|
-
'content-type': 'application/json',
|
|
293
|
-
cookie: ctx.headers.cookie
|
|
294
|
-
},
|
|
295
|
-
body: '{}'
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
},
|
|
299
|
-
getSessionOrder: () => {
|
|
300
|
-
return fetchAPI(`${base}/api/sessions?items=public.orderFormId`, {
|
|
301
|
-
method: 'GET',
|
|
268
|
+
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
269
|
+
method: 'POST',
|
|
302
270
|
headers: {
|
|
303
271
|
'content-type': 'application/json',
|
|
304
272
|
cookie: ctx.headers.cookie
|
|
305
|
-
}
|
|
273
|
+
},
|
|
274
|
+
body: '{}'
|
|
306
275
|
});
|
|
307
276
|
},
|
|
308
277
|
subscribeToNewsletter: data => {
|
|
@@ -1367,17 +1336,6 @@ const isOrderFormStale = form => {
|
|
|
1367
1336
|
const newEtag = getOrderFormEtag(form);
|
|
1368
1337
|
return newEtag !== oldEtag;
|
|
1369
1338
|
};
|
|
1370
|
-
async function getOrderNumberFromSession(headers = {}, commerce) {
|
|
1371
|
-
const cookieSession = getCookie('vtex_session', headers.cookie);
|
|
1372
|
-
if (cookieSession) {
|
|
1373
|
-
var _namespaces$public$or, _namespaces$public, _namespaces$public$or2;
|
|
1374
|
-
const {
|
|
1375
|
-
namespaces
|
|
1376
|
-
} = await commerce.getSessionOrder();
|
|
1377
|
-
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;
|
|
1378
|
-
}
|
|
1379
|
-
return;
|
|
1380
|
-
}
|
|
1381
1339
|
// Returns the regionalized orderForm
|
|
1382
1340
|
const getOrderForm = async (id, {
|
|
1383
1341
|
clients: {
|
|
@@ -1449,9 +1407,8 @@ const validateCart = async (_, {
|
|
|
1449
1407
|
},
|
|
1450
1408
|
session
|
|
1451
1409
|
}, ctx) => {
|
|
1452
|
-
var _ref;
|
|
1453
1410
|
const {
|
|
1454
|
-
orderNumber
|
|
1411
|
+
orderNumber,
|
|
1455
1412
|
acceptedOffer,
|
|
1456
1413
|
shouldSplitItem
|
|
1457
1414
|
} = order;
|
|
@@ -1461,8 +1418,7 @@ const validateCart = async (_, {
|
|
|
1461
1418
|
},
|
|
1462
1419
|
loaders: {
|
|
1463
1420
|
skuLoader
|
|
1464
|
-
}
|
|
1465
|
-
headers
|
|
1421
|
+
}
|
|
1466
1422
|
} = ctx;
|
|
1467
1423
|
const channel = session == null ? void 0 : session.channel;
|
|
1468
1424
|
const locale = session == null ? void 0 : session.locale;
|
|
@@ -1472,19 +1428,9 @@ const validateCart = async (_, {
|
|
|
1472
1428
|
if (locale) {
|
|
1473
1429
|
mutateLocaleContext(ctx, locale);
|
|
1474
1430
|
}
|
|
1475
|
-
const orderNumberFromSession = await getOrderNumberFromSession(headers, commerce);
|
|
1476
|
-
const orderNumber = (_ref = orderNumberFromSession != null ? orderNumberFromSession : orderNumberFromCart) != null ? _ref : '';
|
|
1477
1431
|
// Step1: Get OrderForm from VTEX Commerce
|
|
1478
1432
|
const orderForm = await getOrderForm(orderNumber, ctx);
|
|
1479
|
-
// Step1.
|
|
1480
|
-
// Social Selling: the vtex_session cookie contains a new orderForm id with Social Selling data
|
|
1481
|
-
// 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.
|
|
1482
|
-
// New session: a new user enters the website and has no orderForm attributed to it (has no relation to the vtex_session cookie).
|
|
1483
|
-
// In all cases, the origin orderForm should replace the copy that's in the browser
|
|
1484
|
-
if (orderForm.orderFormId != orderNumberFromCart) {
|
|
1485
|
-
return orderFormToCart(orderForm, skuLoader);
|
|
1486
|
-
}
|
|
1487
|
-
// Step1.2: Check if another system changed the orderForm with this orderNumber
|
|
1433
|
+
// Step1.5: Check if another system changed the orderForm with this orderNumber
|
|
1488
1434
|
// If so, this means the user interacted with this cart elsewhere and expects
|
|
1489
1435
|
// to see this new cart state instead of what's stored on the user's browser.
|
|
1490
1436
|
const isStale = isOrderFormStale(orderForm);
|