@faststore/api 1.12.47 → 1.12.50
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/README.md +1 -1
- package/dist/api.cjs.development.js +43 -40
- 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 +43 -40
- package/dist/api.esm.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/platforms/vtex/clients/fetch.d.ts +1 -1
- package/dist/platforms/vtex/clients/index.d.ts +3 -3
- package/dist/platforms/vtex/clients/search/index.d.ts +2 -0
- package/dist/platforms/vtex/index.d.ts +2 -3
- package/dist/platforms/vtex/resolvers/query.d.ts +1 -1
- package/dist/platforms/vtex/utils/facets.d.ts +1 -0
- package/package.json +3 -3
- package/src/platforms/vtex/clients/commerce/index.ts +11 -32
- package/src/platforms/vtex/clients/fetch.ts +1 -9
- package/src/platforms/vtex/clients/search/index.ts +15 -6
- package/src/platforms/vtex/index.ts +0 -1
- package/src/platforms/vtex/loaders/sku.ts +5 -1
- package/src/platforms/vtex/resolvers/query.ts +3 -0
- package/src/platforms/vtex/resolvers/searchResult.ts +7 -5
- package/src/platforms/vtex/resolvers/validateCart.ts +1 -1
- package/src/platforms/vtex/utils/facets.ts +3 -0
- package/src/platforms/vtex/utils/sku.ts +1 -1
- package/dist/utils/get-cookie-by-name.d.ts +0 -1
- package/src/utils/get-cookie-by-name.ts +0 -6
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.49";
|
|
22
22
|
var license = "MIT";
|
|
23
23
|
var main = "dist/index.js";
|
|
24
24
|
var typings = "dist/index.d.ts";
|
|
@@ -54,7 +54,7 @@ var dependencies = {
|
|
|
54
54
|
};
|
|
55
55
|
var devDependencies = {
|
|
56
56
|
"@envelop/core": "^2.6.0",
|
|
57
|
-
"@faststore/shared": "^1.12.
|
|
57
|
+
"@faststore/shared": "^1.12.48",
|
|
58
58
|
"@graphql-codegen/cli": "2.2.0",
|
|
59
59
|
"@graphql-codegen/typescript": "2.2.2",
|
|
60
60
|
concurrently: "^6.2.1",
|
|
@@ -88,7 +88,7 @@ var packageJson = {
|
|
|
88
88
|
};
|
|
89
89
|
|
|
90
90
|
const USER_AGENT = `${packageJson.name}@${packageJson.version}`;
|
|
91
|
-
const fetchAPI = async (info, init
|
|
91
|
+
const fetchAPI = async (info, init) => {
|
|
92
92
|
const response = await fetch(info, { ...init,
|
|
93
93
|
headers: { ...(init == null ? void 0 : init.headers),
|
|
94
94
|
'User-Agent': USER_AGENT
|
|
@@ -96,10 +96,6 @@ const fetchAPI = async (info, init, getHeaders) => {
|
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
if (response.ok) {
|
|
99
|
-
if (getHeaders) {
|
|
100
|
-
getHeaders(response.headers);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
99
|
return response.status !== 204 ? response.json() : undefined;
|
|
104
100
|
}
|
|
105
101
|
|
|
@@ -108,26 +104,12 @@ const fetchAPI = async (info, init, getHeaders) => {
|
|
|
108
104
|
throw new Error(text);
|
|
109
105
|
};
|
|
110
106
|
|
|
111
|
-
function getCookieByName(cookiename, source) {
|
|
112
|
-
var cookiestring = RegExp(cookiename + '=[^;]+').exec(source);
|
|
113
|
-
return decodeURIComponent(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./, '') : '');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
107
|
const BASE_INIT = {
|
|
117
108
|
method: 'POST',
|
|
118
109
|
headers: {
|
|
119
110
|
'content-type': 'application/json'
|
|
120
111
|
}
|
|
121
112
|
};
|
|
122
|
-
|
|
123
|
-
const setCheckoutOrderFormOwnershipCookie = (headers, ctx) => {
|
|
124
|
-
if (headers) {
|
|
125
|
-
var _headers$get;
|
|
126
|
-
|
|
127
|
-
ctx.storage.cookies = `CheckoutOrderFormOwnership=${getCookieByName('CheckoutOrderFormOwnership', (_headers$get = headers.get('set-cookie')) != null ? _headers$get : '')}`;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
113
|
const VtexCommerce = ({
|
|
132
114
|
account,
|
|
133
115
|
environment
|
|
@@ -184,7 +166,7 @@ const VtexCommerce = ({
|
|
|
184
166
|
|
|
185
167
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, { ...BASE_INIT,
|
|
186
168
|
body: JSON.stringify(body)
|
|
187
|
-
}
|
|
169
|
+
});
|
|
188
170
|
},
|
|
189
171
|
orderForm: ({
|
|
190
172
|
id,
|
|
@@ -198,7 +180,7 @@ const VtexCommerce = ({
|
|
|
198
180
|
refreshOutdatedData: refreshOutdatedData.toString(),
|
|
199
181
|
sc: salesChannel
|
|
200
182
|
});
|
|
201
|
-
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT
|
|
183
|
+
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT);
|
|
202
184
|
},
|
|
203
185
|
updateOrderFormItems: ({
|
|
204
186
|
id,
|
|
@@ -217,7 +199,7 @@ const VtexCommerce = ({
|
|
|
217
199
|
noSplitItem: !shouldSplitItem
|
|
218
200
|
}),
|
|
219
201
|
method: 'PATCH'
|
|
220
|
-
}
|
|
202
|
+
});
|
|
221
203
|
},
|
|
222
204
|
setCustomData: ({
|
|
223
205
|
id,
|
|
@@ -230,7 +212,7 @@ const VtexCommerce = ({
|
|
|
230
212
|
value
|
|
231
213
|
}),
|
|
232
214
|
method: 'PUT'
|
|
233
|
-
}
|
|
215
|
+
});
|
|
234
216
|
},
|
|
235
217
|
region: async ({
|
|
236
218
|
postalCode,
|
|
@@ -256,7 +238,7 @@ const VtexCommerce = ({
|
|
|
256
238
|
cookie: ctx.headers.cookie
|
|
257
239
|
},
|
|
258
240
|
body: '{}'
|
|
259
|
-
}
|
|
241
|
+
});
|
|
260
242
|
},
|
|
261
243
|
subscribeToNewsletter: data => {
|
|
262
244
|
return fetchAPI(`${base}/api/dataentities/NL/documents/`, { ...BASE_INIT,
|
|
@@ -294,22 +276,23 @@ const IntelligentSearch = ({
|
|
|
294
276
|
};
|
|
295
277
|
};
|
|
296
278
|
|
|
297
|
-
const getRegionFacet =
|
|
279
|
+
const getRegionFacet = regionIdFromQuery => {
|
|
298
280
|
const {
|
|
299
281
|
regionId
|
|
300
282
|
} = ctx.storage.channel;
|
|
283
|
+
const facet = regionIdFromQuery != null ? regionIdFromQuery : regionId;
|
|
301
284
|
|
|
302
|
-
if (!
|
|
285
|
+
if (!facet) {
|
|
303
286
|
return null;
|
|
304
287
|
}
|
|
305
288
|
|
|
306
289
|
return {
|
|
307
290
|
key: REGION_KEY,
|
|
308
|
-
value:
|
|
291
|
+
value: facet
|
|
309
292
|
};
|
|
310
293
|
};
|
|
311
294
|
|
|
312
|
-
const addDefaultFacets = facets => {
|
|
295
|
+
const addDefaultFacets = (facets, regionIdFromQuery) => {
|
|
313
296
|
var _facets$find, _facets$find2;
|
|
314
297
|
|
|
315
298
|
const withDefaltFacets = facets.filter(({
|
|
@@ -320,7 +303,7 @@ const IntelligentSearch = ({
|
|
|
320
303
|
}) => key === POLICY_KEY)) != null ? _facets$find : getPolicyFacet();
|
|
321
304
|
const regionFacet = (_facets$find2 = facets.find(({
|
|
322
305
|
key
|
|
323
|
-
}) => key === REGION_KEY)) != null ? _facets$find2 : getRegionFacet();
|
|
306
|
+
}) => key === REGION_KEY)) != null ? _facets$find2 : getRegionFacet(regionIdFromQuery);
|
|
324
307
|
|
|
325
308
|
if (policyFacet !== null) {
|
|
326
309
|
withDefaltFacets.push(policyFacet);
|
|
@@ -340,7 +323,9 @@ const IntelligentSearch = ({
|
|
|
340
323
|
sort = '',
|
|
341
324
|
selectedFacets = [],
|
|
342
325
|
type,
|
|
343
|
-
fuzzy = 'auto'
|
|
326
|
+
fuzzy = 'auto',
|
|
327
|
+
showInvisibleItems,
|
|
328
|
+
regionId
|
|
344
329
|
}) => {
|
|
345
330
|
const params = new URLSearchParams({
|
|
346
331
|
page: (page + 1).toString(),
|
|
@@ -351,11 +336,15 @@ const IntelligentSearch = ({
|
|
|
351
336
|
locale: ctx.storage.locale
|
|
352
337
|
});
|
|
353
338
|
|
|
339
|
+
if (showInvisibleItems) {
|
|
340
|
+
params.append('show-invisible-items', 'true');
|
|
341
|
+
}
|
|
342
|
+
|
|
354
343
|
if (hideUnavailableItems !== undefined) {
|
|
355
344
|
params.append('hideUnavailableItems', hideUnavailableItems.toString());
|
|
356
345
|
}
|
|
357
346
|
|
|
358
|
-
const pathname = addDefaultFacets(selectedFacets).map(({
|
|
347
|
+
const pathname = addDefaultFacets(selectedFacets, regionId).map(({
|
|
359
348
|
key,
|
|
360
349
|
value
|
|
361
350
|
}) => `${key}/${value}`).join('/');
|
|
@@ -548,13 +537,16 @@ const isBadRequestError = error => {
|
|
|
548
537
|
};
|
|
549
538
|
|
|
550
539
|
const getSkuLoader = (_, clients) => {
|
|
551
|
-
const loader = async
|
|
540
|
+
const loader = async keys => {
|
|
541
|
+
const skuIds = keys.map(key => key.split('-')[0]);
|
|
542
|
+
const showInvisibleItems = keys.some(key => key.split('-')[1] === 'invisibleItems');
|
|
552
543
|
const {
|
|
553
544
|
products
|
|
554
545
|
} = await clients.search.products({
|
|
555
546
|
query: `sku:${skuIds.join(';')}`,
|
|
556
547
|
page: 0,
|
|
557
|
-
count: skuIds.length
|
|
548
|
+
count: skuIds.length,
|
|
549
|
+
showInvisibleItems
|
|
558
550
|
});
|
|
559
551
|
const skuBySkuId = products.reduce((acc, product) => {
|
|
560
552
|
for (const sku of product.items) {
|
|
@@ -934,6 +926,11 @@ const findChannel = facets => {
|
|
|
934
926
|
|
|
935
927
|
return (_facets$find$value4 = facets == null ? void 0 : (_facets$find4 = facets.find(facet => facet.key === 'channel')) == null ? void 0 : _facets$find4.value) != null ? _facets$find$value4 : null;
|
|
936
928
|
};
|
|
929
|
+
const findRegionId = facets => {
|
|
930
|
+
var _facets$find$value5, _facets$find5;
|
|
931
|
+
|
|
932
|
+
return (_facets$find$value5 = facets == null ? void 0 : (_facets$find5 = facets.find(facet => facet.key === 'regionId')) == null ? void 0 : _facets$find5.value) != null ? _facets$find$value5 : undefined;
|
|
933
|
+
};
|
|
937
934
|
|
|
938
935
|
/**
|
|
939
936
|
* More info at: https://en.wikipedia.org/wiki/Order_statistic
|
|
@@ -1172,7 +1169,7 @@ const orderFormToCart = async (form, skuLoader) => {
|
|
|
1172
1169
|
order: {
|
|
1173
1170
|
orderNumber: form.orderFormId,
|
|
1174
1171
|
acceptedOffer: form.items.map(async item => ({ ...item,
|
|
1175
|
-
product: await skuLoader.load(item.id)
|
|
1172
|
+
product: await skuLoader.load(`${item.id}-invisibleItems`)
|
|
1176
1173
|
}))
|
|
1177
1174
|
},
|
|
1178
1175
|
messages: form.messages.map(({
|
|
@@ -1800,7 +1797,7 @@ const pickBestSku = skus => {
|
|
|
1800
1797
|
}, {
|
|
1801
1798
|
offer: o2
|
|
1802
1799
|
}) => bestOfferFirst(o1, o2));
|
|
1803
|
-
return best.sku;
|
|
1800
|
+
return best ? best.sku : skus[0];
|
|
1804
1801
|
};
|
|
1805
1802
|
const isValidSkuId = skuId => skuId !== '' && !Number.isNaN(Number(skuId));
|
|
1806
1803
|
|
|
@@ -1811,6 +1808,7 @@ const Query = {
|
|
|
1811
1808
|
// Insert channel in context for later usage
|
|
1812
1809
|
const channel = findChannel(locator);
|
|
1813
1810
|
const locale = findLocale(locator);
|
|
1811
|
+
const regionId = findRegionId(locator);
|
|
1814
1812
|
const id = findSkuId(locator);
|
|
1815
1813
|
const slug = findSlug(locator);
|
|
1816
1814
|
|
|
@@ -1871,7 +1869,8 @@ const Query = {
|
|
|
1871
1869
|
} = await search.products({
|
|
1872
1870
|
page: 0,
|
|
1873
1871
|
count: 1,
|
|
1874
|
-
query: `product:${route.id}
|
|
1872
|
+
query: `product:${route.id}`,
|
|
1873
|
+
regionId
|
|
1875
1874
|
});
|
|
1876
1875
|
|
|
1877
1876
|
if (!product) {
|
|
@@ -2113,7 +2112,9 @@ const StoreSearchResult = {
|
|
|
2113
2112
|
} = root;
|
|
2114
2113
|
const [terms, productSearchResult] = await Promise.all([search.suggestedTerms(searchArgs), productSearchPromise]);
|
|
2115
2114
|
const skus = productSearchResult.products.map(product => {
|
|
2116
|
-
|
|
2115
|
+
// What determines the presentation of the SKU is the price order
|
|
2116
|
+
// https://help.vtex.com/pt/tutorial/ordenando-imagens-na-vitrine-e-na-pagina-de-produto--tutorials_278
|
|
2117
|
+
const maybeSku = pickBestSku(product.items);
|
|
2117
2118
|
return maybeSku && enhanceSku(maybeSku, product);
|
|
2118
2119
|
}).filter(sku => !!sku);
|
|
2119
2120
|
const {
|
|
@@ -2132,7 +2133,9 @@ const StoreSearchResult = {
|
|
|
2132
2133
|
}, _) => {
|
|
2133
2134
|
const productSearchResult = await productSearchPromise;
|
|
2134
2135
|
const skus = productSearchResult.products.map(product => {
|
|
2135
|
-
|
|
2136
|
+
// What determines the presentation of the SKU is the price order
|
|
2137
|
+
// https://help.vtex.com/pt/tutorial/ordenando-imagens-na-vitrine-e-na-pagina-de-produto--tutorials_278
|
|
2138
|
+
const maybeSku = pickBestSku(product.items);
|
|
2136
2139
|
return maybeSku && enhanceSku(maybeSku, product);
|
|
2137
2140
|
}).filter(sku => !!sku);
|
|
2138
2141
|
return {
|