@faststore/api 2.1.82 → 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 +14 -65
- 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 +14 -65
- 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 +6 -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";
|
|
@@ -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.
|
|
62
|
-
"@faststore/shared": "^2.1.
|
|
61
|
+
"@faststore/eslint-config": "^2.1.82",
|
|
62
|
+
"@faststore/shared": "^2.1.82",
|
|
63
63
|
"@graphql-codegen/cli": "2.2.0",
|
|
64
64
|
"@graphql-codegen/typescript": "2.2.2",
|
|
65
65
|
"@types/express": "^4.17.16",
|
|
@@ -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 => {
|
|
@@ -1305,7 +1274,10 @@ const joinItems = form => {
|
|
|
1305
1274
|
items: Object.values(itemsById).map(items => {
|
|
1306
1275
|
const [item] = items;
|
|
1307
1276
|
const quantity = items.reduce((acc, i) => acc + i.quantity, 0);
|
|
1308
|
-
const totalPrice = items.reduce((acc, i) =>
|
|
1277
|
+
const totalPrice = items.reduce((acc, i) => {
|
|
1278
|
+
var _i$priceDefinition$to, _i$priceDefinition, _i$quantity, _i$sellingPrice;
|
|
1279
|
+
return acc + ((_i$priceDefinition$to = i == null ? void 0 : (_i$priceDefinition = i.priceDefinition) == null ? void 0 : _i$priceDefinition.total) != null ? _i$priceDefinition$to : ((_i$quantity = i == null ? void 0 : i.quantity) != null ? _i$quantity : 0) * ((_i$sellingPrice = i == null ? void 0 : i.sellingPrice) != null ? _i$sellingPrice : 0));
|
|
1280
|
+
}, 0);
|
|
1309
1281
|
return {
|
|
1310
1282
|
...item,
|
|
1311
1283
|
quantity,
|
|
@@ -1364,17 +1336,6 @@ const isOrderFormStale = form => {
|
|
|
1364
1336
|
const newEtag = getOrderFormEtag(form);
|
|
1365
1337
|
return newEtag !== oldEtag;
|
|
1366
1338
|
};
|
|
1367
|
-
async function getOrderNumberFromSession(headers = {}, commerce) {
|
|
1368
|
-
const cookieSession = getCookie('vtex_session', headers.cookie);
|
|
1369
|
-
if (cookieSession) {
|
|
1370
|
-
var _namespaces$public$or, _namespaces$public, _namespaces$public$or2;
|
|
1371
|
-
const {
|
|
1372
|
-
namespaces
|
|
1373
|
-
} = await commerce.getSessionOrder();
|
|
1374
|
-
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;
|
|
1375
|
-
}
|
|
1376
|
-
return;
|
|
1377
|
-
}
|
|
1378
1339
|
// Returns the regionalized orderForm
|
|
1379
1340
|
const getOrderForm = async (id, {
|
|
1380
1341
|
clients: {
|
|
@@ -1446,9 +1407,8 @@ const validateCart = async (_, {
|
|
|
1446
1407
|
},
|
|
1447
1408
|
session
|
|
1448
1409
|
}, ctx) => {
|
|
1449
|
-
var _ref;
|
|
1450
1410
|
const {
|
|
1451
|
-
orderNumber
|
|
1411
|
+
orderNumber,
|
|
1452
1412
|
acceptedOffer,
|
|
1453
1413
|
shouldSplitItem
|
|
1454
1414
|
} = order;
|
|
@@ -1458,8 +1418,7 @@ const validateCart = async (_, {
|
|
|
1458
1418
|
},
|
|
1459
1419
|
loaders: {
|
|
1460
1420
|
skuLoader
|
|
1461
|
-
}
|
|
1462
|
-
headers
|
|
1421
|
+
}
|
|
1463
1422
|
} = ctx;
|
|
1464
1423
|
const channel = session == null ? void 0 : session.channel;
|
|
1465
1424
|
const locale = session == null ? void 0 : session.locale;
|
|
@@ -1469,19 +1428,9 @@ const validateCart = async (_, {
|
|
|
1469
1428
|
if (locale) {
|
|
1470
1429
|
mutateLocaleContext(ctx, locale);
|
|
1471
1430
|
}
|
|
1472
|
-
const orderNumberFromSession = await getOrderNumberFromSession(headers, commerce);
|
|
1473
|
-
const orderNumber = (_ref = orderNumberFromSession != null ? orderNumberFromSession : orderNumberFromCart) != null ? _ref : '';
|
|
1474
1431
|
// Step1: Get OrderForm from VTEX Commerce
|
|
1475
1432
|
const orderForm = await getOrderForm(orderNumber, ctx);
|
|
1476
|
-
// Step1.
|
|
1477
|
-
// Social Selling: the vtex_session cookie contains a new orderForm id with Social Selling data
|
|
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.
|
|
1479
|
-
// New session: a new user enters the website and has no orderForm attributed to it (has no relation to the vtex_session cookie).
|
|
1480
|
-
// In all cases, the origin orderForm should replace the copy that's in the browser
|
|
1481
|
-
if (orderForm.orderFormId != orderNumberFromCart) {
|
|
1482
|
-
return orderFormToCart(orderForm, skuLoader);
|
|
1483
|
-
}
|
|
1484
|
-
// 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
|
|
1485
1434
|
// If so, this means the user interacted with this cart elsewhere and expects
|
|
1486
1435
|
// to see this new cart state instead of what's stored on the user's browser.
|
|
1487
1436
|
const isStale = isOrderFormStale(orderForm);
|