Skip to content

Commit

Permalink
Merge 9580032 into 3183412
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyZhang777 committed May 3, 2023
2 parents 3183412 + 9580032 commit f4f3df2
Show file tree
Hide file tree
Showing 24 changed files with 217 additions and 55 deletions.
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> | |

2 changes: 1 addition & 1 deletion docs/search-core.context.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Used to trigger Search [Query Rules](https://hitchhikers.yext.com/tracks/answers
<b>Signature:</b>

```typescript
export declare type Context = any;
export type Context = any;
```

## Remarks
Expand Down
2 changes: 1 addition & 1 deletion docs/search-core.enumorliteral.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Produces a union type from the enum passed as a generic which consists of the en
<b>Signature:</b>

```typescript
export declare type EnumOrLiteral<T extends string> = T | `${T}`;
export type EnumOrLiteral<T extends string> = T | `${T}`;
```
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> | |

2 changes: 1 addition & 1 deletion docs/search-core.featuredsnippetdirectanswer.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ All possible built-in [BaseFeaturedSnippetDirectAnswer](./search-core.basefeatur
<b>Signature:</b>

```typescript
export declare type FeaturedSnippetDirectAnswer = MultiLineTextSnippetDirectAnswer | RichTextSnippetDirectAnswer;
export type FeaturedSnippetDirectAnswer = MultiLineTextSnippetDirectAnswer | RichTextSnippetDirectAnswer;
```
<b>References:</b> [MultiLineTextSnippetDirectAnswer](./search-core.multilinetextsnippetdirectanswer.md)<!-- -->, [RichTextSnippetDirectAnswer](./search-core.richtextsnippetdirectanswer.md)

2 changes: 1 addition & 1 deletion docs/search-core.fieldvaluedirectanswer.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Possible built-in and custom [BaseFieldValueDirectAnswer](./search-core.basefiel
<b>Signature:</b>

```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;
```
<b>References:</b> [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)

2 changes: 1 addition & 1 deletion docs/search-core.highlightedfields.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A mapping of fields to the values emphasized by the Search API.
<b>Signature:</b>

```typescript
export declare type HighlightedFields = {
export type HighlightedFields = {
[fieldId: string]: HighlightedValue | HighlightedValue[] | HighlightedFields | HighlightedFields[];
};
```
Expand Down
3 changes: 3 additions & 0 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,6 +37,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. |

## Interfaces

Expand Down
29 changes: 29 additions & 0 deletions docs/search-core.provideendpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

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

## provideEndpoints() function

Provides all endpoints based on environment and cloud region.

<b>Signature:</b>

```typescript
export declare function provideEndpoints(environment?: Environment, cloudRegion?: CloudRegion): 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 |

<b>Returns:</b>

Required&lt;[Endpoints](./search-core.endpoints.md)<!-- -->&gt;

## Remarks

Returns an [Endpoints](./search-core.endpoints.md) instance.

5 changes: 5 additions & 0 deletions docs/search-core.sandboxendpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## SandboxEndpoints variable

> Warning: This API is now obsolete.
>
> Use [provideEndpoints()](./search-core.provideendpoints.md) instead
>
The endpoints to use for sandbox experiences.

<b>Signature:</b>
Expand Down
2 changes: 1 addition & 1 deletion docs/search-core.searchconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The main configuration options for [SearchCore](./search-core.searchcore.md)<!--
<b>Signature:</b>

```typescript
export declare type SearchConfig = SearchConfigWithApiKey | SearchConfigWithToken;
export type SearchConfig = SearchConfigWithApiKey | SearchConfigWithToken;
```
<b>References:</b> [SearchConfigWithApiKey](./search-core.searchconfigwithapikey.md)<!-- -->, [SearchConfigWithToken](./search-core.searchconfigwithtoken.md)

2 changes: 1 addition & 1 deletion docs/search-core.staticfilter.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Represents a static filter that will be used to refine results.
<b>Signature:</b>

```typescript
export declare type StaticFilter = FieldValueStaticFilter | DisjunctionStaticFilter | ConjunctionStaticFilter;
export type StaticFilter = FieldValueStaticFilter | DisjunctionStaticFilter | ConjunctionStaticFilter;
```
<b>References:</b> [FieldValueStaticFilter](./search-core.fieldvaluestaticfilter.md)<!-- -->, [DisjunctionStaticFilter](./search-core.disjunctionstaticfilter.md)<!-- -->, [ConjunctionStaticFilter](./search-core.conjunctionstaticfilter.md)

21 changes: 20 additions & 1 deletion etc/search-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,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 +274,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,6 +527,9 @@ export interface PhoneDirectAnswer extends BaseFieldValueDirectAnswer<string> {
// @public
export function provideCore(config: SearchConfig): SearchCore;

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

// @public
export interface QueryRulesActionsData {
data?: Record<string, unknown>;
Expand Down Expand Up @@ -581,7 +600,7 @@ export interface RichTextSnippetDirectAnswer extends Omit<BaseFeaturedSnippetDir
fieldType: EnumOrLiteral<BuiltInFieldType.RichText>;
}

// @public
// @public @deprecated
export const SandboxEndpoints: Required<Endpoints>;

// @public
Expand Down
28 changes: 0 additions & 28 deletions src/constants.ts

This file was deleted.

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 { SandboxEndpoints } from './constants';
export { provideEndpoints, Environment, CloudRegion, SandboxEndpoints } from './provideEndpoints';
export * from './models';
export * from './services';
2 changes: 1 addition & 1 deletion src/infra/AutocompleteServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/infra/QuestionSubmissionServiceImpl.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/infra/SearchServiceImpl.ts
Original file line number Diff line number Diff line change
@@ -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';
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 { defaultEndpoints } from './constants';
import { provideEndpoints } 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: {
...defaultEndpoints,
...provideEndpoints(),
...config.endpoints
}
};
Expand Down
89 changes: 89 additions & 0 deletions src/provideEndpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Endpoints } from './models/core/Endpoints';

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 {
private readonly environment: Environment;
private readonly cloudRegion: CloudRegion;

constructor(environment?: Environment, cloudRegion?: CloudRegion) {
this.environment = environment || Environment.PROD;
this.cloudRegion = cloudRegion || CloudRegion.US;
}

/** Provides the domain based on environment and cloud region.
* @internal
*/
getDomain() {
return `https://${this.environment}-cdn.${this.cloudRegion}.yextapis.com`;
}

/**
* Provides all endpoints based on environment and cloud region.
* @internal
*/
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 provideEndpoints} instead
*
* @public
*/
export const SandboxEndpoints: Required<Endpoints> =
new EndpointsProvider(Environment.SANDBOX, 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
*
* @public
*/
export function provideEndpoints(
environment?: Environment,
cloudRegion?: CloudRegion
): Required<Endpoints> {
return new EndpointsProvider(environment, cloudRegion).getEndpoints();
}

0 comments on commit f4f3df2

Please sign in to comment.