@empathyco/x-adapter-platform 1.0.0-alpha.54 → 1.0.0-alpha.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +346 -5
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,9 +1,350 @@
1
1
  # x-adapter-platform
2
2
 
3
- `x-adapter-platform` is a library to ease the communication with
4
- **[empathy.co](https://empathy.co/)** Platform API.
3
+ **Empathy Platform Adapter** is a library to ease the communication with **empathy.co**
4
+ [Empathy Platform API](https://docs.empathy.co/develop-empathy-platform/api-reference/search-api.html).
5
+ Built upon the [x-adapter](https://github.com/empathyco/x/tree/main/packages/x-adapter) library, it
6
+ contains a sample configuration for setup, global configurations, mappers and models.
5
7
 
6
- ### Contributing
8
+ It is used as the default adapter configuration in
9
+ [x-archetype](https://github.com/empathyco/x-archetype), a standardised implementation of the
10
+ [x-components](https://github.com/empathyco/x/tree/main/packages/x-components) library, which
11
+ imports it as a plugin.
7
12
 
8
- To start contributing to the project, please take a look to our
9
- [Contributing Guide](../../.github/CONTRIBUTING.md).
13
+ <br>
14
+
15
+ ## Tech Stack
16
+
17
+ [![TypeScript](https://img.shields.io/badge/-typescript-3178C6?logo=typescript&logoColor=white&style=for-the-badge)](https://www.typescriptlang.org/)
18
+ [![Jest](https://img.shields.io/badge/-jest-C21325?logo=jest&logoColor=white&style=for-the-badge)](https://jestjs.io/)
19
+
20
+ <br>
21
+
22
+ ## Installation
23
+
24
+ ```
25
+ npm i @empathyco/x-adapter-platform
26
+ ```
27
+
28
+ <br>
29
+
30
+ ## Configuration & Usage
31
+
32
+ The `PlatformAdapter` is an object containing several endpoint adapters.
33
+
34
+ Each `EndpointAdapter` contains the configuration of an endpoint, including the URL, the mapper to
35
+ adapt the responses and the requests, the request options ...
36
+
37
+ ```ts
38
+ export const platformAdapter: PlatformAdapter = {
39
+ search: searchEndpointAdapter,
40
+ popularSearches: popularSearchesEndpointAdapter,
41
+ recommendations: recommendationsEndpointAdapter,
42
+ nextQueries: nextQueriesEndpointAdapter,
43
+ querySuggestions: querySuggestionsEndpointAdapter,
44
+ relatedTags: relatedTagsEndpointAdapter,
45
+ identifierResults: identifierResultsEndpointAdapter,
46
+ tagging: taggingEndpointAdapter
47
+ };
48
+ ```
49
+
50
+ <br>
51
+
52
+ ### Platform Endpoint Adapters & usage
53
+
54
+ The
55
+ [Empathy Platform API](https://docs.empathy.co/develop-empathy-platform/api-reference/search-api.html)
56
+ has the particularity of needing an `env`, `instance` and a `language` to be passed in each endpoint
57
+ call (except the tagging).
58
+
59
+ In an [x-archetype](https://github.com/empathyco/x-archetype) project context, which would be the
60
+ recommended scenario to use this package, these parameters are configured through the
61
+ [snippetConfig](https://docs.empathy.co/develop-empathy-platform/build-search-ui/web-archetype-integration-guide.html#snippet-configuration).
62
+
63
+ If you are not using the `x-platform-adapter` inside an `x-archetype` based project, but you want to
64
+ use the **Empathy Platform API**, you can use the `extraParams` field to specify the required
65
+ parameters to make it work, as shown in the examples below.
66
+
67
+ <br>
68
+
69
+ ##### Search endpoint adapter
70
+
71
+ - endpoint: `/search/v1/query/{extraParams.instance}/search`
72
+ - request:
73
+ [`SearchRequest`](https://github.com/empathyco/x/blob/main/packages/x-types/src/request/search-request.model.ts)
74
+ - response:
75
+ [`SearchResponse`](https://github.com/empathyco/x/blob/main/packages/x-types/src/response/search-response.model.ts)
76
+
77
+ The search endpoint will include an
78
+ [array of results](https://github.com/empathyco/x/blob/main/packages/x-types/src/result/result.model.ts)
79
+ in its response.
80
+
81
+ ```ts
82
+ import { platformAdapter } from '@empathyco/x-adapter-platform';
83
+
84
+ const { results } = await platformAdapter.search({
85
+ query: 'trousers',
86
+ extraParams: {
87
+ lang: 'en',
88
+ instance: 'empathy',
89
+ env: 'staging'
90
+ }
91
+ });
92
+ ```
93
+
94
+ <br>
95
+
96
+ ##### Popular searches endpoint adapter
97
+
98
+ - endpoint: `/search/v1/query/{extraParams.instance}/empathize`
99
+ - request:
100
+ [`PopularSearchesRequest`](https://github.com/empathyco/x/blob/main/packages/x-types/src/request/popular-searches-request.model.ts)
101
+ - response:
102
+ [`PopularSearchesResponse`](https://github.com/empathyco/x/blob/main/packages/x-types/src/response/popular-searches-response.model.ts)
103
+
104
+ The `PopularSearches` endpoint will return top searched queries.
105
+
106
+ ```ts
107
+ import { platformAdapter } from '@empathyco/x-adapter-platform';
108
+
109
+ const { suggestions } = await platformAdapter.popularSearches({
110
+ extraParams: {
111
+ lang: 'en',
112
+ instance: 'empathy',
113
+ env: 'staging'
114
+ }
115
+ });
116
+ ```
117
+
118
+ <br>
119
+
120
+ ##### Recommendations endpoint adapter
121
+
122
+ - endpoint: `/search/v1/query/{extraParams.instance}/topclicked`
123
+ - request:
124
+ [`RecommendationsRequest`](https://github.com/empathyco/x/blob/main/packages/x-types/src/request/recommendations-request.model.ts)
125
+ - response:
126
+ [`RecommendationsResponse`](https://github.com/empathyco/x/blob/main/packages/x-types/src/response/recommendations-response.model.ts)
127
+
128
+ These **recommendations** are top clicked products based on user click interactions (note: no personal user data is collected).
129
+
130
+ ```ts
131
+ import { platformAdapter } from '@empathyco/x-adapter-platform';
132
+
133
+ const { results } = await platformAdapter.recommendations({
134
+ extraParams: {
135
+ lang: 'en',
136
+ instance: 'empathy',
137
+ env: 'staging'
138
+ }
139
+ });
140
+ ```
141
+
142
+ <br>
143
+
144
+ ##### Next Queries endpoint adapter
145
+
146
+ - endpoint: `/nextqueries/{extraParams.instance}`
147
+ - request:
148
+ [`NextQueriesRequest`](https://github.com/empathyco/x/blob/main/packages/x-types/src/request/next-queries-request.model.ts)
149
+ - response:
150
+ [`NextQueriesResponse`](https://github.com/empathyco/x/blob/main/packages/x-types/src/response/next-queries-response.model.ts)
151
+
152
+ The `NextQueries` endpoint returns recurring searches that users tend to do after searching for a
153
+ specific item. The aim is to suggest a new term that the user may be interested in.
154
+
155
+ The `NextQueriesRequest` is usually done after a `SearchRequest` has been made.
156
+
157
+ ```ts
158
+ import { platformAdapter } from '@empathyco/x-adapter-platform';
159
+
160
+ const { nextQueries } = await platformAdapter.nextQueries({
161
+ query: 'trousers',
162
+ extraParams: {
163
+ lang: 'en',
164
+ instance: 'empathy',
165
+ env: 'staging'
166
+ }
167
+ });
168
+ ```
169
+
170
+ <br>
171
+
172
+ ##### Query suggestions endpoint adapter
173
+
174
+ - endpoint: `/search/v1/query/{extraParams.instance}/empathize`
175
+ - request:
176
+ [`QuerySuggestionsRequest`](https://github.com/empathyco/x/blob/main/packages/x-types/src/request/query-suggestions-request.model.ts)
177
+ - response:
178
+ [`QuerySuggestionsResponse`](https://github.com/empathyco/x/blob/main/packages/x-types/src/response/query-suggestions-response.model.ts)
179
+
180
+ The `QuerySuggestions` endpoint returns suggestions based on a query. For example, for the query
181
+ "trousers" we could have "denim trousers, cargo trousers, chino trousers, etc..." as query
182
+ suggestions.
183
+
184
+ ```ts
185
+ import { platformAdapter } from '@empathyco/x-adapter-platform';
186
+
187
+ const { suggestions } = await platformAdapter.querySuggestions({
188
+ query: 'trousers',
189
+ extraParams: {
190
+ lang: 'en',
191
+ instance: 'empathy',
192
+ env: 'staging'
193
+ }
194
+ });
195
+ ```
196
+
197
+ <br>
198
+
199
+ ##### Related tags endpoint adapter
200
+
201
+ - endpoint: `/relatedtags/{extraParams.instance}`
202
+ - request:
203
+ [`RelatedTagsRequest`](https://github.com/empathyco/x/blob/main/packages/x-types/src/request/related-tags-request.model.ts)
204
+ - response:
205
+ [`RelatedTagsResponse`](https://github.com/empathyco/x/blob/main/packages/x-types/src/response/related-tags-response.model.ts)
206
+
207
+ The `RelatedTags` endpoint will return terms used to help refining a search query by adding more
208
+ **specificity** (e.g, adjectives: long, short, gluten-free; categories: kids, summer...).
209
+
210
+ ```ts
211
+ import { platformAdapter } from '@empathyco/x-adapter-platform';
212
+
213
+ const { relatedTags } = await platformAdapter.relatedTags({
214
+ query: 'trousers',
215
+ extraParams: {
216
+ lang: 'en',
217
+ instance: 'empathy',
218
+ env: 'staging'
219
+ }
220
+ });
221
+ ```
222
+
223
+ <br>
224
+
225
+ ##### Identifier results endpoint adapter
226
+
227
+ - endpoint: `/search/v1/query/{extraParams.instance}/skusearch`
228
+ - request:
229
+ [`IdentifierResultsRequest`](https://github.com/empathyco/x/blob/main/packages/x-types/src/request/identifier-results-request.model.ts)
230
+ - response:
231
+ [`IdentifierResultsResponse`](https://github.com/empathyco/x/blob/main/packages/x-types/src/response/identifier-results-response.model.ts)
232
+
233
+ The `IdentifierResults` endpoint will return the results whose
234
+ [identifier](https://github.com/empathyco/x/blob/main/packages/x-types/src/identifiable.model.ts)
235
+ matches a given `query`.
236
+
237
+ ```ts
238
+ import { platformAdapter } from '@empathyco/x-adapter-platform';
239
+
240
+ const { results } = await platformAdapter.identifierResults({
241
+ query: '1234',
242
+ extraParams: {
243
+ lang: 'en',
244
+ instance: 'empathy',
245
+ env: 'staging'
246
+ }
247
+ });
248
+ ```
249
+
250
+ <br>
251
+
252
+ ##### Tagging endpoint adapter
253
+
254
+ - endpoint: `({ url }) => url`
255
+ - request:
256
+ [`TaggingRequest`](https://github.com/empathyco/x/blob/main/packages/x-types/src/request/tagging-request.model.ts)
257
+ - response: `void`
258
+
259
+ The `Tagging` endpoint allows sending events to a server to collect metrics about how the search is
260
+ performing (this won't collect user data, just the use of tools per session).
261
+
262
+ You can configure your `tagging` object following the
263
+ [`Taggable`](https://github.com/empathyco/x/blob/main/packages/x-types/src/tagging.model.ts)
264
+ interface, which contains several user actions and the capability to include your own.
265
+
266
+ ```ts
267
+ import { platformAdapter } from '@empathyco/x-adapter-platform';
268
+
269
+ const tagging = await platformAdapter.tagging({
270
+ // The tagging request will be sent to this URL
271
+ url: 'https://api.staging.empathy.co/tagging/v1/track/empathy/query',
272
+ // Info that will be sent along with the query event
273
+ params: {
274
+ filtered: 'false',
275
+ lang: 'en',
276
+ origin: 'customer:no_query',
277
+ page: '1',
278
+ q: 'trousers',
279
+ scope: 'desktop',
280
+ spellcheck: 'false',
281
+ totalHits: 700
282
+ }
283
+ });
284
+ ```
285
+
286
+ <br>
287
+
288
+ ### Modifying the x-platform-adapter
289
+
290
+ Each request and response schemas are created as `MutableSchemas`, so they can be modified using the
291
+ `$extends`, `$override`, `$replace` methods accordingly. You can check the
292
+ [`x-adapter`](https://github.com/empathyco/x/tree/main/packages/x-adapter/README.md)'s package
293
+ documentation for further details.
294
+
295
+ ###### Example of overriding a response by adding a new parameter
296
+
297
+ ```ts
298
+ import { PlatformResult, resultSchema } from '@empathyco/x-adapter-platform';
299
+ import { Result } from '@empathyco/x-types';
300
+
301
+ interface EmpathyDemoPlatformResult extends PlatformResult {
302
+ season: string;
303
+ }
304
+
305
+ declare module '@empathyco/x-types' {
306
+ export interface Result {
307
+ season: string;
308
+ }
309
+ }
310
+
311
+ resultSchema.$override<EmpathyDemoPlatformResult, Partial<Result>>({
312
+ season: 'season'
313
+ });
314
+ ```
315
+
316
+ <br>
317
+
318
+ ## Test
319
+
320
+ **Empathy Adapter Platform** features are tested using [Jest](https://jestjs.io/). You will find a
321
+ `__tests__` folder inside the `src` folder with tests for each of the endpoint calls, and also
322
+ inside each of the project's sections functionalities (`endpoint-adapters`, `mappers` and
323
+ `schemas`).
324
+
325
+ ```
326
+
327
+ npm test
328
+
329
+ ```
330
+
331
+ <br>
332
+
333
+ ## Changelog
334
+
335
+ [Changelog summary](https://github.com/empathyco/x/blob/main/packages/x-adapter-platform/CHANGELOG.md)
336
+
337
+ <br>
338
+
339
+ ## Contributing
340
+
341
+ To start contributing to the project, please take a look at our
342
+ **[Contributing Guide](https://github.com/empathyco/x/blob/HEAD/.github/CONTRIBUTING.md).** Take in
343
+ account that `x-adapter-platform` is developed using [Typescript](https://www.typescriptlang.org/),
344
+ so we recommend you to check it out.
345
+
346
+ <br>
347
+
348
+ ## License
349
+
350
+ [empathyco/x License](https://github.com/empathyco/x/blob/main/packages/x-adapter-platform/LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-adapter-platform",
3
- "version": "1.0.0-alpha.54",
3
+ "version": "1.0.0-alpha.56",
4
4
  "description": "A search client for the Empathy Platform API",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
@@ -38,14 +38,14 @@
38
38
  "prepublishOnly": "npm run build"
39
39
  },
40
40
  "dependencies": {
41
- "@empathyco/x-adapter": "^8.0.0-alpha.19",
42
- "@empathyco/x-types": "^10.0.0-alpha.52",
41
+ "@empathyco/x-adapter": "^8.0.0-alpha.20",
42
+ "@empathyco/x-types": "^10.0.0-alpha.54",
43
43
  "@empathyco/x-utils": "^1.0.0-alpha.13",
44
44
  "tslib": "~2.4.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@microsoft/api-documenter": "~7.19.27",
48
- "@microsoft/api-extractor": "~7.19.4",
48
+ "@microsoft/api-extractor": "~7.33.7",
49
49
  "@types/jest": "~27.0.3",
50
50
  "concurrently": "~7.6.0",
51
51
  "jest": "~27.3.1",
@@ -56,5 +56,5 @@
56
56
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
59
- "gitHead": "b5640ccccd296584a4775a8db625f9039b6025e9"
59
+ "gitHead": "0400d4cb34cc19653bd478ed54be48756ac2dd78"
60
60
  }