@faststore/api 1.12.45 → 1.12.46
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 +9 -64
- 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 +9 -64
- 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 +7 -28
- package/src/platforms/vtex/resolvers/validateCart.ts +10 -33
- 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 = "1.12.
|
|
25
|
+
var version = "1.12.45";
|
|
26
26
|
var license = "MIT";
|
|
27
27
|
var main = "dist/index.js";
|
|
28
28
|
var typings = "dist/index.d.ts";
|
|
@@ -108,19 +108,6 @@ const fetchAPI = async (info, init) => {
|
|
|
108
108
|
throw new Error(text);
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
const getCookie = (name, cookie) => {
|
|
112
|
-
const value = `; ${cookie}`;
|
|
113
|
-
const parts = value.split(`; ${name}=`);
|
|
114
|
-
|
|
115
|
-
if (parts.length === 2) {
|
|
116
|
-
var _parts$pop$split$shif, _parts$pop;
|
|
117
|
-
|
|
118
|
-
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 : '';
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return '';
|
|
122
|
-
};
|
|
123
|
-
|
|
124
111
|
const BASE_INIT = {
|
|
125
112
|
method: 'POST',
|
|
126
113
|
headers: {
|
|
@@ -248,35 +235,13 @@ const VtexCommerce = ({
|
|
|
248
235
|
session: search => {
|
|
249
236
|
const params = new URLSearchParams(search);
|
|
250
237
|
params.set('items', 'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol');
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
// cookie set
|
|
254
|
-
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
255
|
-
method: 'GET',
|
|
256
|
-
headers: {
|
|
257
|
-
'content-type': 'application/json',
|
|
258
|
-
cookie: ctx.headers.cookie
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
} else {
|
|
262
|
-
// cookie unset -> create session
|
|
263
|
-
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
264
|
-
method: 'POST',
|
|
265
|
-
headers: {
|
|
266
|
-
'content-type': 'application/json',
|
|
267
|
-
cookie: ctx.headers.cookie
|
|
268
|
-
},
|
|
269
|
-
body: '{}'
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
},
|
|
273
|
-
getSessionOrder: () => {
|
|
274
|
-
return fetchAPI(`${base}/api/sessions?items=checkout.orderFormId`, {
|
|
275
|
-
method: 'GET',
|
|
238
|
+
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
239
|
+
method: 'POST',
|
|
276
240
|
headers: {
|
|
277
241
|
'content-type': 'application/json',
|
|
278
242
|
cookie: ctx.headers.cookie
|
|
279
|
-
}
|
|
243
|
+
},
|
|
244
|
+
body: '{}'
|
|
280
245
|
});
|
|
281
246
|
},
|
|
282
247
|
subscribeToNewsletter: data => {
|
|
@@ -1243,22 +1208,7 @@ const isOrderFormStale = form => {
|
|
|
1243
1208
|
|
|
1244
1209
|
const newEtag = getOrderFormEtag(form);
|
|
1245
1210
|
return newEtag !== oldEtag;
|
|
1246
|
-
};
|
|
1247
|
-
|
|
1248
|
-
async function getOrderNumberFromSession(headers = {}, commerce) {
|
|
1249
|
-
const cookieSession = getCookie('vtex_session', headers.cookie);
|
|
1250
|
-
|
|
1251
|
-
if (cookieSession) {
|
|
1252
|
-
var _namespaces$checkout, _namespaces$checkout$;
|
|
1253
|
-
|
|
1254
|
-
const {
|
|
1255
|
-
namespaces
|
|
1256
|
-
} = await commerce.getSessionOrder();
|
|
1257
|
-
return (_namespaces$checkout = namespaces.checkout) == null ? void 0 : (_namespaces$checkout$ = _namespaces$checkout.orderFormId) == null ? void 0 : _namespaces$checkout$.value;
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
return;
|
|
1261
|
-
} // Returns the regionalized orderForm
|
|
1211
|
+
}; // Returns the regionalized orderForm
|
|
1262
1212
|
|
|
1263
1213
|
|
|
1264
1214
|
const getOrderForm = async (id, session, {
|
|
@@ -1314,10 +1264,8 @@ const validateCart = async (_, {
|
|
|
1314
1264
|
},
|
|
1315
1265
|
session
|
|
1316
1266
|
}, ctx) => {
|
|
1317
|
-
var _ref;
|
|
1318
|
-
|
|
1319
1267
|
const {
|
|
1320
|
-
orderNumber
|
|
1268
|
+
orderNumber,
|
|
1321
1269
|
acceptedOffer,
|
|
1322
1270
|
shouldSplitItem
|
|
1323
1271
|
} = order;
|
|
@@ -1327,8 +1275,7 @@ const validateCart = async (_, {
|
|
|
1327
1275
|
},
|
|
1328
1276
|
loaders: {
|
|
1329
1277
|
skuLoader
|
|
1330
|
-
}
|
|
1331
|
-
headers
|
|
1278
|
+
}
|
|
1332
1279
|
} = ctx;
|
|
1333
1280
|
const channel = session == null ? void 0 : session.channel;
|
|
1334
1281
|
const locale = session == null ? void 0 : session.locale;
|
|
@@ -1339,10 +1286,8 @@ const validateCart = async (_, {
|
|
|
1339
1286
|
|
|
1340
1287
|
if (locale) {
|
|
1341
1288
|
mutateLocaleContext(ctx, locale);
|
|
1342
|
-
}
|
|
1289
|
+
} // Step1: Get OrderForm from VTEX Commerce
|
|
1343
1290
|
|
|
1344
|
-
const orderNumberFromSession = await getOrderNumberFromSession(headers, commerce);
|
|
1345
|
-
const orderNumber = (_ref = orderNumberFromSession != null ? orderNumberFromSession : orderNumberFromCart) != null ? _ref : ''; // Step1: Get OrderForm from VTEX Commerce
|
|
1346
1291
|
|
|
1347
1292
|
const orderForm = await getOrderForm(orderNumber, session, ctx); // Step1.5: Check if another system changed the orderForm with this orderNumber
|
|
1348
1293
|
// If so, this means the user interacted with this cart elsewhere and expects
|