-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(adapter): update adapter's config in order to use the new platfo… (
- Loading branch information
Pedro López Mareque
authored
Jun 9, 2021
1 parent
0081f4f
commit 2d051f0
Showing
10 changed files
with
3,376 additions
and
3,694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"extends": ["plugin:@empathy/x/all"] | ||
"extends": ["plugin:@empathyco/x/all"] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,27 @@ | ||
function getURLParameter(name) { | ||
return decodeURIComponent( | ||
(new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(window.location.href) || [, ''])[1].replace(/\+/g, '%20')) || null; | ||
return decodeURIComponent( | ||
(new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(window.location.href) || [, ''])[1].replace(/\+/g, '%20')) || null; | ||
} | ||
|
||
var instance = getURLParameter('instance') || 'juguettos'; | ||
var instance = getURLParameter('instance') || undefined; | ||
var env = getURLParameter('env') || undefined; | ||
var scope = getURLParameter('scope') || 'default'; | ||
var lang = getURLParameter('lang') || 'es'; | ||
var scope = getURLParameter('scope') || 'desktop'; | ||
var lang = getURLParameter('lang') || 'en'; | ||
var device = getURLParameter('device') || 'mobile'; | ||
var searchLang = getURLParameter('searchLang') || lang; | ||
var currency = getURLParameter('currency') || 'EUR'; | ||
var consent = getURLParameter('consent') === 'true' || false; | ||
var documentDirection = getURLParameter('doc-dir') || 'ltr'; | ||
|
||
/*window.initX = function() { | ||
return { | ||
instance, | ||
env, | ||
scope, | ||
lang, | ||
searchLang, | ||
currency, | ||
consent, | ||
documentDirection | ||
}; | ||
};*/ | ||
|
||
window.initX = { | ||
instance, | ||
env, | ||
scope, | ||
lang, | ||
device, | ||
searchLang, | ||
currency, | ||
consent, | ||
documentDirection | ||
instance, | ||
env, | ||
scope, | ||
lang, | ||
device, | ||
searchLang, | ||
currency, | ||
consent, | ||
documentDirection | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { EmpathySearchRequest, SearchRequest } from '@empathy/search-adapter'; | ||
|
||
/** | ||
* This mapper modifies the request sent to the API. | ||
* | ||
* @param rawRequest - The initial | ||
* {@link @empathy/search-adapter#SearchRequest | SearchRequest} object without | ||
* any modification. | ||
* @param request - The {@link @empathy/search-adapter#EmpathySearchRequest | | ||
* empathy's search request object} with the changes done in previous hooks or | ||
* mappers. | ||
* | ||
* @returns A new {@link @empathy/search-adapter#EmpathySearchRequest | | ||
* empathy's search request object}. | ||
*/ | ||
export function customRequestMapper( | ||
rawRequest: SearchRequest, | ||
request: EmpathySearchRequest | ||
): EmpathySearchRequest { | ||
return Object.assign(request, { | ||
query: rawRequest.query | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { EmpathyResult } from '@empathy/search-adapter'; | ||
import { Result } from '@empathy/search-types'; | ||
|
||
/** | ||
* Custom platform result which extends the base {@link Result}. | ||
*/ | ||
interface CustomResult { | ||
/** Gender of the result. */ | ||
gender: string; | ||
/** Color of the result. */ | ||
color: string; | ||
/** Year of the result. */ | ||
year: string; | ||
/** List of category paths of the result. */ | ||
categoryPaths: string[]; | ||
/** Usage of the result. */ | ||
usage: string; | ||
/** Group ID of the result. */ | ||
groupId: string; | ||
/** Type of the result. */ | ||
type: string; | ||
/** Score of the result. */ | ||
score: number; | ||
/** List of category ids of the result. */ | ||
categoryIds: string[]; | ||
/** Size of the result. */ | ||
size: string; | ||
/** Season of the result. */ | ||
season: string; | ||
/** List of categories of the result. */ | ||
categories: string[]; | ||
} | ||
|
||
declare module '@empathy/search-types' { | ||
interface Result extends CustomResult {} | ||
} | ||
|
||
declare module '@empathy/search-adapter' { | ||
interface EmpathyResult extends CustomResult {} | ||
} | ||
|
||
/** | ||
* This mapper adapts the response from the api to X Components. | ||
* | ||
* @param rawResult - This is the raw response form the API. | ||
* @param result - This is the Empathy result handle by the app. | ||
* | ||
* @returns A new object which can be handled by XComponents. | ||
*/ | ||
export function resultMapper(rawResult: EmpathyResult, result: Result): Result { | ||
return Object.assign<Result, Partial<Result>>(result, { | ||
gender: rawResult.gender, | ||
color: rawResult.color, | ||
year: rawResult.year, | ||
usage: rawResult.usage, | ||
groupId: rawResult.groupId, | ||
type: rawResult.type, | ||
score: rawResult.score, | ||
size: rawResult.size, | ||
season: rawResult.season, | ||
categories: rawResult.categories, | ||
categoryIds: rawResult.categoryIds, | ||
categoryPaths: rawResult.categoryPaths | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,17 @@ | ||
import { EmpathyAdapterBuilder } from '@empathy/search-adapter'; | ||
import { Result } from '@empathy/search-types'; | ||
import { customRequestMapper } from '@/adapters/demo-request-mapper'; | ||
import { resultMapper } from '@/adapters/demo-result.mapper'; | ||
|
||
export const adapter = new EmpathyAdapterBuilder() | ||
.setInstance('juguettos') | ||
.setEnvironment('staging') | ||
.addMapper((_, result: Result) => { | ||
result.url = `./product_page.html?productId=${result.id.toString()}`; | ||
result.identifier.value = `${result.id.toString()}`; | ||
return result; | ||
}, 'results') | ||
.addRequestMapper(customRequestMapper) | ||
.addMapper(resultMapper, 'results') | ||
.setFeatureConfig('search', { | ||
endpoint: 'https://api.empathybroker.com/search/v1/query/juguettos/searchv2' | ||
endpoint: 'https://search.internal.test.empathy.co/query/empathy/search', | ||
responsePaths: { | ||
results: 'catalog.content', | ||
facets: 'catalog.facets', | ||
totalResults: 'catalog.numFound' | ||
} | ||
}) | ||
.setFacetConfig( | ||
{ | ||
modelName: 'HierarchicalFacet' | ||
}, | ||
'hierarchical_category' | ||
) | ||
.setFacetConfig( | ||
{ | ||
modelName: 'NumberRangeFacet', | ||
template: '<!tag=price_facet>priceSort:[<min> TO <max>]' | ||
}, | ||
'price_facet' | ||
) | ||
.setLang('es') | ||
.setScope('desktop') | ||
.setInstance('platform') | ||
.build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": [] | ||
} |