Skip to content

Commit

Permalink
Exports endpoint and cloud region models
Browse files Browse the repository at this point in the history
Change-Id: I9ba835765871534befce6091d40ac36eb611a0f3
  • Loading branch information
EmilyZhang777 committed May 4, 2023
1 parent 82ae531 commit 079a722
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 69 deletions.
13 changes: 13 additions & 0 deletions docs/search-core.basesearchconfig.cloudregion.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; [BaseSearchConfig](./search-core.basesearchconfig.md) &gt; [cloudRegion](./search-core.basesearchconfig.cloudregion.md)

## BaseSearchConfig.cloudRegion property

Defines the cloud region of the API domains.

<b>Signature:</b>

```typescript
cloudRegion?: CloudRegion;
```
13 changes: 13 additions & 0 deletions docs/search-core.basesearchconfig.environment.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; [BaseSearchConfig](./search-core.basesearchconfig.md) &gt; [environment](./search-core.basesearchconfig.environment.md)

## BaseSearchConfig.environment property

Defines the environment of the API domains.

<b>Signature:</b>

```typescript
environment?: Environment;
```
4 changes: 3 additions & 1 deletion docs/search-core.basesearchconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

<b>Signature:</b>

Expand All @@ -18,7 +18,9 @@ export interface BaseSearchConfig extends ServingConfig
| Property | Type | Description |
| --- | --- | --- |
| [additionalQueryParams?](./search-core.basesearchconfig.additionalqueryparams.md) | { \[key: string\]: string \| number \| boolean; } | <i>(Optional)</i> Additional query params added on to every request. |
| [cloudRegion?](./search-core.basesearchconfig.cloudregion.md) | [CloudRegion](./search-core.cloudregion.md) | <i>(Optional)</i> Defines the cloud region of the API domains. |
| [endpoints?](./search-core.basesearchconfig.endpoints.md) | [Endpoints](./search-core.endpoints.md) | <i>(Optional)</i> 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) | <i>(Optional)</i> 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 | <i>(Optional)</i> The version of the search experience configuration. |
| [locale](./search-core.basesearchconfig.locale.md) | string | The locale of the search experience. |
Expand Down
21 changes: 21 additions & 0 deletions docs/search-core.cloudregion.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; [CloudRegion](./search-core.cloudregion.md)

## CloudRegion enum

Defines the cloud region of the API domains.

<b>Signature:</b>

```typescript
export declare enum CloudRegion
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| EU | <code>&quot;eu&quot;</code> | |
| US | <code>&quot;us&quot;</code> | |

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

## Environment enum

Defines the environment of the API domains.

<b>Signature:</b>

```typescript
export declare enum Environment
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| PROD | <code>&quot;prod&quot;</code> | |
| SANDBOX | <code>&quot;sbx&quot;</code> | |

7 changes: 4 additions & 3 deletions docs/search-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand All @@ -35,7 +37,6 @@
| Function | Description |
| --- | --- |
| [provideCore(config)](./search-core.providecore.md) | The entrypoint to the search-core library. |
| [provideEndpoints(config)](./search-core.provideendpoints.md) | Provides all endpoints based on environment and cloud region. |

## Interfaces

Expand All @@ -51,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. |
Expand Down Expand Up @@ -101,7 +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 [provideEndpoints()](./search-core.provideendpoints.md)<!-- -->. |
| [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. |
Expand Down
28 changes: 0 additions & 28 deletions docs/search-core.provideendpoints.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/search-core.sandboxendpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

> Warning: This API is now obsolete.
>
> Use [provideEndpoints()](./search-core.provideendpoints.md) instead
> Use [provideCore()](./search-core.providecore.md) with the appropriate [ServingConfig](./search-core.servingconfig.md) instead
>
The endpoints to use for sandbox experiences.
Expand Down
1 change: 1 addition & 0 deletions docs/search-core.servingconfig.cloudregion.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## ServingConfig.cloudRegion property

Defines the cloud region of the API domains.

<b>Signature:</b>

Expand Down
1 change: 1 addition & 0 deletions docs/search-core.servingconfig.environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## ServingConfig.environment property

Defines the environment of the API domains.

<b>Signature:</b>

Expand Down
6 changes: 3 additions & 3 deletions docs/search-core.servingconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## ServingConfig interface

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

<b>Signature:</b>

Expand All @@ -16,6 +16,6 @@ export interface ServingConfig

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

29 changes: 18 additions & 11 deletions etc/search-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ 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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -266,6 +276,14 @@ 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 @@ -511,9 +529,6 @@ export interface PhoneDirectAnswer extends BaseFieldValueDirectAnswer<string> {
// @public
export function provideCore(config: SearchConfig): SearchCore;

// @public
export function provideEndpoints(config?: ServingConfig): Required<Endpoints>;

// @public
export interface QueryRulesActionsData {
data?: Record<string, unknown>;
Expand Down Expand Up @@ -647,15 +662,7 @@ export interface SearchService {

// @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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// main symbols
export { SearchCore } from './SearchCore';
export { provideCore } from './provideCore';
export { provideEndpoints, SandboxEndpoints } from './provideEndpoints';
export { SandboxEndpoints } from './provideEndpoints';
export * from './models';
export * from './services';
20 changes: 17 additions & 3 deletions src/models/core/SearchConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Environment } from './Environment';
import { CloudRegion } from './CloudRegion';

/**
* The configuration options for {@link provideEndpoints}.
* The configuration options for getting the endpoints.
*
* @public
*/
Expand All @@ -24,7 +24,9 @@ export interface ServingConfig {
}

/**
* The base configuration options for {@link SearchCore}.
* The base configuration options for {@link SearchCore}, which includes the
* options from {@link ServingConfig}.
*
* @public
*/
export interface BaseSearchConfig extends ServingConfig {
Expand Down Expand Up @@ -57,7 +59,19 @@ export interface BaseSearchConfig extends ServingConfig {
*/
additionalQueryParams?: {
[key: string]: string | number | boolean
}
},
/**
* {@inheritDoc Environment}
*
* @public
*/
environment?: Environment,
/**
* {@inheritDoc CloudRegion}
*
* @public
*/
cloudRegion?: CloudRegion
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,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';
Expand Down
4 changes: 2 additions & 2 deletions src/provideCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { provideEndpoints } from './provideEndpoints';
import { EndpointsFactory } from './provideEndpoints';

/**
* The entrypoint to the search-core library.
Expand All @@ -25,7 +25,7 @@ export function provideCore(config: SearchConfig): SearchCore {
const defaultedConfig: SearchConfigWithDefaulting = {
...config,
endpoints: {
...provideEndpoints(config),
...new EndpointsFactory(config).getEndpoints(),
...config.endpoints
}
};
Expand Down
11 changes: 3 additions & 8 deletions src/provideEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@ export class EndpointsFactory {
this.cloudRegion = config?.cloudRegion || CloudRegion.US;
}

/** Provides the domain based on environment and cloud region.
* @internal
*/
/** 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.
* @internal
*/
/** Provides all endpoints based on environment and cloud region. */
getEndpoints() {
return {
universalSearch: `${this.getDomain()}/v2/accounts/me/search/query`,
Expand All @@ -46,7 +41,7 @@ export class EndpointsFactory {
/**
* The endpoints to use for sandbox experiences.
*
* @deprecated Use {@link provideEndpoints} instead
* @deprecated Use {@link provideCore} with the appropriate {@link ServingConfig} instead
*
* @public
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/infra/AutocompleteServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +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 { defaultApiVersion, provideEndpoints } from '../../src/provideEndpoints';
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<Endpoints> = provideEndpoints();
const defaultEndpoints: Required<Endpoints> = new EndpointsFactory().getEndpoints();

describe('AutocompleteService', () => {
const config: SearchConfigWithDefaulting = {
Expand Down
Loading

0 comments on commit 079a722

Please sign in to comment.