Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@empathyco/x-adapter-platform
Advanced tools
Readme
Empathy Platform Adapter is a library to ease the communication with empathy.co Empathy Platform API. Built upon the x-adapter library, it contains a sample configuration for setup, global configurations, mappers and models.
It is used as the default adapter configuration in x-archetype, a standardised implementation of the x-components library, which imports it as a plugin.
# or pnpm or yarn
npm install @empathyco/x-adapter-platform
The PlatformAdapter
is an object containing several endpoint adapters.
Each EndpointAdapter
contains the configuration of an endpoint, including the URL, the mapper to
adapt the responses and the requests, the request options ...
export const platformAdapter: PlatformAdapter = {
search: searchEndpointAdapter,
popularSearches: popularSearchesEndpointAdapter,
recommendations: recommendationsEndpointAdapter,
nextQueries: nextQueriesEndpointAdapter,
querySuggestions: querySuggestionsEndpointAdapter,
relatedTags: relatedTagsEndpointAdapter,
identifierResults: identifierResultsEndpointAdapter,
tagging: taggingEndpointAdapter
};
The
Empathy Platform API
has the particularity of needing an env
, instance
and a language
to be passed in each endpoint
call (except the tagging).
In an x-archetype project context, which would be the recommended scenario to use this package, these parameters are configured through the snippetConfig.
If you are not using the x-platform-adapter
inside an x-archetype
based project, but you want to
use the Empathy Platform API, you can use the extraParams
field to specify the required
parameters to make it work, as shown in the examples below.
/search/v1/query/{extraParams.instance}/search
SearchRequest
SearchResponse
The search endpoint will include an array of results in its response.
import { platformAdapter } from '@empathyco/x-adapter-platform';
const { results } = await platformAdapter.search({
query: 'trousers',
extraParams: {
lang: 'en',
instance: 'empathy',
env: 'staging'
}
});
/search/v1/query/{extraParams.instance}/empathize
PopularSearchesRequest
PopularSearchesResponse
The PopularSearches
endpoint will return top searched queries.
import { platformAdapter } from '@empathyco/x-adapter-platform';
const { suggestions } = await platformAdapter.popularSearches({
extraParams: {
lang: 'en',
instance: 'empathy',
env: 'staging'
}
});
/search/v1/query/{extraParams.instance}/topclicked
RecommendationsRequest
RecommendationsResponse
These recommendations are top clicked products based on user click interactions (note: no personal user data is collected).
import { platformAdapter } from '@empathyco/x-adapter-platform';
const { results } = await platformAdapter.recommendations({
extraParams: {
lang: 'en',
instance: 'empathy',
env: 'staging'
}
});
/nextqueries/{extraParams.instance}
NextQueriesRequest
NextQueriesResponse
The NextQueries
endpoint returns recurring searches that users tend to do after searching for a
specific item. The aim is to suggest a new term that the user may be interested in.
The NextQueriesRequest
is usually done after a SearchRequest
has been made.
import { platformAdapter } from '@empathyco/x-adapter-platform';
const { nextQueries } = await platformAdapter.nextQueries({
query: 'trousers',
extraParams: {
lang: 'en',
instance: 'empathy',
env: 'staging'
}
});
/search/v1/query/{extraParams.instance}/empathize
QuerySuggestionsRequest
QuerySuggestionsResponse
The QuerySuggestions
endpoint returns suggestions based on a query. For example, for the query
"trousers" we could have "denim trousers, cargo trousers, chino trousers, etc..." as query
suggestions.
import { platformAdapter } from '@empathyco/x-adapter-platform';
const { suggestions } = await platformAdapter.querySuggestions({
query: 'trousers',
extraParams: {
lang: 'en',
instance: 'empathy',
env: 'staging'
}
});
/relatedtags/{extraParams.instance}
RelatedTagsRequest
RelatedTagsResponse
The RelatedTags
endpoint will return terms used to help refining a search query by adding more
specificity (e.g, adjectives: long, short, gluten-free; categories: kids, summer...).
import { platformAdapter } from '@empathyco/x-adapter-platform';
const { relatedTags } = await platformAdapter.relatedTags({
query: 'trousers',
extraParams: {
lang: 'en',
instance: 'empathy',
env: 'staging'
}
});
/search/v1/query/{extraParams.instance}/skusearch
IdentifierResultsRequest
IdentifierResultsResponse
The IdentifierResults
endpoint will return the results whose
identifier
matches a given query
.
import { platformAdapter } from '@empathyco/x-adapter-platform';
const { results } = await platformAdapter.identifierResults({
query: '1234',
extraParams: {
lang: 'en',
instance: 'empathy',
env: 'staging'
}
});
({ url }) => url
TaggingRequest
void
The Tagging
endpoint allows sending events to a server to collect metrics about how the search is
performing (this won't collect user data, just the use of tools per session).
You can configure your tagging
object following the
Taggable
interface, which contains several user actions and the capability to include your own.
import { platformAdapter } from '@empathyco/x-adapter-platform';
const tagging = await platformAdapter.tagging({
// The tagging request will be sent to this URL
url: 'https://api.staging.empathy.co/tagging/v1/track/empathy/query',
// Info that will be sent along with the query event
params: {
filtered: 'false',
lang: 'en',
origin: 'customer:no_query',
page: '1',
q: 'trousers',
scope: 'desktop',
spellcheck: 'false',
totalHits: 700
}
});
Each request and response schemas are created as MutableSchemas
, so they can be modified using the
$extends
, $override
, $replace
methods accordingly. You can check the
x-adapter
's package
documentation for further details.
import { PlatformResult, resultSchema } from '@empathyco/x-adapter-platform';
import { Result } from '@empathyco/x-types';
interface EmpathyDemoPlatformResult extends PlatformResult {
season: string;
}
declare module '@empathyco/x-types' {
export interface Result {
season: string;
}
}
resultSchema.$override<EmpathyDemoPlatformResult, Partial<Result>>({
season: 'season'
});
Empathy Adapter Platform features are tested using Jest. You will find a
__tests__
folder inside the src
folder with tests for each of the endpoint calls, and also
inside each of the project's sections functionalities (endpoint-adapters
, mappers
and
schemas
).
npm run test
To start contributing to the project, please take a look at our
Contributing Guide. Take in
account that x-adapter-platform
is developed using Typescript,
so we recommend you to check it out.
FAQs
A search client for the Empathy Platform API
The npm package @empathyco/x-adapter-platform receives a total of 387 weekly downloads. As such, @empathyco/x-adapter-platform popularity was classified as not popular.
We found that @empathyco/x-adapter-platform demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.