@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/README.md
CHANGED
|
@@ -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.49";
|
|
26
26
|
var license = "MIT";
|
|
27
27
|
var main = "dist/index.js";
|
|
28
28
|
var typings = "dist/index.d.ts";
|
|
@@ -58,7 +58,7 @@ var dependencies = {
|
|
|
58
58
|
};
|
|
59
59
|
var devDependencies = {
|
|
60
60
|
"@envelop/core": "^2.6.0",
|
|
61
|
-
"@faststore/shared": "^1.12.
|
|
61
|
+
"@faststore/shared": "^1.12.48",
|
|
62
62
|
"@graphql-codegen/cli": "2.2.0",
|
|
63
63
|
"@graphql-codegen/typescript": "2.2.2",
|
|
64
64
|
concurrently: "^6.2.1",
|
|
@@ -92,7 +92,7 @@ var packageJson = {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
const USER_AGENT = `${packageJson.name}@${packageJson.version}`;
|
|
95
|
-
const fetchAPI = async (info, init
|
|
95
|
+
const fetchAPI = async (info, init) => {
|
|
96
96
|
const response = await fetch(info, { ...init,
|
|
97
97
|
headers: { ...(init == null ? void 0 : init.headers),
|
|
98
98
|
'User-Agent': USER_AGENT
|
|
@@ -100,10 +100,6 @@ const fetchAPI = async (info, init, getHeaders) => {
|
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
if (response.ok) {
|
|
103
|
-
if (getHeaders) {
|
|
104
|
-
getHeaders(response.headers);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
103
|
return response.status !== 204 ? response.json() : undefined;
|
|
108
104
|
}
|
|
109
105
|
|
|
@@ -112,26 +108,12 @@ const fetchAPI = async (info, init, getHeaders) => {
|
|
|
112
108
|
throw new Error(text);
|
|
113
109
|
};
|
|
114
110
|
|
|
115
|
-
function getCookieByName(cookiename, source) {
|
|
116
|
-
var cookiestring = RegExp(cookiename + '=[^;]+').exec(source);
|
|
117
|
-
return decodeURIComponent(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./, '') : '');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
111
|
const BASE_INIT = {
|
|
121
112
|
method: 'POST',
|
|
122
113
|
headers: {
|
|
123
114
|
'content-type': 'application/json'
|
|
124
115
|
}
|
|
125
116
|
};
|
|
126
|
-
|
|
127
|
-
const setCheckoutOrderFormOwnershipCookie = (headers, ctx) => {
|
|
128
|
-
if (headers) {
|
|
129
|
-
var _headers$get;
|
|
130
|
-
|
|
131
|
-
ctx.storage.cookies = `CheckoutOrderFormOwnership=${getCookieByName('CheckoutOrderFormOwnership', (_headers$get = headers.get('set-cookie')) != null ? _headers$get : '')}`;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
117
|
const VtexCommerce = ({
|
|
136
118
|
account,
|
|
137
119
|
environment
|
|
@@ -188,7 +170,7 @@ const VtexCommerce = ({
|
|
|
188
170
|
|
|
189
171
|
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}/attachments/shippingData`, { ...BASE_INIT,
|
|
190
172
|
body: JSON.stringify(body)
|
|
191
|
-
}
|
|
173
|
+
});
|
|
192
174
|
},
|
|
193
175
|
orderForm: ({
|
|
194
176
|
id,
|
|
@@ -202,7 +184,7 @@ const VtexCommerce = ({
|
|
|
202
184
|
refreshOutdatedData: refreshOutdatedData.toString(),
|
|
203
185
|
sc: salesChannel
|
|
204
186
|
});
|
|
205
|
-
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT
|
|
187
|
+
return fetchAPI(`${base}/api/checkout/pub/orderForm/${id}?${params.toString()}`, BASE_INIT);
|
|
206
188
|
},
|
|
207
189
|
updateOrderFormItems: ({
|
|
208
190
|
id,
|
|
@@ -221,7 +203,7 @@ const VtexCommerce = ({
|
|
|
221
203
|
noSplitItem: !shouldSplitItem
|
|
222
204
|
}),
|
|
223
205
|
method: 'PATCH'
|
|
224
|
-
}
|
|
206
|
+
});
|
|
225
207
|
},
|
|
226
208
|
setCustomData: ({
|
|
227
209
|
id,
|
|
@@ -234,7 +216,7 @@ const VtexCommerce = ({
|
|
|
234
216
|
value
|
|
235
217
|
}),
|
|
236
218
|
method: 'PUT'
|
|
237
|
-
}
|
|
219
|
+
});
|
|
238
220
|
},
|
|
239
221
|
region: async ({
|
|
240
222
|
postalCode,
|
|
@@ -260,7 +242,7 @@ const VtexCommerce = ({
|
|
|
260
242
|
cookie: ctx.headers.cookie
|
|
261
243
|
},
|
|
262
244
|
body: '{}'
|
|
263
|
-
}
|
|
245
|
+
});
|
|
264
246
|
},
|
|
265
247
|
subscribeToNewsletter: data => {
|
|
266
248
|
return fetchAPI(`${base}/api/dataentities/NL/documents/`, { ...BASE_INIT,
|
|
@@ -298,22 +280,23 @@ const IntelligentSearch = ({
|
|
|
298
280
|
};
|
|
299
281
|
};
|
|
300
282
|
|
|
301
|
-
const getRegionFacet =
|
|
283
|
+
const getRegionFacet = regionIdFromQuery => {
|
|
302
284
|
const {
|
|
303
285
|
regionId
|
|
304
286
|
} = ctx.storage.channel;
|
|
287
|
+
const facet = regionIdFromQuery != null ? regionIdFromQuery : regionId;
|
|
305
288
|
|
|
306
|
-
if (!
|
|
289
|
+
if (!facet) {
|
|
307
290
|
return null;
|
|
308
291
|
}
|
|
309
292
|
|
|
310
293
|
return {
|
|
311
294
|
key: REGION_KEY,
|
|
312
|
-
value:
|
|
295
|
+
value: facet
|
|
313
296
|
};
|
|
314
297
|
};
|
|
315
298
|
|
|
316
|
-
const addDefaultFacets = facets => {
|
|
299
|
+
const addDefaultFacets = (facets, regionIdFromQuery) => {
|
|
317
300
|
var _facets$find, _facets$find2;
|
|
318
301
|
|
|
319
302
|
const withDefaltFacets = facets.filter(({
|
|
@@ -324,7 +307,7 @@ const IntelligentSearch = ({
|
|
|
324
307
|
}) => key === POLICY_KEY)) != null ? _facets$find : getPolicyFacet();
|
|
325
308
|
const regionFacet = (_facets$find2 = facets.find(({
|
|
326
309
|
key
|
|
327
|
-
}) => key === REGION_KEY)) != null ? _facets$find2 : getRegionFacet();
|
|
310
|
+
}) => key === REGION_KEY)) != null ? _facets$find2 : getRegionFacet(regionIdFromQuery);
|
|
328
311
|
|
|
329
312
|
if (policyFacet !== null) {
|
|
330
313
|
withDefaltFacets.push(policyFacet);
|
|
@@ -344,7 +327,9 @@ const IntelligentSearch = ({
|
|
|
344
327
|
sort = '',
|
|
345
328
|
selectedFacets = [],
|
|
346
329
|
type,
|
|
347
|
-
fuzzy = 'auto'
|
|
330
|
+
fuzzy = 'auto',
|
|
331
|
+
showInvisibleItems,
|
|
332
|
+
regionId
|
|
348
333
|
}) => {
|
|
349
334
|
const params = new URLSearchParams({
|
|
350
335
|
page: (page + 1).toString(),
|
|
@@ -355,11 +340,15 @@ const IntelligentSearch = ({
|
|
|
355
340
|
locale: ctx.storage.locale
|
|
356
341
|
});
|
|
357
342
|
|
|
343
|
+
if (showInvisibleItems) {
|
|
344
|
+
params.append('show-invisible-items', 'true');
|
|
345
|
+
}
|
|
346
|
+
|
|
358
347
|
if (hideUnavailableItems !== undefined) {
|
|
359
348
|
params.append('hideUnavailableItems', hideUnavailableItems.toString());
|
|
360
349
|
}
|
|
361
350
|
|
|
362
|
-
const pathname = addDefaultFacets(selectedFacets).map(({
|
|
351
|
+
const pathname = addDefaultFacets(selectedFacets, regionId).map(({
|
|
363
352
|
key,
|
|
364
353
|
value
|
|
365
354
|
}) => `${key}/${value}`).join('/');
|
|
@@ -552,13 +541,16 @@ const isBadRequestError = error => {
|
|
|
552
541
|
};
|
|
553
542
|
|
|
554
543
|
const getSkuLoader = (_, clients) => {
|
|
555
|
-
const loader = async
|
|
544
|
+
const loader = async keys => {
|
|
545
|
+
const skuIds = keys.map(key => key.split('-')[0]);
|
|
546
|
+
const showInvisibleItems = keys.some(key => key.split('-')[1] === 'invisibleItems');
|
|
556
547
|
const {
|
|
557
548
|
products
|
|
558
549
|
} = await clients.search.products({
|
|
559
550
|
query: `sku:${skuIds.join(';')}`,
|
|
560
551
|
page: 0,
|
|
561
|
-
count: skuIds.length
|
|
552
|
+
count: skuIds.length,
|
|
553
|
+
showInvisibleItems
|
|
562
554
|
});
|
|
563
555
|
const skuBySkuId = products.reduce((acc, product) => {
|
|
564
556
|
for (const sku of product.items) {
|
|
@@ -938,6 +930,11 @@ const findChannel = facets => {
|
|
|
938
930
|
|
|
939
931
|
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;
|
|
940
932
|
};
|
|
933
|
+
const findRegionId = facets => {
|
|
934
|
+
var _facets$find$value5, _facets$find5;
|
|
935
|
+
|
|
936
|
+
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;
|
|
937
|
+
};
|
|
941
938
|
|
|
942
939
|
/**
|
|
943
940
|
* More info at: https://en.wikipedia.org/wiki/Order_statistic
|
|
@@ -1176,7 +1173,7 @@ const orderFormToCart = async (form, skuLoader) => {
|
|
|
1176
1173
|
order: {
|
|
1177
1174
|
orderNumber: form.orderFormId,
|
|
1178
1175
|
acceptedOffer: form.items.map(async item => ({ ...item,
|
|
1179
|
-
product: await skuLoader.load(item.id)
|
|
1176
|
+
product: await skuLoader.load(`${item.id}-invisibleItems`)
|
|
1180
1177
|
}))
|
|
1181
1178
|
},
|
|
1182
1179
|
messages: form.messages.map(({
|
|
@@ -1804,7 +1801,7 @@ const pickBestSku = skus => {
|
|
|
1804
1801
|
}, {
|
|
1805
1802
|
offer: o2
|
|
1806
1803
|
}) => bestOfferFirst(o1, o2));
|
|
1807
|
-
return best.sku;
|
|
1804
|
+
return best ? best.sku : skus[0];
|
|
1808
1805
|
};
|
|
1809
1806
|
const isValidSkuId = skuId => skuId !== '' && !Number.isNaN(Number(skuId));
|
|
1810
1807
|
|
|
@@ -1815,6 +1812,7 @@ const Query = {
|
|
|
1815
1812
|
// Insert channel in context for later usage
|
|
1816
1813
|
const channel = findChannel(locator);
|
|
1817
1814
|
const locale = findLocale(locator);
|
|
1815
|
+
const regionId = findRegionId(locator);
|
|
1818
1816
|
const id = findSkuId(locator);
|
|
1819
1817
|
const slug = findSlug(locator);
|
|
1820
1818
|
|
|
@@ -1875,7 +1873,8 @@ const Query = {
|
|
|
1875
1873
|
} = await search.products({
|
|
1876
1874
|
page: 0,
|
|
1877
1875
|
count: 1,
|
|
1878
|
-
query: `product:${route.id}
|
|
1876
|
+
query: `product:${route.id}`,
|
|
1877
|
+
regionId
|
|
1879
1878
|
});
|
|
1880
1879
|
|
|
1881
1880
|
if (!product) {
|
|
@@ -2117,7 +2116,9 @@ const StoreSearchResult = {
|
|
|
2117
2116
|
} = root;
|
|
2118
2117
|
const [terms, productSearchResult] = await Promise.all([search.suggestedTerms(searchArgs), productSearchPromise]);
|
|
2119
2118
|
const skus = productSearchResult.products.map(product => {
|
|
2120
|
-
|
|
2119
|
+
// What determines the presentation of the SKU is the price order
|
|
2120
|
+
// https://help.vtex.com/pt/tutorial/ordenando-imagens-na-vitrine-e-na-pagina-de-produto--tutorials_278
|
|
2121
|
+
const maybeSku = pickBestSku(product.items);
|
|
2121
2122
|
return maybeSku && enhanceSku(maybeSku, product);
|
|
2122
2123
|
}).filter(sku => !!sku);
|
|
2123
2124
|
const {
|
|
@@ -2136,7 +2137,9 @@ const StoreSearchResult = {
|
|
|
2136
2137
|
}, _) => {
|
|
2137
2138
|
const productSearchResult = await productSearchPromise;
|
|
2138
2139
|
const skus = productSearchResult.products.map(product => {
|
|
2139
|
-
|
|
2140
|
+
// What determines the presentation of the SKU is the price order
|
|
2141
|
+
// https://help.vtex.com/pt/tutorial/ordenando-imagens-na-vitrine-e-na-pagina-de-produto--tutorials_278
|
|
2142
|
+
const maybeSku = pickBestSku(product.items);
|
|
2140
2143
|
return maybeSku && enhanceSku(maybeSku, product);
|
|
2141
2144
|
}).filter(sku => !!sku);
|
|
2142
2145
|
return {
|