Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit 42df865

Browse files
author
tkostuch
committed
Merge branch 'master' of github.com:DivanteLtd/vue-storefront-api into HEAD
2 parents db11e15 + 093d393 commit 42df865

File tree

3 files changed

+64
-58
lines changed

3 files changed

+64
-58
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
- Fix MSI default stock id value
2626
- Add outputFormatter to response from cache - @gibkigonzo (#428)
2727

28+
29+
## [1.11.1] - 2020.03.17
30+
31+
### Added
32+
- Add save address on place order - @lucasqm (#394)
33+
- Add ElasticSearch client support for HTTP authentication - @cewald (#397)
34+
- Add error handling for catalog and add header 'X-VS-Cache-Tags' to response - @gibkigonzo
35+
36+
### Fixed
37+
- Add fallback for `sourcePriceInclTax` and `finalPriceInclTax` in `magento1` platform - @cewald (#398)
38+
- Add default ES index to config and update `getStockList` - @gibkigonzo (#405)
39+
- Makes elastic-stock extension compatible with both ES5 and ES7. Allows for stock fetch of configurable children that is set as "Not Visible Individually" - @didkan (#410)
40+
41+
2842
## [1.11.0] - 2019.12.20
2943

3044
### Fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-storefront-api",
3-
"version": "1.11.0",
3+
"version": "1.11.1",
44
"private": true,
55
"description": "vue-storefront API and data services",
66
"main": "dist",

src/api/catalog.ts

Lines changed: 49 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { sha3_224 } from 'js-sha3'
77
import AttributeService from './attribute/service'
88
import bodybuilder from 'bodybuilder'
99
import { elasticsearch, SearchQuery } from 'storefront-query-builder'
10+
import { apiError } from '../lib/util';
1011

1112
function _cacheStorageHandler (config, result, hash, tags) {
1213
if (config.server.useOutputCache && cache) {
@@ -109,64 +110,55 @@ export default ({config, db}) => async function (req, res, body) {
109110
body: requestBody,
110111
json: true,
111112
auth: auth
112-
}, (_err, _res, _resBody) => { // TODO: add caching layer to speed up SSR? How to invalidate products (checksum on the response BEFORE processing it)
113-
if (_resBody && _resBody.hits && _resBody.hits.hits) { // we're signing up all objects returned to the client to be able to validate them when (for example order)
114-
const factory = new ProcessorFactory(config)
115-
const tagsArray = []
116-
if (config.server.useOutputCache && cache) {
117-
const tagPrefix = entityType[0].toUpperCase() // first letter of entity name: P, T, A ...
118-
tagsArray.push(entityType)
119-
_resBody.hits.hits.map(item => {
120-
if (item._source.id) { // has common identifier
121-
tagsArray.push(`${tagPrefix}${item._source.id}`)
122-
}
123-
})
124-
}
125-
126-
let resultProcessor = factory.getAdapter(entityType, indexName, req, res)
127-
128-
if (!resultProcessor) { resultProcessor = factory.getAdapter('default', indexName, req, res) } // get the default processor
129-
if (entityType === 'product') {
130-
resultProcessor.process(_resBody.hits.hits, groupId).then(async (result) => {
131-
_resBody.hits.hits = result
132-
if (config.get('varnish.enabled')) {
133-
// Add tags to cache, so we can display them in response headers then
134-
_cacheStorageHandler(config, {
135-
..._resBody,
136-
tags: tagsArray
137-
}, reqHash, tagsArray)
138-
} else {
139-
_cacheStorageHandler(config, _resBody, reqHash, tagsArray)
140-
}
141-
if (_resBody.aggregations && config.entities.attribute.loadByAttributeMetadata) {
142-
const attributeListParam = AttributeService.transformAggsToAttributeListParam(_resBody.aggregations)
143-
// find attribute list
144-
const attributeList = await AttributeService.list(attributeListParam, config, indexName)
145-
_resBody.attribute_metadata = attributeList.map(AttributeService.transformToMetadata)
146-
}
147-
res.json(_outputFormatter(_resBody, responseFormat));
148-
}).catch((err) => {
149-
console.error(err)
150-
})
151-
} else {
152-
resultProcessor.process(_resBody.hits.hits).then((result) => {
153-
_resBody.hits.hits = result
154-
if (config.get('varnish.enabled')) {
155-
// Add tags to cache, so we can display them in response headers then
156-
_cacheStorageHandler(config, {
157-
..._resBody,
158-
tags: tagsArray
159-
}, reqHash, tagsArray)
160-
} else {
161-
_cacheStorageHandler(config, _resBody, reqHash, tagsArray)
162-
}
163-
res.json(_outputFormatter(_resBody, responseFormat));
164-
}).catch((err) => {
165-
console.error(err)
166-
})
113+
}, async (_err, _res, _resBody) => { // TODO: add caching layer to speed up SSR? How to invalidate products (checksum on the response BEFORE processing it)
114+
if (_err || _resBody.error) {
115+
apiError(res, _err || _resBody.error);
116+
return
117+
}
118+
try {
119+
if (_resBody && _resBody.hits && _resBody.hits.hits) { // we're signing up all objects returned to the client to be able to validate them when (for example order)
120+
const factory = new ProcessorFactory(config)
121+
const tagsArray = []
122+
if (config.server.useOutputCache && cache) {
123+
const tagPrefix = entityType[0].toUpperCase() // first letter of entity name: P, T, A ...
124+
tagsArray.push(entityType)
125+
_resBody.hits.hits.map(item => {
126+
if (item._source.id) { // has common identifier
127+
tagsArray.push(`${tagPrefix}${item._source.id}`)
128+
}
129+
})
130+
const cacheTags = tagsArray.join(' ')
131+
res.setHeader('X-VS-Cache-Tags', cacheTags)
132+
}
133+
134+
let resultProcessor = factory.getAdapter(entityType, indexName, req, res)
135+
136+
if (!resultProcessor) { resultProcessor = factory.getAdapter('default', indexName, req, res) } // get the default processor
137+
138+
const productGroupId = entityType === 'product' ? groupId : undefined
139+
const result = await resultProcessor.process(_resBody.hits.hits, productGroupId)
140+
_resBody.hits.hits = result
141+
if (entityType === 'product' && _resBody.aggregations && config.entities.attribute.loadByAttributeMetadata) {
142+
const attributeListParam = AttributeService.transformAggsToAttributeListParam(_resBody.aggregations)
143+
// find attribute list
144+
const attributeList = await AttributeService.list(attributeListParam, config, indexName)
145+
_resBody.attribute_metadata = attributeList.map(AttributeService.transformToMetadata)
146+
}
147+
if (config.get('varnish.enabled')) {
148+
// Add tags to cache, so we can display them in response headers then
149+
_cacheStorageHandler(config, {
150+
..._resBody,
151+
tags: tagsArray
152+
}, reqHash, tagsArray)
153+
} else {
154+
_cacheStorageHandler(config, _resBody, reqHash, tagsArray)
155+
}
156+
res.json(_outputFormatter(_resBody, responseFormat));
157+
} else { // no cache storage if no results from Elastic
158+
res.json(_resBody);
167159
}
168-
} else { // no cache storage if no results from Elastic
169-
res.json(_resBody);
160+
} catch (err) {
161+
apiError(res, err);
170162
}
171163
});
172164
}

0 commit comments

Comments
 (0)