From 20501351f9e2b1dbe5b324ca5df295d99ceb89cd Mon Sep 17 00:00:00 2001 From: mkouzel-yext Date: Wed, 20 Nov 2024 10:22:32 -0500 Subject: [PATCH] search-core: Use Cached Endpoints 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. --- package-lock.json | 4 ++-- package.json | 2 +- src/provideEndpoints.ts | 15 +++++++++++++-- tests/provideEndpointsTest.ts | 4 ++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7c2b2589..741fce25 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@yext/search-core", - "version": "2.5.4", + "version": "2.5.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@yext/search-core", - "version": "2.5.4", + "version": "2.5.5", "license": "BSD-3-Clause", "dependencies": { "@babel/runtime-corejs3": "^7.12.5", diff --git a/package.json b/package.json index 60c0181b..61e21be8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/provideEndpoints.ts b/src/provideEndpoints.ts index e4dd966d..a512cf4c 100644 --- a/src/provideEndpoints.ts +++ b/src/provideEndpoints.ts @@ -33,6 +33,17 @@ 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 { @@ -40,8 +51,8 @@ export class EndpointsFactory { 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`, }; } diff --git a/tests/provideEndpointsTest.ts b/tests/provideEndpointsTest.ts index a2bb1900..f21421dd 100644 --- a/tests/provideEndpointsTest.ts +++ b/tests/provideEndpointsTest.ts @@ -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', () => { @@ -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', () => {