From 3951cbd7ac9fe951d72834692712b6cf46612f72 Mon Sep 17 00:00:00 2001 From: Fondryext <160865254+Fondryext@users.noreply.github.com> Date: Wed, 11 Sep 2024 10:07:42 -0400 Subject: [PATCH] search-core: add cloudChoice enum and config support (#277) This PR adds the new cloudChoice config property, to allow choosing either all consumer serving regions, or just the ones backed by GCP. By default the Multi option will be used, so default behavior is unchanged. J=WAT-4374 TEST=auto Added new test class --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- docs/search-core.cloudchoice.md | 21 +++++++++ docs/search-core.md | 1 + docs/search-core.servingconfig.cloudchoice.md | 13 +++++ docs/search-core.servingconfig.md | 1 + etc/search-core.api.md | 9 ++++ package-lock.json | 4 +- package.json | 2 +- src/models/core/CloudChoice.ts | 9 ++++ src/models/core/SearchConfig.ts | 11 ++++- src/models/index.ts | 1 + src/provideEndpoints.ts | 16 ++++++- tests/provideEndpointsTest.ts | 47 +++++++++++++++++++ 12 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 docs/search-core.cloudchoice.md create mode 100644 docs/search-core.servingconfig.cloudchoice.md create mode 100644 src/models/core/CloudChoice.ts create mode 100644 tests/provideEndpointsTest.ts diff --git a/docs/search-core.cloudchoice.md b/docs/search-core.cloudchoice.md new file mode 100644 index 00000000..d1102d14 --- /dev/null +++ b/docs/search-core.cloudchoice.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [CloudChoice](./search-core.cloudchoice.md) + +## CloudChoice enum + +Defines the cloud choice of the API domains. + +Signature: + +```typescript +export declare enum CloudChoice +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| GLOBAL\_GCP | "GLOBAL-GCP" | | +| GLOBAL\_MULTI | "GLOBAL-MULTI" | | + diff --git a/docs/search-core.md b/docs/search-core.md index 3ca5a1c9..a36f8cc3 100644 --- a/docs/search-core.md +++ b/docs/search-core.md @@ -17,6 +17,7 @@ | --- | --- | | [AppliedQueryFilterType](./search-core.appliedqueryfiltertype.md) | Represents the type of [AppliedQueryFilter](./search-core.appliedqueryfilter.md) applied to a search. | | [BuiltInFieldType](./search-core.builtinfieldtype.md) | Possible built-in field types for [DirectAnswer.fieldType](./search-core.directanswer.fieldtype.md). | +| [CloudChoice](./search-core.cloudchoice.md) | Defines the cloud choice of the API domains. | | [CloudRegion](./search-core.cloudregion.md) | Defines the cloud region of the API domains. | | [DirectAnswerType](./search-core.directanswertype.md) | Represents the type of direct answer. | | [Direction](./search-core.direction.md) | The direction of a sort. | diff --git a/docs/search-core.servingconfig.cloudchoice.md b/docs/search-core.servingconfig.cloudchoice.md new file mode 100644 index 00000000..38c42cee --- /dev/null +++ b/docs/search-core.servingconfig.cloudchoice.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [ServingConfig](./search-core.servingconfig.md) > [cloudChoice](./search-core.servingconfig.cloudchoice.md) + +## ServingConfig.cloudChoice property + +Defines the cloud choice of the API domains. + +Signature: + +```typescript +cloudChoice?: CloudChoice; +``` diff --git a/docs/search-core.servingconfig.md b/docs/search-core.servingconfig.md index 233f2845..6d6a056c 100644 --- a/docs/search-core.servingconfig.md +++ b/docs/search-core.servingconfig.md @@ -16,6 +16,7 @@ export interface ServingConfig | Property | Type | Description | | --- | --- | --- | +| [cloudChoice?](./search-core.servingconfig.cloudchoice.md) | [CloudChoice](./search-core.cloudchoice.md) | (Optional) Defines the cloud choice of the API domains. | | [cloudRegion?](./search-core.servingconfig.cloudregion.md) | [CloudRegion](./search-core.cloudregion.md) | (Optional) Defines the cloud region of the API domains. | | [environment?](./search-core.servingconfig.environment.md) | [Environment](./search-core.environment.md) | (Optional) Defines the environment of the API domains. | diff --git a/etc/search-core.api.md b/etc/search-core.api.md index 1435c291..d56e9bf6 100644 --- a/etc/search-core.api.md +++ b/etc/search-core.api.md @@ -166,6 +166,14 @@ export interface ClientSDKHeaderValues { ANSWERS_CORE?: never; } +// @public +export enum CloudChoice { + // (undocumented) + GLOBAL_GCP = "GLOBAL-GCP", + // (undocumented) + GLOBAL_MULTI = "GLOBAL-MULTI" +} + // @public export enum CloudRegion { // (undocumented) @@ -699,6 +707,7 @@ export interface Segment { // @public export interface ServingConfig { + cloudChoice?: CloudChoice; cloudRegion?: CloudRegion; environment?: Environment; } diff --git a/package-lock.json b/package-lock.json index 541c6f5a..7c2b2589 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@yext/search-core", - "version": "2.5.3", + "version": "2.5.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@yext/search-core", - "version": "2.5.3", + "version": "2.5.4", "license": "BSD-3-Clause", "dependencies": { "@babel/runtime-corejs3": "^7.12.5", diff --git a/package.json b/package.json index a40aa9f4..60c0181b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yext/search-core", - "version": "2.5.3", + "version": "2.5.4", "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/models/core/CloudChoice.ts b/src/models/core/CloudChoice.ts new file mode 100644 index 00000000..881fad7a --- /dev/null +++ b/src/models/core/CloudChoice.ts @@ -0,0 +1,9 @@ +/** + * Defines the cloud choice of the API domains. + * + * @public + */ +export enum CloudChoice { + GLOBAL_MULTI = 'GLOBAL-MULTI', //All available cloud regions + GLOBAL_GCP = 'GLOBAL-GCP', //Only available GCP-backed cloud regions +} diff --git a/src/models/core/SearchConfig.ts b/src/models/core/SearchConfig.ts index 67e4fea2..9b4c50a5 100644 --- a/src/models/core/SearchConfig.ts +++ b/src/models/core/SearchConfig.ts @@ -2,6 +2,7 @@ import { Endpoints } from './Endpoints'; import { Visitor } from './Visitor'; import { Environment } from './Environment'; import { CloudRegion } from './CloudRegion'; +import { CloudChoice } from './CloudChoice'; /** * The configuration options for getting the endpoints. @@ -20,7 +21,13 @@ export interface ServingConfig { * * @public */ - cloudRegion?: CloudRegion + cloudRegion?: CloudRegion, + /** + * {@inheritDoc CloudChoice} + * + * @public + */ + cloudChoice?: CloudChoice } /** @@ -119,4 +126,4 @@ export type SearchConfig = SearchConfigWithApiKey | SearchConfigWithToken; * * @internal */ -export type SearchConfigWithDefaulting = SearchConfig & { endpoints: Required }; \ No newline at end of file +export type SearchConfigWithDefaulting = SearchConfig & { endpoints: Required }; diff --git a/src/models/index.ts b/src/models/index.ts index 369e4a4f..7ac79c4d 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -18,6 +18,7 @@ export { } from './core/AdditionalHttpHeaders'; export { Environment } from './core/Environment'; export { CloudRegion } from './core/CloudRegion'; +export { CloudChoice } from './core/CloudChoice'; // Autocomplete service export * from './autocompleteservice/AutocompleteRequest'; diff --git a/src/provideEndpoints.ts b/src/provideEndpoints.ts index 11b0ad9f..e4dd966d 100644 --- a/src/provideEndpoints.ts +++ b/src/provideEndpoints.ts @@ -2,6 +2,7 @@ import { Endpoints } from './models/core/Endpoints'; import { Environment } from './models/core/Environment'; import { CloudRegion } from './models/core/CloudRegion'; import { ServingConfig } from './models/core/SearchConfig'; +import { CloudChoice } from './models/core/CloudChoice'; export const defaultApiVersion = 20220511; @@ -13,15 +14,23 @@ export const defaultApiVersion = 20220511; export class EndpointsFactory { private readonly environment: Environment; private readonly cloudRegion: CloudRegion; + private readonly cloudChoice: CloudChoice; constructor(config?: ServingConfig) { this.environment = config?.environment || Environment.PROD; this.cloudRegion = config?.cloudRegion || CloudRegion.US; + this.cloudChoice = config?.cloudChoice || CloudChoice.GLOBAL_MULTI; } /** Provides the domain based on environment and cloud region. */ getDomain() { - return `https://${this.environment}-cdn.${this.cloudRegion}.yextapis.com`; + switch (this.cloudChoice){ + case CloudChoice.GLOBAL_GCP: + return `https://${this.environment}-cdn-gcp.${this.cloudRegion}.yextapis.com`; + case CloudChoice.GLOBAL_MULTI: + default: + return `https://${this.environment}-cdn.${this.cloudRegion}.yextapis.com`; + } } /** Provides all endpoints based on environment and cloud region. */ @@ -46,5 +55,8 @@ export class EndpointsFactory { * @public */ export const SandboxEndpoints: Required = - new EndpointsFactory({ environment: Environment.SANDBOX, cloudRegion: CloudRegion.US }) + new EndpointsFactory({ + environment: Environment.SANDBOX, + cloudRegion: CloudRegion.US, + cloudChoice: CloudChoice.GLOBAL_MULTI }) .getEndpoints(); diff --git a/tests/provideEndpointsTest.ts b/tests/provideEndpointsTest.ts new file mode 100644 index 00000000..a2bb1900 --- /dev/null +++ b/tests/provideEndpointsTest.ts @@ -0,0 +1,47 @@ +import { EndpointsFactory } from '../src/provideEndpoints'; +import { CloudChoice, CloudRegion, Environment } from '../src'; + +it('Sandbox, US, Multi produces expected endpoint', () => { + const endPoints = new EndpointsFactory({ + environment: Environment.SANDBOX, + cloudRegion: CloudRegion.US, + cloudChoice: CloudChoice.GLOBAL_MULTI + }).getEndpoints(); + expect(endPoints).toHaveProperty('universalSearch', 'https://sbx-cdn.us.yextapis.com/v2/accounts/me/search/query'); +}); + +it('Prod, US, Multi produces expected endpoint', () => { + const endPoints = new EndpointsFactory({ + environment: Environment.PROD, + cloudRegion: CloudRegion.US, + cloudChoice: CloudChoice.GLOBAL_MULTI + }).getEndpoints(); + expect(endPoints).toHaveProperty('verticalSearch', 'https://prod-cdn.us.yextapis.com/v2/accounts/me/search/vertical/query'); +}); + +it('Prod, US, GCP produces expected endpoint', () => { + const endPoints = new EndpointsFactory({ + environment: Environment.PROD, + cloudRegion: CloudRegion.US, + cloudChoice: CloudChoice.GLOBAL_GCP + }).getEndpoints(); + expect(endPoints).toHaveProperty('universalAutocomplete', 'https://prod-cdn-gcp.us.yextapis.com/v2/accounts/me/search/autocomplete'); +}); + +it('Prod, EU, Multi produces expected endpoint', () => { + const endPoints = new EndpointsFactory({ + environment: Environment.PROD, + cloudRegion: CloudRegion.EU, + cloudChoice: CloudChoice.GLOBAL_MULTI + }).getEndpoints(); + expect(endPoints).toHaveProperty('verticalAutocomplete', 'https://prod-cdn.eu.yextapis.com/v2/accounts/me/search/vertical/autocomplete'); +}); + +it('Prod, EU, GCP produces expected endpoint', () => { + const endPoints = new EndpointsFactory({ + environment: Environment.PROD, + cloudRegion: CloudRegion.EU, + cloudChoice: CloudChoice.GLOBAL_GCP + }).getEndpoints(); + expect(endPoints).toHaveProperty('filterSearch', 'https://prod-cdn-gcp.eu.yextapis.com/v2/accounts/me/search/filtersearch'); +});