From fb44cdc09759e06f1d97fde24417a604de379bcc Mon Sep 17 00:00:00 2001 From: Emily Zhang Date: Thu, 4 May 2023 12:41:31 -0400 Subject: [PATCH] Create ServingConfig and update name Change-Id: I40c3c538871a5a14e9ff8fd7c79617d99369781c --- docs/search-core.basesearchconfig.md | 3 +- docs/search-core.cloudregion.md | 21 --------- docs/search-core.environment.md | 21 --------- docs/search-core.md | 5 +-- docs/search-core.provideendpoints.md | 5 +-- docs/search-core.servingconfig.cloudregion.md | 12 +++++ docs/search-core.servingconfig.environment.md | 12 +++++ docs/search-core.servingconfig.md | 21 +++++++++ etc/search-core.api.md | 34 +++++++------- src/index.ts | 2 +- src/models/core/CloudRegion.ts | 9 ++++ src/models/core/Environment.ts | 9 ++++ src/models/core/SearchConfig.ts | 24 +++++++++- src/models/index.ts | 1 + src/provideCore.ts | 2 +- src/provideEndpoints.ts | 44 +++++-------------- 16 files changed, 123 insertions(+), 102 deletions(-) delete mode 100644 docs/search-core.cloudregion.md delete mode 100644 docs/search-core.environment.md create mode 100644 docs/search-core.servingconfig.cloudregion.md create mode 100644 docs/search-core.servingconfig.environment.md create mode 100644 docs/search-core.servingconfig.md create mode 100644 src/models/core/CloudRegion.ts create mode 100644 src/models/core/Environment.ts diff --git a/docs/search-core.basesearchconfig.md b/docs/search-core.basesearchconfig.md index e3e2d413..716e7b21 100644 --- a/docs/search-core.basesearchconfig.md +++ b/docs/search-core.basesearchconfig.md @@ -9,8 +9,9 @@ The base configuration options for [SearchCore](./search-core.searchcore.md) - -[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.environment.md b/docs/search-core.environment.md deleted file mode 100644 index 238ee840..00000000 --- a/docs/search-core.environment.md +++ /dev/null @@ -1,21 +0,0 @@ - - -[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.md b/docs/search-core.md index 5ff6ad3c..250595a0 100644 --- a/docs/search-core.md +++ b/docs/search-core.md @@ -17,10 +17,8 @@ | --- | --- | | [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. | @@ -37,7 +35,7 @@ | Function | Description | | --- | --- | | [provideCore(config)](./search-core.providecore.md) | The entrypoint to the search-core library. | -| [provideEndpoints(environment, cloudRegion)](./search-core.provideendpoints.md) | Provides all endpoints based on environment and cloud region. | +| [provideEndpoints(config)](./search-core.provideendpoints.md) | Provides all endpoints based on environment and cloud region. | ## Interfaces @@ -103,6 +101,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 [provideEndpoints()](./search-core.provideendpoints.md). | | [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.provideendpoints.md b/docs/search-core.provideendpoints.md index bf7e5d31..f3e1d5c5 100644 --- a/docs/search-core.provideendpoints.md +++ b/docs/search-core.provideendpoints.md @@ -9,15 +9,14 @@ Provides all endpoints based on environment and cloud region. Signature: ```typescript -export declare function provideEndpoints(environment?: Environment, cloudRegion?: CloudRegion): Required; +export declare function provideEndpoints(config?: ServingConfig): Required; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| environment | [Environment](./search-core.environment.md) | environment of the domain to use, defaults to prod if not provided | -| cloudRegion | [CloudRegion](./search-core.cloudregion.md) | cloud region of the domain to use, defaults to us if not provided | +| config | [ServingConfig](./search-core.servingconfig.md) | serving config to use for the domain, defaults to Prod and US if not provided. | Returns: diff --git a/docs/search-core.servingconfig.cloudregion.md b/docs/search-core.servingconfig.cloudregion.md new file mode 100644 index 00000000..a9150f8d --- /dev/null +++ b/docs/search-core.servingconfig.cloudregion.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [ServingConfig](./search-core.servingconfig.md) > [cloudRegion](./search-core.servingconfig.cloudregion.md) + +## ServingConfig.cloudRegion property + + +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..15c07711 --- /dev/null +++ b/docs/search-core.servingconfig.environment.md @@ -0,0 +1,12 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [ServingConfig](./search-core.servingconfig.md) > [environment](./search-core.servingconfig.environment.md) + +## ServingConfig.environment property + + +Signature: + +```typescript +environment?: Environment; +``` diff --git a/docs/search-core.servingconfig.md b/docs/search-core.servingconfig.md new file mode 100644 index 00000000..a6eb0035 --- /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 [provideEndpoints()](./search-core.provideendpoints.md). + +Signature: + +```typescript +export interface ServingConfig +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [cloudRegion?](./search-core.servingconfig.cloudregion.md) | CloudRegion | (Optional) | +| [environment?](./search-core.servingconfig.environment.md) | Environment | (Optional) | + diff --git a/etc/search-core.api.md b/etc/search-core.api.md index aa590ea3..b13c1478 100644 --- a/etc/search-core.api.md +++ b/etc/search-core.api.md @@ -105,7 +105,7 @@ export interface BaseFieldValueDirectAnswer extends DirectAnswer } // @public -export interface BaseSearchConfig { +export interface BaseSearchConfig extends ServingConfig { additionalQueryParams?: { [key: string]: string | number | boolean; }; @@ -158,14 +158,6 @@ export interface ClientSDKHeaderValues { ANSWERS_CORE?: never; } -// @public -export enum CloudRegion { - // (undocumented) - EU = "eu", - // (undocumented) - US = "us" -} - // @public export interface ComplexURL { // (undocumented) @@ -274,14 +266,6 @@ 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", @@ -528,7 +512,7 @@ export interface PhoneDirectAnswer extends BaseFieldValueDirectAnswer { export function provideCore(config: SearchConfig): SearchCore; // @public -export function provideEndpoints(environment?: Environment, cloudRegion?: CloudRegion): Required; +export function provideEndpoints(config?: ServingConfig): Required; // @public export interface QueryRulesActionsData { @@ -661,6 +645,20 @@ export interface SearchService { verticalSearch(request: VerticalSearchRequest): Promise; } +// @public +export interface ServingConfig { + // Warning: (ae-forgotten-export) The symbol "CloudRegion" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-inheritdoc-reference) The @inheritDoc reference could not be resolved: The package "@yext/search-core" does not have an export "CloudRegion" + // + // (undocumented) + cloudRegion?: CloudRegion; + // Warning: (ae-forgotten-export) The symbol "Environment" needs to be exported by the entry point index.d.ts + // Warning: (ae-unresolved-inheritdoc-reference) The @inheritDoc reference could not be resolved: The package "@yext/search-core" does not have an export "Environment" + // + // (undocumented) + environment?: Environment; +} + // @public export interface Snippet { matchedSubstrings: { diff --git a/src/index.ts b/src/index.ts index 75068996..60585af4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ // main symbols export { SearchCore } from './SearchCore'; export { provideCore } from './provideCore'; -export { provideEndpoints, Environment, CloudRegion, SandboxEndpoints } from './provideEndpoints'; +export { provideEndpoints, SandboxEndpoints } from './provideEndpoints'; export * from './models'; export * from './services'; \ No newline at end of file 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..7ceda795 100644 --- a/src/models/core/SearchConfig.ts +++ b/src/models/core/SearchConfig.ts @@ -1,11 +1,33 @@ import { Endpoints } from './Endpoints'; import { Visitor } from './Visitor'; +import { Environment } from './Environment'; +import { CloudRegion } from './CloudRegion'; + +/** + * The configuration options for {@link provideEndpoints}. + * + * @public + */ +export interface ServingConfig { + /** + * {@inheritDoc Environment} + * + * @public + */ + environment?: Environment, + /** + * {@inheritDoc CloudRegion} + * + * @public + */ + cloudRegion?: CloudRegion +} /** * The base configuration options for {@link SearchCore}. * @public */ -export interface BaseSearchConfig { +export interface BaseSearchConfig extends ServingConfig { /** The experience key of the search experience. */ experienceKey: string, /** The locale of the search experience. */ diff --git a/src/models/index.ts b/src/models/index.ts index 023f7576..301ea517 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, diff --git a/src/provideCore.ts b/src/provideCore.ts index e40706a2..11f88881 100644 --- a/src/provideCore.ts +++ b/src/provideCore.ts @@ -25,7 +25,7 @@ export function provideCore(config: SearchConfig): SearchCore { const defaultedConfig: SearchConfigWithDefaulting = { ...config, endpoints: { - ...provideEndpoints(), + ...provideEndpoints(config), ...config.endpoints } }; diff --git a/src/provideEndpoints.ts b/src/provideEndpoints.ts index 282b3a15..73c0a5d6 100644 --- a/src/provideEndpoints.ts +++ b/src/provideEndpoints.ts @@ -1,39 +1,22 @@ 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; -/** - * Defines the cloud region of the API domains. - * - * @public - */ -export enum CloudRegion { - US = 'us', - EU = 'eu', -} - -/** - * Defines the environment of the API domains. - * - * @public - */ -export enum Environment { - PROD = 'prod', - SANDBOX = 'sbx', -} - /** * Provides methods for getting various endpoints. * * @internal */ -export class EndpointsProvider { +export class EndpointsAdapter { private readonly environment: Environment; private readonly cloudRegion: CloudRegion; - constructor(environment?: Environment, cloudRegion?: CloudRegion) { - this.environment = environment || Environment.PROD; - this.cloudRegion = cloudRegion || CloudRegion.US; + constructor(config?: ServingConfig) { + this.environment = config?.environment || Environment.PROD; + this.cloudRegion = config?.cloudRegion || CloudRegion.US; } /** Provides the domain based on environment and cloud region. @@ -68,7 +51,8 @@ export class EndpointsProvider { * @public */ export const SandboxEndpoints: Required = - new EndpointsProvider(Environment.SANDBOX, CloudRegion.US).getEndpoints(); + new EndpointsAdapter({ environment: Environment.SANDBOX, cloudRegion: CloudRegion.US }) + .getEndpoints(); /** * Provides all endpoints based on environment and cloud region. @@ -76,14 +60,10 @@ export const SandboxEndpoints: Required = * @remarks * Returns an {@link Endpoints} instance. * - * @param environment - environment of the domain to use, defaults to prod if not provided - * @param cloudRegion - cloud region of the domain to use, defaults to us if not provided + * @param config - serving config to use for the domain, defaults to Prod and US if not provided. * * @public */ -export function provideEndpoints( - environment?: Environment, - cloudRegion?: CloudRegion -): Required { - return new EndpointsProvider(environment, cloudRegion).getEndpoints(); +export function provideEndpoints(config?: ServingConfig): Required { + return new EndpointsAdapter(config).getEndpoints(); }