Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Add `Product.breadcrumbs`and `Category.breadcrumbs` - @gibkigonzo (#71)
- Add changes from vsf-api hotfix 1.12.1 - @gibkigonzo (https://github.com/DivanteLtd/vue-storefront-api/pull/475)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
],
"index": "vue_storefront_catalog",
"apiVersion": "7.2",

"cacheRequest": false,
"searchScoring": {
"attributes": {
"attribute_code": {
Expand Down
1 change: 1 addition & 0 deletions packages/default-catalog/api/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,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) {
Logger.error(_err || _resBody.error)
apiError(res, _err || _resBody.error);
return
}
Expand Down
10 changes: 9 additions & 1 deletion packages/lib/elastic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export function adjustBackendProxyUrl (req, indexName: string, entityType: strin
delete parsedQuery.request
delete parsedQuery.request_format
delete parsedQuery.response_format
if (config.get<boolean>('elasticsearch.cacheRequest')) {
parsedQuery.request_cache = !!config.get<boolean>('elasticsearch.cacheRequest')
}
url = config.get<string>('elasticsearch.host') + ':' + config.get<number>('elasticsearch.port') + '/' + adjustIndexName(indexName, entityType, config) + '/_search?' + queryString.stringify(parsedQuery)
}
if (!url.startsWith('http')) {
Expand Down Expand Up @@ -99,6 +102,7 @@ export function getHits (result) {
}
}

let esClient = null
export function getClient (config: IConfig): Client {
const { host, port, protocol, requestTimeout } = config.get('elasticsearch')
const node = `${protocol}://${host}:${port}`
Expand All @@ -110,7 +114,11 @@ export function getClient (config: IConfig): Client {
auth = { username: user, password }
}

return new Client({ node, auth, requestTimeout })
if (!esClient) {
esClient = new Client({ node, auth, requestTimeout })
}

return esClient
}

export async function putAlias (db: Client, originalName: string, aliasName: string) {
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ export function apiStatus (res, result: string|Record<any, any> = 'OK', code = 2
* @return {json} [result='OK'] Text message or result information object
*/
export function apiError (res, error: Record<any, any>): string|Record<any, any> {
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 as any).code || errorCode;
errorMessage = error.message;
}
return apiStatus(res, errorMessage, errorCode);
return apiStatus(res, errorMessage, Number(errorCode) || 500);
}

export function encryptToken (textToken, secret): string {
Expand Down
4 changes: 2 additions & 2 deletions packages/platform-magento1/tax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class TaxProxy extends AbstractTaxProxy {
taxCountry = this._config.get('tax.defaultCountry')
}
}
if (sourcePriceInclTax === null) {
if (sourcePriceInclTax == null) {
sourcePriceInclTax = this._config.get('tax.sourcePriceIncludesTax')
}
if (finalPriceInclTax === null) {
if (finalPriceInclTax == null) {
finalPriceInclTax = this._config.get('tax.finalPriceIncludesTax')
}
this._deprecatedPriceFieldsSupport = this._config.get('tax.deprecatedPriceFieldsSupport')
Expand Down
4 changes: 2 additions & 2 deletions packages/platform-magento2/tax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class TaxProxy extends AbstractTaxProxy {
taxCountry = this._storeConfigTax.defaultCountry
}
}
if (sourcePriceInclTax === null) {
if (sourcePriceInclTax == null) {
sourcePriceInclTax = this._storeConfigTax.sourcePriceIncludesTax
}
if (finalPriceInclTax === null) {
if (finalPriceInclTax == null) {
finalPriceInclTax = this._storeConfigTax.finalPriceIncludesTax
}
this._deprecatedPriceFieldsSupport = this._storeConfigTax.deprecatedPriceFieldsSupport
Expand Down