@faststore/api 2.2.0-alpha.0 → 2.2.0-alpha.1
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 +4 -4
- 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
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.
|
|
21
|
+
var version = "2.2.0-alpha.0";
|
|
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.
|
|
58
|
-
"@faststore/shared": "^2.
|
|
57
|
+
"@faststore/eslint-config": "^2.2.0-alpha.0",
|
|
58
|
+
"@faststore/shared": "^2.2.0-alpha.0",
|
|
59
59
|
"@graphql-codegen/cli": "2.2.0",
|
|
60
60
|
"@graphql-codegen/typescript": "2.2.2",
|
|
61
61
|
"@types/express": "^4.17.16",
|
|
@@ -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
|
-
|
|
275
|
-
|
|
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 => {
|
|
@@ -1301,7 +1270,10 @@ const joinItems = form => {
|
|
|
1301
1270
|
items: Object.values(itemsById).map(items => {
|
|
1302
1271
|
const [item] = items;
|
|
1303
1272
|
const quantity = items.reduce((acc, i) => acc + i.quantity, 0);
|
|
1304
|
-
const totalPrice = items.reduce((acc, i) =>
|
|
1273
|
+
const totalPrice = items.reduce((acc, i) => {
|
|
1274
|
+
var _i$priceDefinition$to, _i$priceDefinition, _i$quantity, _i$sellingPrice;
|
|
1275
|
+
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));
|
|
1276
|
+
}, 0);
|
|
1305
1277
|
return {
|
|
1306
1278
|
...item,
|
|
1307
1279
|
quantity,
|
|
@@ -1360,17 +1332,6 @@ const isOrderFormStale = form => {
|
|
|
1360
1332
|
const newEtag = getOrderFormEtag(form);
|
|
1361
1333
|
return newEtag !== oldEtag;
|
|
1362
1334
|
};
|
|
1363
|
-
async function getOrderNumberFromSession(headers = {}, commerce) {
|
|
1364
|
-
const cookieSession = getCookie('vtex_session', headers.cookie);
|
|
1365
|
-
if (cookieSession) {
|
|
1366
|
-
var _namespaces$public$or, _namespaces$public, _namespaces$public$or2;
|
|
1367
|
-
const {
|
|
1368
|
-
namespaces
|
|
1369
|
-
} = await commerce.getSessionOrder();
|
|
1370
|
-
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;
|
|
1371
|
-
}
|
|
1372
|
-
return;
|
|
1373
|
-
}
|
|
1374
1335
|
// Returns the regionalized orderForm
|
|
1375
1336
|
const getOrderForm = async (id, {
|
|
1376
1337
|
clients: {
|
|
@@ -1442,9 +1403,8 @@ const validateCart = async (_, {
|
|
|
1442
1403
|
},
|
|
1443
1404
|
session
|
|
1444
1405
|
}, ctx) => {
|
|
1445
|
-
var _ref;
|
|
1446
1406
|
const {
|
|
1447
|
-
orderNumber
|
|
1407
|
+
orderNumber,
|
|
1448
1408
|
acceptedOffer,
|
|
1449
1409
|
shouldSplitItem
|
|
1450
1410
|
} = order;
|
|
@@ -1454,8 +1414,7 @@ const validateCart = async (_, {
|
|
|
1454
1414
|
},
|
|
1455
1415
|
loaders: {
|
|
1456
1416
|
skuLoader
|
|
1457
|
-
}
|
|
1458
|
-
headers
|
|
1417
|
+
}
|
|
1459
1418
|
} = ctx;
|
|
1460
1419
|
const channel = session == null ? void 0 : session.channel;
|
|
1461
1420
|
const locale = session == null ? void 0 : session.locale;
|
|
@@ -1465,19 +1424,9 @@ const validateCart = async (_, {
|
|
|
1465
1424
|
if (locale) {
|
|
1466
1425
|
mutateLocaleContext(ctx, locale);
|
|
1467
1426
|
}
|
|
1468
|
-
const orderNumberFromSession = await getOrderNumberFromSession(headers, commerce);
|
|
1469
|
-
const orderNumber = (_ref = orderNumberFromSession != null ? orderNumberFromSession : orderNumberFromCart) != null ? _ref : '';
|
|
1470
1427
|
// Step1: Get OrderForm from VTEX Commerce
|
|
1471
1428
|
const orderForm = await getOrderForm(orderNumber, ctx);
|
|
1472
|
-
// Step1.
|
|
1473
|
-
// Social Selling: the vtex_session cookie contains a new orderForm id with Social Selling data
|
|
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.
|
|
1475
|
-
// New session: a new user enters the website and has no orderForm attributed to it (has no relation to the vtex_session cookie).
|
|
1476
|
-
// In all cases, the origin orderForm should replace the copy that's in the browser
|
|
1477
|
-
if (orderForm.orderFormId != orderNumberFromCart) {
|
|
1478
|
-
return orderFormToCart(orderForm, skuLoader);
|
|
1479
|
-
}
|
|
1480
|
-
// 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
|
|
1481
1430
|
// If so, this means the user interacted with this cart elsewhere and expects
|
|
1482
1431
|
// to see this new cart state instead of what's stored on the user's browser.
|
|
1483
1432
|
const isStale = isOrderFormStale(orderForm);
|