diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fe36c29..0538d565 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.12.1] - 2020.06.22 + +### Added + +- Add request_cache to ES url - @gibkigonzo (#387) + +### Fixed + +- Add error status code as number in `apiError` - @gibkigonzo (#442) +- Get proper tax calculation for multistore - @didkan (#464) +- Create only one ES client instance per app - @gibkigonzo (#393) + ## [1.12.0] - 2020.06.01 ### Added diff --git a/config/default.json b/config/default.json index 9906eaf9..bf8d204f 100644 --- a/config/default.json +++ b/config/default.json @@ -40,7 +40,7 @@ "review" ], "apiVersion": "5.6", - + "cacheRequest": false, "searchScoring": { "attributes": { "attribute_code": { diff --git a/package.json b/package.json index a3c9775f..8c5b2e1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-storefront-api", - "version": "1.12.0", + "version": "1.12.1", "private": true, "description": "vue-storefront API and data services", "main": "dist", diff --git a/src/api/catalog.ts b/src/api/catalog.ts index f8fe39a3..0f7128f4 100755 --- a/src/api/catalog.ts +++ b/src/api/catalog.ts @@ -42,7 +42,7 @@ export default ({config, db}) => async function (req, res, body) { let groupId = null // Request method handling: exit if not GET or POST - // Other metods - like PUT, DELETE etc. should be available only for authorized users or not available at all) + // Other methods - like PUT, DELETE etc. should be available only for authorized users or not available at all) if (!(req.method === 'GET' || req.method === 'POST' || req.method === 'OPTIONS')) { throw new Error('ERROR: ' + req.method + ' request method is not supported.') } @@ -118,6 +118,7 @@ export default ({config, db}) => async function (req, res, body) { auth: auth }, async (_err, _res, _resBody) => { // TODO: add caching layer to speed up SSR? How to invalidate products (checksum on the response BEFORE processing it) if (_err || _resBody.error) { + console.error(_err || _resBody.error) apiError(res, _err || _resBody.error) return } diff --git a/src/lib/elastic.js b/src/lib/elastic.js index 3cab2e3c..41327a13 100644 --- a/src/lib/elastic.js +++ b/src/lib/elastic.js @@ -49,6 +49,10 @@ function adjustBackendProxyUrl (req, indexName, entityType, config) { delete parsedQuery.request delete parsedQuery.request_format delete parsedQuery.response_format + if (config.elasticsearch.cacheRequest) { + parsedQuery.request_cache = !!config.elasticsearch.cacheRequest + } + url = config.elasticsearch.host + ':' + config.elasticsearch.port + '/' + adjustIndexName(indexName, entityType, config) + '/_search?' + queryString.stringify(parsedQuery) } if (!url.startsWith('http')) { @@ -66,13 +70,14 @@ function adjustQuery (esQuery, entityType, config) { } function getHits (result) { - if (result.body) { // differences between ES5 andd ES7 + if (result.body) { // differences between ES5 and ES7 return result.body.hits.hits } else { return result.hits.hits } } +let esClient = null function getClient (config) { let { host, port, protocol, apiVersion, requestTimeout } = config.elasticsearch const node = `${protocol}://${host}:${port}` @@ -83,7 +88,11 @@ function getClient (config) { auth = { username: user, password } } - return new es.Client({ node, auth, apiVersion, requestTimeout }) + if (!esClient) { + esClient = new es.Client({ node, auth, apiVersion, requestTimeout }) + } + + return esClient } function putAlias (db, originalName, aliasName, next) { diff --git a/src/lib/util.js b/src/lib/util.js index e36009e3..bf534c51 100755 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -86,14 +86,14 @@ export function apiStatus (res, result = 'OK', code = 200, meta = null) { * @return {json} [result='OK'] Text message or result information object */ export function apiError (res, error) { - let errorCode = error.code || error.status || 500; + let errorCode = error.code || error.status; let errorMessage = error.errorMessage || error; if (error instanceof Error) { // Class 'Error' is not serializable with JSON.stringify, extract data explicitly. errorCode = error.code || errorCode; errorMessage = error.message; } - return apiStatus(res, errorMessage, errorCode); + return apiStatus(res, errorMessage, Number(errorCode) || 500); } export function encryptToken (textToken, secret) { diff --git a/src/platform/magento1/tax.js b/src/platform/magento1/tax.js index 9bb1b04b..5d953cdf 100644 --- a/src/platform/magento1/tax.js +++ b/src/platform/magento1/tax.js @@ -39,10 +39,10 @@ class TaxProxy extends AbstractTaxProxy { taxCountry = this._config.tax.defaultCountry } } - if (sourcePriceInclTax === null) { + if (sourcePriceInclTax == null) { sourcePriceInclTax = this._config.tax.sourcePriceIncludesTax } - if (finalPriceInclTax === null) { + if (finalPriceInclTax == null) { finalPriceInclTax = this._config.tax.finalPriceIncludesTax } this._deprecatedPriceFieldsSupport = this._config.tax.deprecatedPriceFieldsSupport diff --git a/src/platform/magento2/tax.js b/src/platform/magento2/tax.js index 175cd456..089fd0a0 100644 --- a/src/platform/magento2/tax.js +++ b/src/platform/magento2/tax.js @@ -38,10 +38,10 @@ class TaxProxy extends AbstractTaxProxy { taxCountry = this._config.tax.defaultCountry } } - if (sourcePriceInclTax === null) { + if (sourcePriceInclTax == null) { sourcePriceInclTax = this._config.tax.sourcePriceIncludesTax } - if (finalPriceInclTax === null) { + if (finalPriceInclTax == null) { finalPriceInclTax = this._config.tax.finalPriceIncludesTax } this._deprecatedPriceFieldsSupport = this._config.tax.deprecatedPriceFieldsSupport diff --git a/yarn.lock b/yarn.lock index 8ed39c07..d0ac99be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1520,12 +1520,12 @@ commander@2.13.0: version "2.13.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c" -commander@^2.18.0: +commander@^2.18.0, commander@~2.20.3: version "2.20.3" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^2.9.0, commander@~2.20.0: +commander@^2.9.0: version "2.20.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422" @@ -3004,12 +3004,14 @@ gtoken@^3.0.0: mime "^2.2.0" handlebars@^4.1.2: - version "4.1.2" - resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.1.2.tgz#b6b37c1ced0306b221e094fc7aca3ec23b131b67" + version "4.7.6" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.6.tgz#d4c05c1baf90e9945f77aa68a7a219aa4a7df74e" + integrity sha512-1f2BACcBfiwAfStCKZNrUCgqNZkGsAT7UM3kkYtXuLo0KnaVfjKOyf7PRzB6++aK9STyT1Pd2ZCPe3EGOXleXA== dependencies: + minimist "^1.2.5" neo-async "^2.6.0" - optimist "^0.6.1" source-map "^0.6.1" + wordwrap "^1.0.0" optionalDependencies: uglify-js "^3.1.4" @@ -4654,11 +4656,7 @@ minimist@0.0.8: resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0= -minimist@^1.1.0, minimist@^1.1.1, minimist@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" - -minimist@^1.2.5: +minimist@^1.1.0, minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5: version "1.2.5" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== @@ -4810,6 +4808,7 @@ negotiator@0.6.2: neo-async@^2.6.0: version "2.6.1" resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.1.tgz#ac27ada66167fa8849a6addd837f6b189ad2081c" + integrity sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw== nib@~1.1.2: version "1.1.2" @@ -5079,7 +5078,7 @@ onetime@^5.1.0: dependencies: mimic-fn "^2.1.0" -optimist@^0.6.1, optimist@latest: +optimist@latest: version "0.6.1" resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" dependencies: @@ -7150,11 +7149,11 @@ uglify-js@^2.6.1: uglify-to-browserify "~1.0.0" uglify-js@^3.1.4: - version "3.6.0" - resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.6.0.tgz#704681345c53a8b2079fb6cec294b05ead242ff5" + version "3.9.4" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.9.4.tgz#867402377e043c1fc7b102253a22b64e5862401b" + integrity sha512-8RZBJq5smLOa7KslsNsVcSH+KOXf1uDU8yqLeNuVKwmT0T3FA0ZoXlinQfRad7SDcbZZRZE4ov+2v71EnxNyCA== dependencies: - commander "~2.20.0" - source-map "~0.6.1" + commander "~2.20.3" uglify-to-browserify@~1.0.0: version "1.0.2" @@ -7476,14 +7475,14 @@ wordwrap@0.0.2: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f" integrity sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8= +wordwrap@^1.0.0, wordwrap@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + wordwrap@~0.0.2: version "0.0.3" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107" -wordwrap@~1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" - wrap-ansi@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"