diff --git a/docs/search-core.basesearchconfig.cloudregion.md b/docs/search-core.basesearchconfig.cloudregion.md
new file mode 100644
index 00000000..6fe93ecb
--- /dev/null
+++ b/docs/search-core.basesearchconfig.cloudregion.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [@yext/search-core](./search-core.md) > [BaseSearchConfig](./search-core.basesearchconfig.md) > [cloudRegion](./search-core.basesearchconfig.cloudregion.md)
+
+## BaseSearchConfig.cloudRegion property
+
+Defines the cloud region of the API domains.
+
+Signature:
+
+```typescript
+cloudRegion?: CloudRegion;
+```
diff --git a/docs/search-core.basesearchconfig.environment.md b/docs/search-core.basesearchconfig.environment.md
new file mode 100644
index 00000000..6294b2f6
--- /dev/null
+++ b/docs/search-core.basesearchconfig.environment.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [@yext/search-core](./search-core.md) > [BaseSearchConfig](./search-core.basesearchconfig.md) > [environment](./search-core.basesearchconfig.environment.md)
+
+## BaseSearchConfig.environment property
+
+Defines the environment of the API domains.
+
+Signature:
+
+```typescript
+environment?: Environment;
+```
diff --git a/docs/search-core.basesearchconfig.md b/docs/search-core.basesearchconfig.md
index e3e2d413..db9b02da 100644
--- a/docs/search-core.basesearchconfig.md
+++ b/docs/search-core.basesearchconfig.md
@@ -4,20 +4,23 @@
## BaseSearchConfig interface
-The base configuration options for [SearchCore](./search-core.searchcore.md).
+The base configuration options for [SearchCore](./search-core.searchcore.md), which includes the options from [ServingConfig](./search-core.servingconfig.md).
Signature:
```typescript
-export interface BaseSearchConfig
+export interface BaseSearchConfig extends ServingConfig
```
+Extends: [ServingConfig](./search-core.servingconfig.md)
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [additionalQueryParams?](./search-core.basesearchconfig.additionalqueryparams.md) | { \[key: string\]: string \| number \| boolean; } | (Optional) Additional query params added on to every request. |
+| [cloudRegion?](./search-core.basesearchconfig.cloudregion.md) | [CloudRegion](./search-core.cloudregion.md) | (Optional) Defines the cloud region of the API domains. |
| [endpoints?](./search-core.basesearchconfig.endpoints.md) | [Endpoints](./search-core.endpoints.md) | (Optional) Overrides for the URLs which are used when making requests to the Search API. |
+| [environment?](./search-core.basesearchconfig.environment.md) | [Environment](./search-core.environment.md) | (Optional) Defines the environment of the API domains. |
| [experienceKey](./search-core.basesearchconfig.experiencekey.md) | string | The experience key of the search experience. |
| [experienceVersion?](./search-core.basesearchconfig.experienceversion.md) | 'STAGING' \| 'PRODUCTION' \| string \| number | (Optional) The version of the search experience configuration. |
| [locale](./search-core.basesearchconfig.locale.md) | string | The locale of the search experience. |
diff --git a/docs/search-core.cloudregion.md b/docs/search-core.cloudregion.md
new file mode 100644
index 00000000..e6db39bc
--- /dev/null
+++ b/docs/search-core.cloudregion.md
@@ -0,0 +1,21 @@
+
+
+[Home](./index.md) > [@yext/search-core](./search-core.md) > [CloudRegion](./search-core.cloudregion.md)
+
+## CloudRegion enum
+
+Defines the cloud region of the API domains.
+
+Signature:
+
+```typescript
+export declare enum CloudRegion
+```
+
+## Enumeration Members
+
+| Member | Value | Description |
+| --- | --- | --- |
+| EU | "eu"
| |
+| US | "us"
| |
+
diff --git a/docs/search-core.context.md b/docs/search-core.context.md
index 526795e2..78b28cba 100644
--- a/docs/search-core.context.md
+++ b/docs/search-core.context.md
@@ -9,7 +9,7 @@ Used to trigger Search [Query Rules](https://hitchhikers.yext.com/tracks/answers
Signature:
```typescript
-export declare type Context = any;
+export type Context = any;
```
## Remarks
diff --git a/docs/search-core.enumorliteral.md b/docs/search-core.enumorliteral.md
index 7dc80b4c..22b56c8c 100644
--- a/docs/search-core.enumorliteral.md
+++ b/docs/search-core.enumorliteral.md
@@ -9,5 +9,5 @@ Produces a union type from the enum passed as a generic which consists of the en
Signature:
```typescript
-export declare type EnumOrLiteral = T | `${T}`;
+export type EnumOrLiteral = T | `${T}`;
```
diff --git a/docs/search-core.environment.md b/docs/search-core.environment.md
new file mode 100644
index 00000000..238ee840
--- /dev/null
+++ b/docs/search-core.environment.md
@@ -0,0 +1,21 @@
+
+
+[Home](./index.md) > [@yext/search-core](./search-core.md) > [Environment](./search-core.environment.md)
+
+## Environment enum
+
+Defines the environment of the API domains.
+
+Signature:
+
+```typescript
+export declare enum Environment
+```
+
+## Enumeration Members
+
+| Member | Value | Description |
+| --- | --- | --- |
+| PROD | "prod"
| |
+| SANDBOX | "sbx"
| |
+
diff --git a/docs/search-core.featuredsnippetdirectanswer.md b/docs/search-core.featuredsnippetdirectanswer.md
index fb2a6e1f..dea968c5 100644
--- a/docs/search-core.featuredsnippetdirectanswer.md
+++ b/docs/search-core.featuredsnippetdirectanswer.md
@@ -9,7 +9,7 @@ All possible built-in [BaseFeaturedSnippetDirectAnswer](./search-core.basefeatur
Signature:
```typescript
-export declare type FeaturedSnippetDirectAnswer = MultiLineTextSnippetDirectAnswer | RichTextSnippetDirectAnswer;
+export type FeaturedSnippetDirectAnswer = MultiLineTextSnippetDirectAnswer | RichTextSnippetDirectAnswer;
```
References: [MultiLineTextSnippetDirectAnswer](./search-core.multilinetextsnippetdirectanswer.md), [RichTextSnippetDirectAnswer](./search-core.richtextsnippetdirectanswer.md)
diff --git a/docs/search-core.fieldvaluedirectanswer.md b/docs/search-core.fieldvaluedirectanswer.md
index 952a3fbb..eced3cb6 100644
--- a/docs/search-core.fieldvaluedirectanswer.md
+++ b/docs/search-core.fieldvaluedirectanswer.md
@@ -9,7 +9,7 @@ Possible built-in and custom [BaseFieldValueDirectAnswer](./search-core.basefiel
Signature:
```typescript
-export declare type FieldValueDirectAnswer = UnknownFieldValueDirectAnswer | TextDirectAnswer | UrlDirectAnswer | RichTextDirectAnswer | DecimalDirectAnswer | FacebookUrlDirectAnswer | InstagramHandleDirectAnswer | TwitterHandleDirectAnswer | IosAppUrlDirectAnswer | AndroidAppUrlDirectAnswer | ComplexUrlDirectAnswer | IntegerDirectAnswer | PhoneDirectAnswer | EmailDirectAnswer | AddressDirectAnswer | HoursDirectAnswer;
+export type FieldValueDirectAnswer = UnknownFieldValueDirectAnswer | TextDirectAnswer | UrlDirectAnswer | RichTextDirectAnswer | DecimalDirectAnswer | FacebookUrlDirectAnswer | InstagramHandleDirectAnswer | TwitterHandleDirectAnswer | IosAppUrlDirectAnswer | AndroidAppUrlDirectAnswer | ComplexUrlDirectAnswer | IntegerDirectAnswer | PhoneDirectAnswer | EmailDirectAnswer | AddressDirectAnswer | HoursDirectAnswer;
```
References: [UnknownFieldValueDirectAnswer](./search-core.unknownfieldvaluedirectanswer.md), [TextDirectAnswer](./search-core.textdirectanswer.md), [UrlDirectAnswer](./search-core.urldirectanswer.md), [RichTextDirectAnswer](./search-core.richtextdirectanswer.md), [DecimalDirectAnswer](./search-core.decimaldirectanswer.md), [FacebookUrlDirectAnswer](./search-core.facebookurldirectanswer.md), [InstagramHandleDirectAnswer](./search-core.instagramhandledirectanswer.md), [TwitterHandleDirectAnswer](./search-core.twitterhandledirectanswer.md), [IosAppUrlDirectAnswer](./search-core.iosappurldirectanswer.md), [AndroidAppUrlDirectAnswer](./search-core.androidappurldirectanswer.md), [ComplexUrlDirectAnswer](./search-core.complexurldirectanswer.md), [IntegerDirectAnswer](./search-core.integerdirectanswer.md), [PhoneDirectAnswer](./search-core.phonedirectanswer.md), [EmailDirectAnswer](./search-core.emaildirectanswer.md), [AddressDirectAnswer](./search-core.addressdirectanswer.md), [HoursDirectAnswer](./search-core.hoursdirectanswer.md)
diff --git a/docs/search-core.highlightedfields.md b/docs/search-core.highlightedfields.md
index a78aa79f..64a8d17e 100644
--- a/docs/search-core.highlightedfields.md
+++ b/docs/search-core.highlightedfields.md
@@ -9,7 +9,7 @@ A mapping of fields to the values emphasized by the Search API.
Signature:
```typescript
-export declare type HighlightedFields = {
+export type HighlightedFields = {
[fieldId: string]: HighlightedValue | HighlightedValue[] | HighlightedFields | HighlightedFields[];
};
```
diff --git a/docs/search-core.md b/docs/search-core.md
index 615f03a8..ceda135f 100644
--- a/docs/search-core.md
+++ b/docs/search-core.md
@@ -17,8 +17,10 @@
| --- | --- |
| [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). |
+| [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. |
+| [Environment](./search-core.environment.md) | Defines the environment of the API domains. |
| [ErrorType](./search-core.errortype.md) | Identifier for the type of error causing the failure. |
| [FilterCombinator](./search-core.filtercombinator.md) | Indicates how child filters in a [StaticFilter](./search-core.staticfilter.md) should be combined. |
| [LocationBiasMethod](./search-core.locationbiasmethod.md) | The method used to determine the location. |
@@ -50,7 +52,7 @@
| [AutocompleteService](./search-core.autocompleteservice.md) | A service for autocomplete requests. |
| [BaseFeaturedSnippetDirectAnswer](./search-core.basefeaturedsnippetdirectanswer.md) | A direct answer which was found within a document. |
| [BaseFieldValueDirectAnswer](./search-core.basefieldvaluedirectanswer.md) | A direct answer where the answer came from a field from the knowledge graph. |
-| [BaseSearchConfig](./search-core.basesearchconfig.md) | The base configuration options for [SearchCore](./search-core.searchcore.md). |
+| [BaseSearchConfig](./search-core.basesearchconfig.md) | The base configuration options for [SearchCore](./search-core.searchcore.md), which includes the options from [ServingConfig](./search-core.servingconfig.md). |
| [ClientSDKHeaderValues](./search-core.clientsdkheadervalues.md) | Additional agents and their versions used to create the Search experience. The information for these agents is added to the Client-SDK HTTP header along with that of the ANSWERS\_CORE agent. |
| [ComplexURL](./search-core.complexurl.md) | The shape of a [BuiltInFieldType.ComplexURL](./search-core.builtinfieldtype.md) DirectAnswer value |
| [ComplexUrlDirectAnswer](./search-core.complexurldirectanswer.md) | A direct answer for a complex url field. |
@@ -100,6 +102,7 @@
| [SearchParameterField](./search-core.searchparameterfield.md) | Indicates which entity field to perform the autocomplete request on. |
| [SearchRequest](./search-core.searchrequest.md) | Options for a Search API request. |
| [SearchService](./search-core.searchservice.md) | A service which performs Yext Search. |
+| [ServingConfig](./search-core.servingconfig.md) | The configuration options for getting the endpoints. |
| [Snippet](./search-core.snippet.md) | The section of text where a [FeaturedSnippetDirectAnswer](./search-core.featuredsnippetdirectanswer.md) was found. |
| [SortBy](./search-core.sortby.md) | Represents a criterion that can be used to sort results. |
| [SpellCheck](./search-core.spellcheck.md) | A spellcheck response from a search query. |
diff --git a/docs/search-core.sandboxendpoints.md b/docs/search-core.sandboxendpoints.md
index 4b28fa12..03769138 100644
--- a/docs/search-core.sandboxendpoints.md
+++ b/docs/search-core.sandboxendpoints.md
@@ -4,6 +4,11 @@
## SandboxEndpoints variable
+> Warning: This API is now obsolete.
+>
+> Use [provideCore()](./search-core.providecore.md) with the appropriate [ServingConfig](./search-core.servingconfig.md) instead
+>
+
The endpoints to use for sandbox experiences.
Signature:
diff --git a/docs/search-core.searchconfig.md b/docs/search-core.searchconfig.md
index 56d994c6..5d9997b2 100644
--- a/docs/search-core.searchconfig.md
+++ b/docs/search-core.searchconfig.md
@@ -9,7 +9,7 @@ The main configuration options for [SearchCore](./search-core.searchcore.md), [SearchConfigWithToken](./search-core.searchconfigwithtoken.md)
diff --git a/docs/search-core.servingconfig.cloudregion.md b/docs/search-core.servingconfig.cloudregion.md
new file mode 100644
index 00000000..b610eaf3
--- /dev/null
+++ b/docs/search-core.servingconfig.cloudregion.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [@yext/search-core](./search-core.md) > [ServingConfig](./search-core.servingconfig.md) > [cloudRegion](./search-core.servingconfig.cloudregion.md)
+
+## ServingConfig.cloudRegion property
+
+Defines the cloud region of the API domains.
+
+Signature:
+
+```typescript
+cloudRegion?: CloudRegion;
+```
diff --git a/docs/search-core.servingconfig.environment.md b/docs/search-core.servingconfig.environment.md
new file mode 100644
index 00000000..f8d8fce3
--- /dev/null
+++ b/docs/search-core.servingconfig.environment.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [@yext/search-core](./search-core.md) > [ServingConfig](./search-core.servingconfig.md) > [environment](./search-core.servingconfig.environment.md)
+
+## ServingConfig.environment property
+
+Defines the environment of the API domains.
+
+Signature:
+
+```typescript
+environment?: Environment;
+```
diff --git a/docs/search-core.servingconfig.md b/docs/search-core.servingconfig.md
new file mode 100644
index 00000000..233f2845
--- /dev/null
+++ b/docs/search-core.servingconfig.md
@@ -0,0 +1,21 @@
+
+
+[Home](./index.md) > [@yext/search-core](./search-core.md) > [ServingConfig](./search-core.servingconfig.md)
+
+## ServingConfig interface
+
+The configuration options for getting the endpoints.
+
+Signature:
+
+```typescript
+export interface ServingConfig
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [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/docs/search-core.staticfilter.md b/docs/search-core.staticfilter.md
index 757a6a6d..b2bdffba 100644
--- a/docs/search-core.staticfilter.md
+++ b/docs/search-core.staticfilter.md
@@ -9,7 +9,7 @@ Represents a static filter that will be used to refine results.
Signature:
```typescript
-export declare type StaticFilter = FieldValueStaticFilter | DisjunctionStaticFilter | ConjunctionStaticFilter;
+export type StaticFilter = FieldValueStaticFilter | DisjunctionStaticFilter | ConjunctionStaticFilter;
```
References: [FieldValueStaticFilter](./search-core.fieldvaluestaticfilter.md), [DisjunctionStaticFilter](./search-core.disjunctionstaticfilter.md), [ConjunctionStaticFilter](./search-core.conjunctionstaticfilter.md)
diff --git a/etc/search-core.api.md b/etc/search-core.api.md
index 68e326d1..a44ffbea 100644
--- a/etc/search-core.api.md
+++ b/etc/search-core.api.md
@@ -105,11 +105,13 @@ export interface BaseFieldValueDirectAnswer extends DirectAnswer
}
// @public
-export interface BaseSearchConfig {
+export interface BaseSearchConfig extends ServingConfig {
additionalQueryParams?: {
[key: string]: string | number | boolean;
};
+ cloudRegion?: CloudRegion;
endpoints?: Endpoints;
+ environment?: Environment;
experienceKey: string;
experienceVersion?: 'STAGING' | 'PRODUCTION' | string | number;
locale: string;
@@ -158,6 +160,14 @@ export interface ClientSDKHeaderValues {
ANSWERS_CORE?: never;
}
+// @public
+export enum CloudRegion {
+ // (undocumented)
+ EU = "eu",
+ // (undocumented)
+ US = "us"
+}
+
// @public
export interface ComplexURL {
// (undocumented)
@@ -266,6 +276,14 @@ export interface Endpoints {
// @public
export type EnumOrLiteral = T | `${T}`;
+// @public
+export enum Environment {
+ // (undocumented)
+ PROD = "prod",
+ // (undocumented)
+ SANDBOX = "sbx"
+}
+
// @public
export enum ErrorType {
BackendError = "BACKEND_ERROR",
@@ -581,7 +599,7 @@ export interface RichTextSnippetDirectAnswer extends Omit;
}
-// @public
+// @public @deprecated
export const SandboxEndpoints: Required;
// @public
@@ -642,6 +660,12 @@ export interface SearchService {
verticalSearch(request: VerticalSearchRequest): Promise;
}
+// @public
+export interface ServingConfig {
+ cloudRegion?: CloudRegion;
+ environment?: Environment;
+}
+
// @public
export interface Snippet {
matchedSubstrings: {
diff --git a/src/constants.ts b/src/constants.ts
deleted file mode 100644
index fed7d675..00000000
--- a/src/constants.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { Endpoints } from './models/core/Endpoints';
-
-export const defaultApiVersion = 20220511;
-
-export const defaultEndpoints: Required = {
- universalSearch: 'https://liveapi.yext.com/v2/accounts/me/search/query',
- verticalSearch: 'https://liveapi.yext.com/v2/accounts/me/search/vertical/query',
- questionSubmission: 'https://liveapi.yext.com/v2/accounts/me/createQuestion',
- status: 'https://answersstatus.pagescdn.com',
- universalAutocomplete: 'https://liveapi-cached.yext.com/v2/accounts/me/search/autocomplete',
- verticalAutocomplete: 'https://liveapi-cached.yext.com/v2/accounts/me/search/vertical/autocomplete',
- filterSearch: 'https://liveapi-cached.yext.com/v2/accounts/me/search/filtersearch',
-} as const;
-
-/**
- * The endpoints to use for sandbox experiences.
- *
- * @public
- */
-export const SandboxEndpoints: Required = {
- universalSearch: 'https://liveapi-sandbox.yext.com/v2/accounts/me/search/query',
- verticalSearch: 'https://liveapi-sandbox.yext.com/v2/accounts/me/search/vertical/query',
- questionSubmission: 'https://liveapi-sandbox.yext.com/v2/accounts/me/createQuestion',
- status: 'https://answersstatus.pagescdn.com',
- universalAutocomplete: 'https://liveapi-sandbox.yext.com/v2/accounts/me/search/autocomplete',
- verticalAutocomplete: 'https://liveapi-sandbox.yext.com/v2/accounts/me/search/vertical/autocomplete',
- filterSearch: 'https://liveapi-sandbox.yext.com/v2/accounts/me/search/filtersearch',
-} as const;
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index fcff8109..3c763909 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,6 +1,6 @@
// main symbols
export { SearchCore } from './SearchCore';
export { provideCore } from './provideCore';
-export { SandboxEndpoints } from './constants';
+export { SandboxEndpoints } from './provideEndpoints';
export * from './models';
export * from './services';
\ No newline at end of file
diff --git a/src/infra/AutocompleteServiceImpl.ts b/src/infra/AutocompleteServiceImpl.ts
index 6068ebde..5f0669eb 100644
--- a/src/infra/AutocompleteServiceImpl.ts
+++ b/src/infra/AutocompleteServiceImpl.ts
@@ -5,7 +5,7 @@ import {
UniversalAutocompleteRequest
} from '../models/autocompleteservice/AutocompleteRequest';
import { AutocompleteResponse, FilterSearchResponse } from '../models/autocompleteservice/AutocompleteResponse';
-import { defaultApiVersion } from '../constants';
+import { defaultApiVersion } from '../provideEndpoints';
import { SearchConfigWithDefaulting } from '../models/core/SearchConfig';
import { HttpService } from '../services/HttpService';
import { AutocompleteQueryParams } from '../models/autocompleteservice/AutocompleteQueryParams';
diff --git a/src/infra/QuestionSubmissionServiceImpl.ts b/src/infra/QuestionSubmissionServiceImpl.ts
index 5609da1d..9b63687c 100644
--- a/src/infra/QuestionSubmissionServiceImpl.ts
+++ b/src/infra/QuestionSubmissionServiceImpl.ts
@@ -1,4 +1,4 @@
-import { defaultApiVersion } from '../constants';
+import { defaultApiVersion } from '../provideEndpoints';
import { QuestionSubmissionService } from '../services/QuestionSubmissionService';
import { HttpService } from '../services/HttpService';
import { SearchConfigWithDefaulting } from '../models/core/SearchConfig';
diff --git a/src/infra/SearchServiceImpl.ts b/src/infra/SearchServiceImpl.ts
index 0355e8b7..053cad1f 100644
--- a/src/infra/SearchServiceImpl.ts
+++ b/src/infra/SearchServiceImpl.ts
@@ -1,6 +1,6 @@
import { createVerticalSearchResponse } from '../transformers/searchservice/createVerticalSearchResponse';
import { SearchService } from '../services/SearchService';
-import { defaultApiVersion } from '../constants';
+import { defaultApiVersion } from '../provideEndpoints';
import { QueryParams } from '../models/http/params';
import { QueryTrigger } from '../models/searchservice/request/QueryTrigger';
import { QuerySource } from '../models/searchservice/request/QuerySource';
diff --git a/src/models/core/CloudRegion.ts b/src/models/core/CloudRegion.ts
new file mode 100644
index 00000000..ea36ec02
--- /dev/null
+++ b/src/models/core/CloudRegion.ts
@@ -0,0 +1,9 @@
+/**
+ * Defines the cloud region of the API domains.
+ *
+ * @public
+ */
+export enum CloudRegion {
+ US = 'us',
+ EU = 'eu',
+}
\ No newline at end of file
diff --git a/src/models/core/Environment.ts b/src/models/core/Environment.ts
new file mode 100644
index 00000000..8db28830
--- /dev/null
+++ b/src/models/core/Environment.ts
@@ -0,0 +1,9 @@
+/**
+ * Defines the environment of the API domains.
+ *
+ * @public
+ */
+export enum Environment {
+ PROD = 'prod',
+ SANDBOX = 'sbx',
+}
\ No newline at end of file
diff --git a/src/models/core/SearchConfig.ts b/src/models/core/SearchConfig.ts
index ae6e2178..67e4fea2 100644
--- a/src/models/core/SearchConfig.ts
+++ b/src/models/core/SearchConfig.ts
@@ -1,11 +1,35 @@
import { Endpoints } from './Endpoints';
import { Visitor } from './Visitor';
+import { Environment } from './Environment';
+import { CloudRegion } from './CloudRegion';
/**
- * The base configuration options for {@link SearchCore}.
+ * The configuration options for getting the endpoints.
+ *
* @public
*/
-export interface BaseSearchConfig {
+export interface ServingConfig {
+ /**
+ * {@inheritDoc Environment}
+ *
+ * @public
+ */
+ environment?: Environment,
+ /**
+ * {@inheritDoc CloudRegion}
+ *
+ * @public
+ */
+ cloudRegion?: CloudRegion
+}
+
+/**
+ * The base configuration options for {@link SearchCore}, which includes the
+ * options from {@link ServingConfig}.
+ *
+ * @public
+ */
+export interface BaseSearchConfig extends ServingConfig {
/** The experience key of the search experience. */
experienceKey: string,
/** The locale of the search experience. */
@@ -35,7 +59,19 @@ export interface BaseSearchConfig {
*/
additionalQueryParams?: {
[key: string]: string | number | boolean
- }
+ },
+ /**
+ * {@inheritDoc Environment}
+ *
+ * @public
+ */
+ environment?: Environment,
+ /**
+ * {@inheritDoc CloudRegion}
+ *
+ * @public
+ */
+ cloudRegion?: CloudRegion
}
/**
diff --git a/src/models/index.ts b/src/models/index.ts
index 023f7576..2c095d9c 100644
--- a/src/models/index.ts
+++ b/src/models/index.ts
@@ -3,6 +3,7 @@ export { SearchError } from './searchapi/SearchError';
// Core models
export {
+ ServingConfig,
SearchConfig,
BaseSearchConfig,
SearchConfigWithApiKey,
@@ -15,6 +16,8 @@ export {
AdditionalHttpHeaders,
ClientSDKHeaderValues
} from './core/AdditionalHttpHeaders';
+export { Environment } from './core/Environment';
+export { CloudRegion } from './core/CloudRegion';
// Autocomplete service
export * from './autocompleteservice/AutocompleteRequest';
diff --git a/src/provideCore.ts b/src/provideCore.ts
index be1aac89..d69bec1a 100644
--- a/src/provideCore.ts
+++ b/src/provideCore.ts
@@ -5,7 +5,7 @@ import { SearchConfig, SearchConfigWithDefaulting } from './models/core/SearchCo
import { AutocompleteServiceImpl } from './infra/AutocompleteServiceImpl';
import { ApiResponseValidator } from './validation/ApiResponseValidator';
import { SearchCore } from './SearchCore';
-import { defaultEndpoints } from './constants';
+import { EndpointsFactory } from './provideEndpoints';
/**
* The entrypoint to the search-core library.
@@ -25,7 +25,7 @@ export function provideCore(config: SearchConfig): SearchCore {
const defaultedConfig: SearchConfigWithDefaulting = {
...config,
endpoints: {
- ...defaultEndpoints,
+ ...new EndpointsFactory(config).getEndpoints(),
...config.endpoints
}
};
diff --git a/src/provideEndpoints.ts b/src/provideEndpoints.ts
new file mode 100644
index 00000000..b8dc77e0
--- /dev/null
+++ b/src/provideEndpoints.ts
@@ -0,0 +1,64 @@
+import { Endpoints } from './models/core/Endpoints';
+import { Environment } from './models/core/Environment';
+import { CloudRegion } from './models/core/CloudRegion';
+import { ServingConfig } from './models/core/SearchConfig';
+
+export const defaultApiVersion = 20220511;
+
+/**
+ * Provides methods for getting various endpoints.
+ *
+ * @internal
+ */
+export class EndpointsFactory {
+ private readonly environment: Environment;
+ private readonly cloudRegion: CloudRegion;
+
+ constructor(config?: ServingConfig) {
+ this.environment = config?.environment || Environment.PROD;
+ this.cloudRegion = config?.cloudRegion || CloudRegion.US;
+ }
+
+ /** Provides the domain based on environment and cloud region. */
+ getDomain() {
+ return `https://${this.environment}-cdn.${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`,
+ filterSearch: `${this.getDomain()}/v2/accounts/me/search/filtersearch`,
+ };
+ }
+}
+
+/**
+ * The endpoints to use for sandbox experiences.
+ *
+ * @deprecated Use {@link provideCore} with the appropriate {@link ServingConfig} instead
+ *
+ * @public
+ */
+export const SandboxEndpoints: Required =
+ new EndpointsFactory({ environment: Environment.SANDBOX, cloudRegion: CloudRegion.US })
+ .getEndpoints();
+
+/**
+ * Provides all endpoints based on environment and cloud region.
+ *
+ * @remarks
+ * Returns an {@link Endpoints} instance.
+ *
+ * @param config - serving config to use for the domain, defaults to Prod and US if not provided.
+ *
+ * @public
+ */
+export function provideEndpoints(config?: ServingConfig): Required {
+ return new EndpointsFactory(config).getEndpoints();
+}
diff --git a/tests/infra/AutocompleteServiceImpl.ts b/tests/infra/AutocompleteServiceImpl.ts
index 5d2838ee..12b2be08 100644
--- a/tests/infra/AutocompleteServiceImpl.ts
+++ b/tests/infra/AutocompleteServiceImpl.ts
@@ -11,12 +11,15 @@ import mockAutocompleteResponse from '../fixtures/autocompleteresponse.json';
import mockAutocompleteResponseWithSections from '../fixtures/autocompleteresponsewithsections.json';
import mockAutocompleteResponseWithFailedVerticals from '../fixtures/autocompleteresponsewithfailedverticals.json';
import mockAutocompleteResponseWithVerticalKeys from '../fixtures/autocompleteresponsewithverticalkeys.json';
-import { defaultEndpoints, defaultApiVersion } from '../../src/constants';
+import { defaultApiVersion, EndpointsFactory } from '../../src/provideEndpoints';
import { ApiResponseValidator } from '../../src/validation/ApiResponseValidator';
import { ApiResponse } from '../../src/models/searchapi/ApiResponse';
import { SearchError } from '../../src/models/searchapi/SearchError';
import { getClientSdk } from '../../src/utils/getClientSdk';
import { Matcher } from '../../src/models/searchservice/common/Matcher';
+import { Endpoints } from '../../src/models/core/Endpoints';
+
+const defaultEndpoints: Required = new EndpointsFactory().getEndpoints();
describe('AutocompleteService', () => {
const config: SearchConfigWithDefaulting = {
diff --git a/tests/infra/QuestionSubmissionServiceImpl.ts b/tests/infra/QuestionSubmissionServiceImpl.ts
index 87933a2a..f355b9fc 100644
--- a/tests/infra/QuestionSubmissionServiceImpl.ts
+++ b/tests/infra/QuestionSubmissionServiceImpl.ts
@@ -3,14 +3,14 @@ import { HttpServiceMock } from '../mocks/HttpServiceMock';
import { HttpService } from '../../src/services/HttpService';
import { SearchConfigWithDefaulting } from '../../src/models/core/SearchConfig';
import { ApiResponseValidator } from '../../src/validation/ApiResponseValidator';
-import { defaultApiVersion, defaultEndpoints } from '../../src/constants';
+import { defaultApiVersion, EndpointsFactory } from '../../src/provideEndpoints';
const baseCoreConfig = {
apiKey: 'anApiKey',
experienceKey: 'anExperienceKey',
locale: 'fr',
experienceVersion: 'STAGING',
- endpoints: defaultEndpoints
+ endpoints: new EndpointsFactory().getEndpoints()
};
const qaRequest = {
@@ -42,7 +42,7 @@ describe('Question submission', () => {
});
it('uses the production endpoint by default', () => {
- const expectedUrl = 'https://liveapi.yext.com/v2/accounts/me/createQuestion';
+ const expectedUrl = 'https://prod-cdn.us.yextapis.com/v2/accounts/me/createQuestion';
const actualUrl = actualHttpParams[0];
expect(expectedUrl).toEqual(actualUrl);
});
diff --git a/tests/infra/SearchServiceImpl.ts b/tests/infra/SearchServiceImpl.ts
index 5460b3eb..8c5181b6 100644
--- a/tests/infra/SearchServiceImpl.ts
+++ b/tests/infra/SearchServiceImpl.ts
@@ -11,7 +11,10 @@ import { Matcher } from '../../src/models/searchservice/common/Matcher';
import { Direction } from '../../src/models/searchservice/request/Direction';
import { SortType } from '../../src/models/searchservice/request/SortType';
import { getClientSdk } from '../../src/utils/getClientSdk';
-import { defaultApiVersion, defaultEndpoints } from '../../src/constants';
+import { defaultApiVersion, EndpointsFactory } from '../../src/provideEndpoints';
+import { Endpoints } from '../../src/models/core/Endpoints';
+
+const defaultEndpoints: Required = new EndpointsFactory().getEndpoints();
describe('SearchService', () => {
const configWithRequiredApiKey: SearchConfigWithDefaulting = {
@@ -74,7 +77,7 @@ describe('SearchService', () => {
});
describe('Universal Search', () => {
- const expectedUniversalUrl = 'https://liveapi.yext.com/v2/accounts/me/search/query';
+ const expectedUniversalUrl = 'https://prod-cdn.us.yextapis.com/v2/accounts/me/search/query';
it('Query params are correct when only required params (without token) are supplied', async () => {
const requestWithRequiredParams: UniversalSearchRequest = {
@@ -157,10 +160,7 @@ describe('SearchService', () => {
const customUrl = 'http://custom.endpoint.com/api';
const config: SearchConfigWithDefaulting = {
...configWithRequiredApiKey,
- endpoints: {
- ...defaultEndpoints,
- universalSearch: customUrl
- }
+ endpoints: { ...defaultEndpoints, universalSearch: customUrl }
};
const searchService: SearchServiceImpl = new SearchServiceImpl(
config,
@@ -200,7 +200,7 @@ describe('SearchService', () => {
});
describe('Vertical Search', () => {
- const expectedVerticalUrl = 'https://liveapi.yext.com/v2/accounts/me/search/vertical/query';
+ const expectedVerticalUrl = 'https://prod-cdn.us.yextapis.com/v2/accounts/me/search/vertical/query';
it('Query params are correct when only required params (without token) are supplied', async () => {
const requestWithRequiredParams: VerticalSearchRequest = {
diff --git a/tests/provideCore.ts b/tests/provideCore.ts
index 92615fdb..2370d646 100644
--- a/tests/provideCore.ts
+++ b/tests/provideCore.ts
@@ -1,4 +1,4 @@
-import { SandboxEndpoints } from '../src/constants';
+import { EndpointsFactory } from '../src/provideEndpoints';
import { AutocompleteServiceImpl } from '../src/infra/AutocompleteServiceImpl';
import { QuestionSubmissionServiceImpl } from '../src/infra/QuestionSubmissionServiceImpl';
import { SearchServiceImpl } from '../src/infra/SearchServiceImpl';
@@ -12,7 +12,7 @@ jest.mock('../src/infra/SearchServiceImpl');
it('can specify custom endpoints', () => {
const customEndPoints: Required = {
- ...SandboxEndpoints,
+ ...new EndpointsFactory().getEndpoints(),
verticalSearch: ''
};