Skip to content

Commit

Permalink
search-core: Use Cached Endpoints
Browse files Browse the repository at this point in the history
This change updates the autocomplete LiveAPI endpoints that 
search-core provides so that it provides the cached version of
the endpoints. Using the cached endpoints helps improve
performance.

J=WAT-4442
TEST=manual, auto

Built test site with new change, saw that the cached endpoints
were being used.
Tests pass.
  • Loading branch information
mkouzel-yext authored Nov 20, 2024
1 parent 2b6bfc4 commit 2050135
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yext/search-core",
"version": "2.5.4",
"version": "2.5.5",
"description": "Typescript Networking Library for the Yext Search API",
"main": "./dist/commonjs/src/index.js",
"module": "./dist/esm/src/index.js",
Expand Down
15 changes: 13 additions & 2 deletions src/provideEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,26 @@ export class EndpointsFactory {
}
}

/** Provides the cached domain based on environment and cloud region. */
getCachedDomain() {
switch (this.cloudChoice){
case CloudChoice.GLOBAL_GCP:
return `https://${this.environment}-cdn-cached-gcp.${this.cloudRegion}.yextapis.com`;
case CloudChoice.GLOBAL_MULTI:
default:
return `https://${this.environment}-cdn-cached.${this.cloudRegion}.yextapis.com`;
}
}

/** Provides all endpoints based on environment and cloud region. */
getEndpoints() {
return {
universalSearch: `${this.getDomain()}/v2/accounts/me/search/query`,
verticalSearch: `${this.getDomain()}/v2/accounts/me/search/vertical/query`,
questionSubmission: `${this.getDomain()}/v2/accounts/me/createQuestion`,
status: 'https://answersstatus.pagescdn.com',
universalAutocomplete: `${this.getDomain()}/v2/accounts/me/search/autocomplete`,
verticalAutocomplete: `${this.getDomain()}/v2/accounts/me/search/vertical/autocomplete`,
universalAutocomplete: `${this.getCachedDomain()}/v2/accounts/me/search/autocomplete`,
verticalAutocomplete: `${this.getCachedDomain()}/v2/accounts/me/search/vertical/autocomplete`,
filterSearch: `${this.getDomain()}/v2/accounts/me/search/filtersearch`,
};
}
Expand Down
4 changes: 2 additions & 2 deletions tests/provideEndpointsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ it('Prod, US, GCP produces expected endpoint', () => {
cloudRegion: CloudRegion.US,
cloudChoice: CloudChoice.GLOBAL_GCP
}).getEndpoints();
expect(endPoints).toHaveProperty('universalAutocomplete', 'https://prod-cdn-gcp.us.yextapis.com/v2/accounts/me/search/autocomplete');
expect(endPoints).toHaveProperty('universalAutocomplete', 'https://prod-cdn-cached-gcp.us.yextapis.com/v2/accounts/me/search/autocomplete');
});

it('Prod, EU, Multi produces expected endpoint', () => {
Expand All @@ -34,7 +34,7 @@ it('Prod, EU, Multi produces expected endpoint', () => {
cloudRegion: CloudRegion.EU,
cloudChoice: CloudChoice.GLOBAL_MULTI
}).getEndpoints();
expect(endPoints).toHaveProperty('verticalAutocomplete', 'https://prod-cdn.eu.yextapis.com/v2/accounts/me/search/vertical/autocomplete');
expect(endPoints).toHaveProperty('verticalAutocomplete', 'https://prod-cdn-cached.eu.yextapis.com/v2/accounts/me/search/vertical/autocomplete');
});

it('Prod, EU, GCP produces expected endpoint', () => {
Expand Down

0 comments on commit 2050135

Please sign in to comment.