Skip to content

Commit

Permalink
Version 2.5.4
Browse files Browse the repository at this point in the history
**Changes:**

- Adds new cloudChoice config property #277
  • Loading branch information
Fondryext authored Sep 11, 2024
2 parents 8f0e835 + 3951cbd commit 2b6bfc4
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 7 deletions.
21 changes: 21 additions & 0 deletions docs/search-core.cloudchoice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [CloudChoice](./search-core.cloudchoice.md)

## CloudChoice enum

Defines the cloud choice of the API domains.

<b>Signature:</b>

```typescript
export declare enum CloudChoice
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| GLOBAL\_GCP | <code>&quot;GLOBAL-GCP&quot;</code> | |
| GLOBAL\_MULTI | <code>&quot;GLOBAL-MULTI&quot;</code> | |

1 change: 1 addition & 0 deletions docs/search-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
13 changes: 13 additions & 0 deletions docs/search-core.servingconfig.cloudchoice.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/search-core](./search-core.md) &gt; [ServingConfig](./search-core.servingconfig.md) &gt; [cloudChoice](./search-core.servingconfig.cloudchoice.md)

## ServingConfig.cloudChoice property

Defines the cloud choice of the API domains.

<b>Signature:</b>

```typescript
cloudChoice?: CloudChoice;
```
1 change: 1 addition & 0 deletions docs/search-core.servingconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ServingConfig

| Property | Type | Description |
| --- | --- | --- |
| [cloudChoice?](./search-core.servingconfig.cloudchoice.md) | [CloudChoice](./search-core.cloudchoice.md) | <i>(Optional)</i> Defines the cloud choice of the API domains. |
| [cloudRegion?](./search-core.servingconfig.cloudregion.md) | [CloudRegion](./search-core.cloudregion.md) | <i>(Optional)</i> Defines the cloud region of the API domains. |
| [environment?](./search-core.servingconfig.environment.md) | [Environment](./search-core.environment.md) | <i>(Optional)</i> Defines the environment of the API domains. |

9 changes: 9 additions & 0 deletions etc/search-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -699,6 +707,7 @@ export interface Segment {

// @public
export interface ServingConfig {
cloudChoice?: CloudChoice;
cloudRegion?: CloudRegion;
environment?: Environment;
}
Expand Down
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.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",
Expand Down
9 changes: 9 additions & 0 deletions src/models/core/CloudChoice.ts
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 9 additions & 2 deletions src/models/core/SearchConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -20,7 +21,13 @@ export interface ServingConfig {
*
* @public
*/
cloudRegion?: CloudRegion
cloudRegion?: CloudRegion,
/**
* {@inheritDoc CloudChoice}
*
* @public
*/
cloudChoice?: CloudChoice
}

/**
Expand Down Expand Up @@ -119,4 +126,4 @@ export type SearchConfig = SearchConfigWithApiKey | SearchConfigWithToken;
*
* @internal
*/
export type SearchConfigWithDefaulting = SearchConfig & { endpoints: Required<Endpoints> };
export type SearchConfigWithDefaulting = SearchConfig & { endpoints: Required<Endpoints> };
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
16 changes: 14 additions & 2 deletions src/provideEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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. */
Expand All @@ -46,5 +55,8 @@ export class EndpointsFactory {
* @public
*/
export const SandboxEndpoints: Required<Endpoints> =
new EndpointsFactory({ environment: Environment.SANDBOX, cloudRegion: CloudRegion.US })
new EndpointsFactory({
environment: Environment.SANDBOX,
cloudRegion: CloudRegion.US,
cloudChoice: CloudChoice.GLOBAL_MULTI })
.getEndpoints();
47 changes: 47 additions & 0 deletions tests/provideEndpointsTest.ts
Original file line number Diff line number Diff line change
@@ -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');
});

0 comments on commit 2b6bfc4

Please sign in to comment.