Skip to content

Commit

Permalink
Version 1.3 (#99)
Browse files Browse the repository at this point in the history
### Features
- Direct answers are now supported on vertical searches (#96)
- For universal searches, a limit for each vertical can now be supplied (#90) (#93)
- A session ID can now be supplied for vertical and universal searches (#94)
- A query source can now be an arbitrary string for vertical and universal searches (#95)
### Enhancements
- Question submissions are now sent to a new endpoint with higher availability (#98)
### Bugfixes
- Fixes a bug which caused cookies to not be sent properly (#97)
  • Loading branch information
cea2aj authored Aug 24, 2021
2 parents 19c773d + 67a3601 commit 98f272c
Show file tree
Hide file tree
Showing 32 changed files with 251 additions and 101 deletions.
2 changes: 1 addition & 1 deletion THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ THE SOFTWARE.

The following NPM packages may be included in this product:

- cross-fetch@3.0.6
- cross-fetch@3.1.4

These packages each contain the following license and notice below:

Expand Down
2 changes: 1 addition & 1 deletion api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
* DEFAULT VALUE: ""
*/
"publicTrimmedFilePath": "<projectFolder>/dist/bundle.d.ts"
"publicTrimmedFilePath": "<projectFolder>/dist/bundle.d.ts"

/**
* When a declaration is trimmed, by default it will be replaced by a code comment such as
Expand Down
1 change: 1 addition & 0 deletions docs/answers-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
| [SortBy](./answers-core.sortby.md) | Represents a criterion that can be used to sort results. |
| [SpellCheck](./answers-core.spellcheck.md) | A spellcheck response from a search query. |
| [UniversalAutocompleteRequest](./answers-core.universalautocompleterequest.md) | Options for a universal autocomplete request. |
| [UniversalLimit](./answers-core.universallimit.md) | The maximum limit of results per vertical. Each limit can be set from 1-50, inclusive. |
| [UniversalSearchRequest](./answers-core.universalsearchrequest.md) | Options which can be specified for a universal search. |
| [UniversalSearchResponse](./answers-core.universalsearchresponse.md) | A representation of a response from a universal search. |
| [VerticalAutocompleteRequest](./answers-core.verticalautocompleterequest.md) | Options for a vertial autocomplete request. |
Expand Down
18 changes: 18 additions & 0 deletions docs/answers-core.universallimit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/answers-core](./answers-core.md) &gt; [UniversalLimit](./answers-core.universallimit.md)

## UniversalLimit interface

The maximum limit of results per vertical. Each limit can be set from 1-50, inclusive.

<b>Signature:</b>

```typescript
export interface UniversalLimit
```

## Example

{ people: 5, locations: 10, events: 8 }

13 changes: 13 additions & 0 deletions docs/answers-core.universalsearchrequest.limit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/answers-core](./answers-core.md) &gt; [UniversalSearchRequest](./answers-core.universalsearchrequest.md) &gt; [limit](./answers-core.universalsearchrequest.limit.md)

## UniversalSearchRequest.limit property

The maximum limit of results per vertical. Each limit can be set from 1-50, inclusive.

<b>Signature:</b>

```typescript
limit?: UniversalLimit;
```
4 changes: 3 additions & 1 deletion docs/answers-core.universalsearchrequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export interface UniversalSearchRequest
| Property | Type | Description |
| --- | --- | --- |
| [context?](./answers-core.universalsearchrequest.context.md) | [Context](./answers-core.context.md) | <i>(Optional)</i> Used to trigger Answers [Query Rules](https://hitchhikers.yext.com/tracks/answers-advanced/ans302-query-rules/)<!-- -->. |
| [limit?](./answers-core.universalsearchrequest.limit.md) | [UniversalLimit](./answers-core.universallimit.md) | <i>(Optional)</i> The maximum limit of results per vertical. Each limit can be set from 1-50, inclusive. |
| [location?](./answers-core.universalsearchrequest.location.md) | [LatLong](./answers-core.latlong.md) | <i>(Optional)</i> The latitude and longitude of the user making the request. Used to bias the results. |
| [query](./answers-core.universalsearchrequest.query.md) | string | The search query. |
| [querySource?](./answers-core.universalsearchrequest.querysource.md) | [QuerySource](./answers-core.querysource.md) | <i>(Optional)</i> The source of the search request. |
| [querySource?](./answers-core.universalsearchrequest.querysource.md) | [QuerySource](./answers-core.querysource.md) \| string | <i>(Optional)</i> The source of the search request. |
| [queryTrigger?](./answers-core.universalsearchrequest.querytrigger.md) | [QueryTrigger](./answers-core.querytrigger.md) | <i>(Optional)</i> Describes the ways a search can be executed besides user input. |
| [referrerPageUrl?](./answers-core.universalsearchrequest.referrerpageurl.md) | string | <i>(Optional)</i> The URl of the page which referred the user to the current page. |
| [sessionId?](./answers-core.universalsearchrequest.sessionid.md) | string | <i>(Optional)</i> Used to track session state when cookies are blocked. |
| [sessionTrackingEnabled?](./answers-core.universalsearchrequest.sessiontrackingenabled.md) | boolean | <i>(Optional)</i> Enables session tracking. |
| [skipSpellCheck?](./answers-core.universalsearchrequest.skipspellcheck.md) | boolean | <i>(Optional)</i> Disables spellcheck if true. |

2 changes: 1 addition & 1 deletion docs/answers-core.universalsearchrequest.querysource.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The source of the search request.
<b>Signature:</b>

```typescript
querySource?: QuerySource;
querySource?: QuerySource | string;
```
13 changes: 13 additions & 0 deletions docs/answers-core.universalsearchrequest.sessionid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/answers-core](./answers-core.md) &gt; [UniversalSearchRequest](./answers-core.universalsearchrequest.md) &gt; [sessionId](./answers-core.universalsearchrequest.sessionid.md)

## UniversalSearchRequest.sessionId property

Used to track session state when cookies are blocked.

<b>Signature:</b>

```typescript
sessionId?: string;
```
3 changes: 2 additions & 1 deletion docs/answers-core.verticalsearchrequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ export interface VerticalSearchRequest
| [offset?](./answers-core.verticalsearchrequest.offset.md) | number | <i>(Optional)</i> The result offset which allows for fetching more results with the same query. |
| [query](./answers-core.verticalsearchrequest.query.md) | string | The search query. |
| [queryId?](./answers-core.verticalsearchrequest.queryid.md) | string | <i>(Optional)</i> The queryId for the query, if this is a repeat query. |
| [querySource?](./answers-core.verticalsearchrequest.querysource.md) | [QuerySource](./answers-core.querysource.md) | <i>(Optional)</i> The source of the search request. |
| [querySource?](./answers-core.verticalsearchrequest.querysource.md) | [QuerySource](./answers-core.querysource.md) \| string | <i>(Optional)</i> The source of the search request. |
| [queryTrigger?](./answers-core.verticalsearchrequest.querytrigger.md) | [QueryTrigger](./answers-core.querytrigger.md) | <i>(Optional)</i> Describes the ways a search can be executed besides user input. |
| [referrerPageUrl?](./answers-core.verticalsearchrequest.referrerpageurl.md) | string | <i>(Optional)</i> The URl of the page which referred the user to the current page. |
| [retrieveFacets?](./answers-core.verticalsearchrequest.retrievefacets.md) | boolean | <i>(Optional)</i> Indicates that facets should be retrieved. |
| [sessionId?](./answers-core.verticalsearchrequest.sessionid.md) | string | <i>(Optional)</i> Used to track session state when cookies are blocked. |
| [sessionTrackingEnabled?](./answers-core.verticalsearchrequest.sessiontrackingenabled.md) | boolean | <i>(Optional)</i> Enables session tracking. |
| [skipSpellCheck?](./answers-core.verticalsearchrequest.skipspellcheck.md) | boolean | <i>(Optional)</i> Skips spell checking if true. |
| [sortBys?](./answers-core.verticalsearchrequest.sortbys.md) | [SortBy](./answers-core.sortby.md)<!-- -->\[\] | <i>(Optional)</i> Determines how results are sorted. \* |
Expand Down
2 changes: 1 addition & 1 deletion docs/answers-core.verticalsearchrequest.querysource.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ The source of the search request.
<b>Signature:</b>

```typescript
querySource?: QuerySource;
querySource?: QuerySource | string;
```
13 changes: 13 additions & 0 deletions docs/answers-core.verticalsearchrequest.sessionid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/answers-core](./answers-core.md) &gt; [VerticalSearchRequest](./answers-core.verticalsearchrequest.md) &gt; [sessionId](./answers-core.verticalsearchrequest.sessionid.md)

## VerticalSearchRequest.sessionId property

Used to track session state when cookies are blocked.

<b>Signature:</b>

```typescript
sessionId?: string;
```
13 changes: 13 additions & 0 deletions docs/answers-core.verticalsearchresponse.directanswer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/answers-core](./answers-core.md) &gt; [VerticalSearchResponse](./answers-core.verticalsearchresponse.md) &gt; [directAnswer](./answers-core.verticalsearchresponse.directanswer.md)

## VerticalSearchResponse.directAnswer property

A direct answer to a search.

<b>Signature:</b>

```typescript
directAnswer?: FeaturedSnippetDirectAnswer | FieldValueDirectAnswer;
```
1 change: 1 addition & 0 deletions docs/answers-core.verticalsearchresponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface VerticalSearchResponse
| --- | --- | --- |
| [allResultsForVertical?](./answers-core.verticalsearchresponse.allresultsforvertical.md) | [VerticalSearchResponse](./answers-core.verticalsearchresponse.md) | <i>(Optional)</i> A representation of a response from a vertical search. |
| [alternativeVerticals?](./answers-core.verticalsearchresponse.alternativeverticals.md) | [VerticalResults](./answers-core.verticalresults.md)<!-- -->\[\] | <i>(Optional)</i> The [VerticalResults](./answers-core.verticalresults.md) for each search vertical. |
| [directAnswer?](./answers-core.verticalsearchresponse.directanswer.md) | [FeaturedSnippetDirectAnswer](./answers-core.featuredsnippetdirectanswer.md) \| [FieldValueDirectAnswer](./answers-core.fieldvaluedirectanswer.md) | <i>(Optional)</i> A direct answer to a search. |
| [facets?](./answers-core.verticalsearchresponse.facets.md) | [DisplayableFacet](./answers-core.displayablefacet.md)<!-- -->\[\] | <i>(Optional)</i> An array of [Facet](./answers-core.facet.md)<!-- -->s associated with the search results. |
| [locationBias?](./answers-core.verticalsearchresponse.locationbias.md) | [LocationBias](./answers-core.locationbias.md) | <i>(Optional)</i> Information about the user's location. |
| [queryId](./answers-core.verticalsearchresponse.queryid.md) | string | The ID of the query. |
Expand Down
14 changes: 12 additions & 2 deletions etc/answers-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,22 @@ export interface UniversalAutocompleteRequest {
sessionTrackingEnabled?: boolean;
}

// @public
export interface UniversalLimit {
// (undocumented)
[verticalKey: string]: number;
}

// @public
export interface UniversalSearchRequest {
context?: Context;
limit?: UniversalLimit;
location?: LatLong;
query: string;
querySource?: QuerySource;
querySource?: QuerySource | string;
queryTrigger?: QueryTrigger;
referrerPageUrl?: string;
sessionId?: string;
sessionTrackingEnabled?: boolean;
skipSpellCheck?: boolean;
}
Expand Down Expand Up @@ -415,10 +423,11 @@ export interface VerticalSearchRequest {
offset?: number;
query: string;
queryId?: string;
querySource?: QuerySource;
querySource?: QuerySource | string;
queryTrigger?: QueryTrigger;
referrerPageUrl?: string;
retrieveFacets?: boolean;
sessionId?: string;
sessionTrackingEnabled?: boolean;
skipSpellCheck?: boolean;
sortBys?: SortBy[];
Expand All @@ -430,6 +439,7 @@ export interface VerticalSearchRequest {
export interface VerticalSearchResponse {
allResultsForVertical?: VerticalSearchResponse;
alternativeVerticals?: VerticalResults[];
directAnswer?: FeaturedSnippetDirectAnswer | FieldValueDirectAnswer;
facets?: DisplayableFacet[];
locationBias?: LocationBias;
queryId: string;
Expand Down
24 changes: 4 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yext/answers-core",
"version": "1.2.0",
"version": "1.3.0",
"description": "Typescript Networking Library for the Yext Answers API",
"main": "./lib/commonjs/index.js",
"module": "./lib/esm/index.js",
Expand Down Expand Up @@ -54,15 +54,14 @@
"eslint": "^7.11.0",
"generate-license-file": "^1.1.0",
"jest": "^26.6.0",
"jest-fetch-mock": "^3.0.3",
"ts-loader": "^8.0.14",
"typescript": "^4.0.3",
"webpack": "^5.18.0",
"webpack-cli": "^4.4.0"
},
"dependencies": {
"@babel/runtime-corejs3": "^7.12.5",
"cross-fetch": "^3.0.6"
"cross-fetch": "^3.1.4"
},
"jest": {
"bail": 0,
Expand All @@ -74,15 +73,11 @@
"js",
"ts"
],
"setupFilesAfterEnv": [
"./tests/setup/setup.js"
],
"moduleDirectories": [
"node_modules",
"<rootDir>"
],
"testPathIgnorePatterns": [
"./tests/setup/setup.js",
"./tests/mocks/*"
],
"testMatch": [
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const defaultApiVersion = 20190101;
export const defaultEndpoints: Required<Endpoints> = {
universalSearch: 'https://liveapi.yext.com/v2/accounts/me/answers/query',
verticalSearch: 'https://liveapi.yext.com/v2/accounts/me/answers/vertical/query',
questionSubmission: 'https://api.yext.com/v2/accounts/me/createQuestion',
questionSubmission: 'https://liveapi.yext.com/v2/accounts/me/createQuestion',
status: 'https://answersstatus.pagescdn.com',
universalAutocomplete: 'https://liveapi-cached.yext.com/v2/accounts/me/answers/autocomplete',
verticalAutocomplete: 'https://liveapi-cached.yext.com/v2/accounts/me/answers/vertical/autocomplete',
Expand Down
29 changes: 15 additions & 14 deletions src/infra/HttpServiceImpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fetch from 'cross-fetch';
import crossFetch from 'cross-fetch';
import { addParamsToURL, sanitizeQueryParams } from '../utils/urlutils';
import { QueryParams } from '../models/http/params';
import { HttpService } from '../services/HttpService';
Expand All @@ -22,14 +22,11 @@ export class HttpServiceImpl implements HttpService {
get<T>(
url: string,
queryParams: QueryParams,
options?: RequestInit,
): Promise<T> {
const reqInitWithMethod = {
return this.fetch(url, queryParams, {
method: RequestMethods.GET,
...options
};
return this.fetch(url, queryParams, reqInitWithMethod)
.then(res => res.json());
credentials: 'include'
}).then(res => res.json());
}

/**
Expand All @@ -38,16 +35,17 @@ export class HttpServiceImpl implements HttpService {
post<T>(
url: string,
queryParams: QueryParams,
body: QueryParams,
reqInit: RequestInit
body: QueryParams
): Promise<T> {
const sanitizedBodyParams = sanitizeQueryParams(body);
const reqInitWithMethodAndBody = {
return this.fetch(url, queryParams, {
method: RequestMethods.POST,
body: JSON.stringify(sanitizedBodyParams),
...reqInit
};
return this.fetch(url, queryParams, reqInitWithMethodAndBody)
mode: 'cors',
headers: {
'Content-Type': 'application/json'
}
})
.then(res => res.json());
}

Expand All @@ -60,6 +58,9 @@ export class HttpServiceImpl implements HttpService {
reqInit: RequestInit
): Promise<Response> {
const urlWithParams = addParamsToURL(url, queryParams);
return fetch(urlWithParams, reqInit);
if (window.fetch) {
return window.fetch(urlWithParams, reqInit);
}
return crossFetch(urlWithParams, reqInit);
}
}
10 changes: 1 addition & 9 deletions src/infra/QuestionSubmissionServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,10 @@ export class QuestionSubmissionServiceImpl implements QuestionSubmissionService
site: 'FIRSTPARTY'
};

const requestInit = {
mode: 'cors' as RequestMode,
headers: {
'Content-Type': 'application/json'
}
};

const response = await this.httpService.post<ApiResponse>(
this.endpoint,
queryParams,
body,
requestInit
body
);

const validationResult = this.apiResponseValidator.validate(response);
Expand Down
Loading

0 comments on commit 98f272c

Please sign in to comment.