Skip to content

Commit

Permalink
Create ServingConfig and update name
Browse files Browse the repository at this point in the history
Change-Id: I40c3c538871a5a14e9ff8fd7c79617d99369781c
  • Loading branch information
EmilyZhang777 committed May 4, 2023
1 parent 7c97fff commit fb44cdc
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 102 deletions.
3 changes: 2 additions & 1 deletion docs/search-core.basesearchconfig.md
Expand Up @@ -9,8 +9,9 @@ The base configuration options for [SearchCore](./search-core.searchcore.md)<!--
<b>Signature:</b>

```typescript
export interface BaseSearchConfig
export interface BaseSearchConfig extends ServingConfig
```
<b>Extends:</b> [ServingConfig](./search-core.servingconfig.md)
## Properties
Expand Down
21 changes: 0 additions & 21 deletions docs/search-core.cloudregion.md

This file was deleted.

21 changes: 0 additions & 21 deletions docs/search-core.environment.md

This file was deleted.

5 changes: 2 additions & 3 deletions docs/search-core.md
Expand Up @@ -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. |
Expand All @@ -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

Expand Down Expand Up @@ -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. |
Expand Down
5 changes: 2 additions & 3 deletions docs/search-core.provideendpoints.md
Expand Up @@ -9,15 +9,14 @@ Provides all endpoints based on environment and cloud region.
<b>Signature:</b>

```typescript
export declare function provideEndpoints(environment?: Environment, cloudRegion?: CloudRegion): Required<Endpoints>;
export declare function provideEndpoints(config?: ServingConfig): Required<Endpoints>;
```

## 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. |

<b>Returns:</b>

Expand Down
12 changes: 12 additions & 0 deletions docs/search-core.servingconfig.cloudregion.md
@@ -0,0 +1,12 @@
<!-- 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; [cloudRegion](./search-core.servingconfig.cloudregion.md)

## ServingConfig.cloudRegion property


<b>Signature:</b>

```typescript
cloudRegion?: CloudRegion;
```
12 changes: 12 additions & 0 deletions docs/search-core.servingconfig.environment.md
@@ -0,0 +1,12 @@
<!-- 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; [environment](./search-core.servingconfig.environment.md)

## ServingConfig.environment property


<b>Signature:</b>

```typescript
environment?: Environment;
```
21 changes: 21 additions & 0 deletions docs/search-core.servingconfig.md
@@ -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; [ServingConfig](./search-core.servingconfig.md)

## ServingConfig interface

The configuration options for [provideEndpoints()](./search-core.provideendpoints.md)<!-- -->.

<b>Signature:</b>

```typescript
export interface ServingConfig
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [cloudRegion?](./search-core.servingconfig.cloudregion.md) | CloudRegion | <i>(Optional)</i> |
| [environment?](./search-core.servingconfig.environment.md) | Environment | <i>(Optional)</i> |

34 changes: 16 additions & 18 deletions etc/search-core.api.md
Expand Up @@ -105,7 +105,7 @@ export interface BaseFieldValueDirectAnswer<T = unknown> extends DirectAnswer<T>
}

// @public
export interface BaseSearchConfig {
export interface BaseSearchConfig extends ServingConfig {
additionalQueryParams?: {
[key: string]: string | number | boolean;
};
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -274,14 +266,6 @@ export interface Endpoints {
// @public
export type EnumOrLiteral<T extends string> = T | `${T}`;

// @public
export enum Environment {
// (undocumented)
PROD = "prod",
// (undocumented)
SANDBOX = "sbx"
}

// @public
export enum ErrorType {
BackendError = "BACKEND_ERROR",
Expand Down Expand Up @@ -528,7 +512,7 @@ export interface PhoneDirectAnswer extends BaseFieldValueDirectAnswer<string> {
export function provideCore(config: SearchConfig): SearchCore;

// @public
export function provideEndpoints(environment?: Environment, cloudRegion?: CloudRegion): Required<Endpoints>;
export function provideEndpoints(config?: ServingConfig): Required<Endpoints>;

// @public
export interface QueryRulesActionsData {
Expand Down Expand Up @@ -661,6 +645,20 @@ export interface SearchService {
verticalSearch(request: VerticalSearchRequest): Promise<VerticalSearchResponse>;
}

// @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: {
Expand Down
2 changes: 1 addition & 1 deletion 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';
9 changes: 9 additions & 0 deletions 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',
}
9 changes: 9 additions & 0 deletions src/models/core/Environment.ts
@@ -0,0 +1,9 @@
/**
* Defines the environment of the API domains.
*
* @public
*/
export enum Environment {
PROD = 'prod',
SANDBOX = 'sbx',
}
24 changes: 23 additions & 1 deletion 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. */
Expand Down
1 change: 1 addition & 0 deletions src/models/index.ts
Expand Up @@ -3,6 +3,7 @@ export { SearchError } from './searchapi/SearchError';

// Core models
export {
ServingConfig,
SearchConfig,
BaseSearchConfig,
SearchConfigWithApiKey,
Expand Down
2 changes: 1 addition & 1 deletion src/provideCore.ts
Expand Up @@ -25,7 +25,7 @@ export function provideCore(config: SearchConfig): SearchCore {
const defaultedConfig: SearchConfigWithDefaulting = {
...config,
endpoints: {
...provideEndpoints(),
...provideEndpoints(config),
...config.endpoints
}
};
Expand Down
44 changes: 12 additions & 32 deletions 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.
Expand Down Expand Up @@ -68,22 +51,19 @@ export class EndpointsProvider {
* @public
*/
export const SandboxEndpoints: Required<Endpoints> =
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.
*
* @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<Endpoints> {
return new EndpointsProvider(environment, cloudRegion).getEndpoints();
export function provideEndpoints(config?: ServingConfig): Required<Endpoints> {
return new EndpointsAdapter(config).getEndpoints();
}

0 comments on commit fb44cdc

Please sign in to comment.