@faststore/api 1.12.44 → 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 +12 -75
- 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 +12 -75
- 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/dist/platforms/vtex/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/platforms/vtex/clients/commerce/index.ts +7 -28
- package/src/platforms/vtex/index.ts +1 -2
- package/src/platforms/vtex/resolvers/searchResult.ts +8 -14
- 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
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 = "1.12.
|
|
21
|
+
var version = "1.12.45";
|
|
22
22
|
var license = "MIT";
|
|
23
23
|
var main = "dist/index.js";
|
|
24
24
|
var typings = "dist/index.d.ts";
|
|
@@ -104,19 +104,6 @@ const fetchAPI = async (info, init) => {
|
|
|
104
104
|
throw new Error(text);
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
-
const getCookie = (name, cookie) => {
|
|
108
|
-
const value = `; ${cookie}`;
|
|
109
|
-
const parts = value.split(`; ${name}=`);
|
|
110
|
-
|
|
111
|
-
if (parts.length === 2) {
|
|
112
|
-
var _parts$pop$split$shif, _parts$pop;
|
|
113
|
-
|
|
114
|
-
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 : '';
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return '';
|
|
118
|
-
};
|
|
119
|
-
|
|
120
107
|
const BASE_INIT = {
|
|
121
108
|
method: 'POST',
|
|
122
109
|
headers: {
|
|
@@ -244,35 +231,13 @@ const VtexCommerce = ({
|
|
|
244
231
|
session: search => {
|
|
245
232
|
const params = new URLSearchParams(search);
|
|
246
233
|
params.set('items', 'profile.id,profile.email,profile.firstName,profile.lastName,store.channel,store.countryCode,store.cultureInfo,store.currencyCode,store.currencySymbol');
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
// cookie set
|
|
250
|
-
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
251
|
-
method: 'GET',
|
|
252
|
-
headers: {
|
|
253
|
-
'content-type': 'application/json',
|
|
254
|
-
cookie: ctx.headers.cookie
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
} else {
|
|
258
|
-
// cookie unset -> create session
|
|
259
|
-
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
260
|
-
method: 'POST',
|
|
261
|
-
headers: {
|
|
262
|
-
'content-type': 'application/json',
|
|
263
|
-
cookie: ctx.headers.cookie
|
|
264
|
-
},
|
|
265
|
-
body: '{}'
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
getSessionOrder: () => {
|
|
270
|
-
return fetchAPI(`${base}/api/sessions?items=checkout.orderFormId`, {
|
|
271
|
-
method: 'GET',
|
|
234
|
+
return fetchAPI(`${base}/api/sessions?${params.toString()}`, {
|
|
235
|
+
method: 'POST',
|
|
272
236
|
headers: {
|
|
273
237
|
'content-type': 'application/json',
|
|
274
238
|
cookie: ctx.headers.cookie
|
|
275
|
-
}
|
|
239
|
+
},
|
|
240
|
+
body: '{}'
|
|
276
241
|
});
|
|
277
242
|
},
|
|
278
243
|
subscribeToNewsletter: data => {
|
|
@@ -1239,22 +1204,7 @@ const isOrderFormStale = form => {
|
|
|
1239
1204
|
|
|
1240
1205
|
const newEtag = getOrderFormEtag(form);
|
|
1241
1206
|
return newEtag !== oldEtag;
|
|
1242
|
-
};
|
|
1243
|
-
|
|
1244
|
-
async function getOrderNumberFromSession(headers = {}, commerce) {
|
|
1245
|
-
const cookieSession = getCookie('vtex_session', headers.cookie);
|
|
1246
|
-
|
|
1247
|
-
if (cookieSession) {
|
|
1248
|
-
var _namespaces$checkout, _namespaces$checkout$;
|
|
1249
|
-
|
|
1250
|
-
const {
|
|
1251
|
-
namespaces
|
|
1252
|
-
} = await commerce.getSessionOrder();
|
|
1253
|
-
return (_namespaces$checkout = namespaces.checkout) == null ? void 0 : (_namespaces$checkout$ = _namespaces$checkout.orderFormId) == null ? void 0 : _namespaces$checkout$.value;
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
return;
|
|
1257
|
-
} // Returns the regionalized orderForm
|
|
1207
|
+
}; // Returns the regionalized orderForm
|
|
1258
1208
|
|
|
1259
1209
|
|
|
1260
1210
|
const getOrderForm = async (id, session, {
|
|
@@ -1310,10 +1260,8 @@ const validateCart = async (_, {
|
|
|
1310
1260
|
},
|
|
1311
1261
|
session
|
|
1312
1262
|
}, ctx) => {
|
|
1313
|
-
var _ref;
|
|
1314
|
-
|
|
1315
1263
|
const {
|
|
1316
|
-
orderNumber
|
|
1264
|
+
orderNumber,
|
|
1317
1265
|
acceptedOffer,
|
|
1318
1266
|
shouldSplitItem
|
|
1319
1267
|
} = order;
|
|
@@ -1323,8 +1271,7 @@ const validateCart = async (_, {
|
|
|
1323
1271
|
},
|
|
1324
1272
|
loaders: {
|
|
1325
1273
|
skuLoader
|
|
1326
|
-
}
|
|
1327
|
-
headers
|
|
1274
|
+
}
|
|
1328
1275
|
} = ctx;
|
|
1329
1276
|
const channel = session == null ? void 0 : session.channel;
|
|
1330
1277
|
const locale = session == null ? void 0 : session.locale;
|
|
@@ -1335,10 +1282,8 @@ const validateCart = async (_, {
|
|
|
1335
1282
|
|
|
1336
1283
|
if (locale) {
|
|
1337
1284
|
mutateLocaleContext(ctx, locale);
|
|
1338
|
-
}
|
|
1285
|
+
} // Step1: Get OrderForm from VTEX Commerce
|
|
1339
1286
|
|
|
1340
|
-
const orderNumberFromSession = await getOrderNumberFromSession(headers, commerce);
|
|
1341
|
-
const orderNumber = (_ref = orderNumberFromSession != null ? orderNumberFromSession : orderNumberFromCart) != null ? _ref : ''; // Step1: Get OrderForm from VTEX Commerce
|
|
1342
1287
|
|
|
1343
1288
|
const orderForm = await getOrderForm(orderNumber, session, ctx); // Step1.5: Check if another system changed the orderForm with this orderNumber
|
|
1344
1289
|
// If so, this means the user interacted with this cart elsewhere and expects
|
|
@@ -2166,10 +2111,10 @@ const StoreSearchResult = {
|
|
|
2166
2111
|
},
|
|
2167
2112
|
products: async ({
|
|
2168
2113
|
productSearchPromise
|
|
2169
|
-
}, _
|
|
2114
|
+
}, _) => {
|
|
2170
2115
|
const productSearchResult = await productSearchPromise;
|
|
2171
2116
|
const skus = productSearchResult.products.map(product => {
|
|
2172
|
-
const
|
|
2117
|
+
const maybeSku = product.items.find(item => item.sellers.some(item => inStock(item.commertialOffer)));
|
|
2173
2118
|
return maybeSku && enhanceSku(maybeSku, product);
|
|
2174
2119
|
}).filter(sku => !!sku);
|
|
2175
2120
|
return {
|
|
@@ -2180,14 +2125,7 @@ const StoreSearchResult = {
|
|
|
2180
2125
|
endCursor: productSearchResult.recordsFiltered.toString(),
|
|
2181
2126
|
totalCount: productSearchResult.recordsFiltered
|
|
2182
2127
|
},
|
|
2183
|
-
edges: skus.
|
|
2184
|
-
if (ctx.hideUnavailableItems) {
|
|
2185
|
-
return sku.sellers.some(item => inStock(item.commertialOffer));
|
|
2186
|
-
} else {
|
|
2187
|
-
return true;
|
|
2188
|
-
}
|
|
2189
|
-
}) // TODO: remove this filter when the IS returns correctly with hideUnavailableItems
|
|
2190
|
-
.map((sku, index) => ({
|
|
2128
|
+
edges: skus.map((sku, index) => ({
|
|
2191
2129
|
node: sku,
|
|
2192
2130
|
cursor: index.toString()
|
|
2193
2131
|
}))
|
|
@@ -2509,7 +2447,6 @@ const getContextFactory = options => ctx => {
|
|
|
2509
2447
|
};
|
|
2510
2448
|
ctx.clients = getClients(options, ctx);
|
|
2511
2449
|
ctx.loaders = getLoaders(options, ctx);
|
|
2512
|
-
ctx.hideUnavailableItems = options.hideUnavailableItems;
|
|
2513
2450
|
return ctx;
|
|
2514
2451
|
};
|
|
2515
2452
|
const getResolvers = _ => Resolvers;
|