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', () => {