From db0f80463ee8d5eb46caac9fac8213cc06af8a94 Mon Sep 17 00:00:00 2001 From: Emily Zhang Date: Tue, 2 May 2023 16:30:45 -0400 Subject: [PATCH 1/4] Provide Endpoints for EU Cloud Region This PR creates an EndpointProvider class to offer a way to get endpoints for EU. J=BACK-2270 TEST=auto,manual Ran tests under tests/. Manually started a test site and made sure the api request use the correct endpoints. Change-Id: I5c5bbd99e9c3f0f67d0b6817e0a0db6eeaf2f231 --- THIRD-PARTY-NOTICES | 12 ++ docs/search-core.context.md | 2 +- ...ch-core.endpointsprovider._constructor_.md | 22 +++ ...rch-core.endpointsprovider.getendpoints.md | 29 ++++ ...dpointsprovider.getfiltersearchendpoint.md | 17 +++ ...sprovider.getquestionsubmissionendpoint.md | 17 +++ ...ore.endpointsprovider.getstatusendpoint.md | 17 +++ ...pointsprovider.getuniversalautocomplete.md | 17 +++ ...intsprovider.getuniversalsearchendpoint.md | 17 +++ ...dpointsprovider.getverticalautocomplete.md | 17 +++ ...ointsprovider.getverticalsearchendpoint.md | 17 +++ docs/search-core.endpointsprovider.md | 33 +++++ docs/search-core.enumorliteral.md | 2 +- ...search-core.featuredsnippetdirectanswer.md | 2 +- docs/search-core.fieldvaluedirectanswer.md | 2 +- docs/search-core.highlightedfields.md | 2 +- docs/search-core.md | 1 + docs/search-core.sandboxendpoints.md | 5 + docs/search-core.searchconfig.md | 2 +- docs/search-core.staticfilter.md | 2 +- etc/search-core.api.md | 27 +++- src/constants.ts | 136 +++++++++++++++--- src/index.ts | 2 +- src/provideCore.ts | 8 +- tests/infra/AutocompleteServiceImpl.ts | 12 +- tests/infra/QuestionSubmissionServiceImpl.ts | 6 +- tests/infra/SearchServiceImpl.ts | 20 ++- tests/provideCore.ts | 13 +- 28 files changed, 407 insertions(+), 52 deletions(-) create mode 100644 docs/search-core.endpointsprovider._constructor_.md create mode 100644 docs/search-core.endpointsprovider.getendpoints.md create mode 100644 docs/search-core.endpointsprovider.getfiltersearchendpoint.md create mode 100644 docs/search-core.endpointsprovider.getquestionsubmissionendpoint.md create mode 100644 docs/search-core.endpointsprovider.getstatusendpoint.md create mode 100644 docs/search-core.endpointsprovider.getuniversalautocomplete.md create mode 100644 docs/search-core.endpointsprovider.getuniversalsearchendpoint.md create mode 100644 docs/search-core.endpointsprovider.getverticalautocomplete.md create mode 100644 docs/search-core.endpointsprovider.getverticalsearchendpoint.md create mode 100644 docs/search-core.endpointsprovider.md diff --git a/THIRD-PARTY-NOTICES b/THIRD-PARTY-NOTICES index 7e7197aa..f7302a19 100644 --- a/THIRD-PARTY-NOTICES +++ b/THIRD-PARTY-NOTICES @@ -157,6 +157,18 @@ This package contains the following license and notice below: ----------- +The following NPM package may be included in this product: + + - tsc@2.0.4 + +This package contains the following license and notice below: + +## DEPRECATED. + +Use [`typescript`](https://www.npmjs.com/package/typescript) to get access to the `tsc` CLI command. + +----------- + The following NPM package may be included in this product: - webidl-conversions@3.0.1 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.endpointsprovider._constructor_.md b/docs/search-core.endpointsprovider._constructor_.md new file mode 100644 index 00000000..086a4026 --- /dev/null +++ b/docs/search-core.endpointsprovider._constructor_.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [(constructor)](./search-core.endpointsprovider._constructor_.md) + +## EndpointsProvider.(constructor) + +Constructs a new instance of the `EndpointsProvider` class + +Signature: + +```typescript +constructor(environment?: Environment, cloudRegion?: CloudRegion, overrideEndpoints?: Endpoints); +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| environment | Environment | | +| cloudRegion | CloudRegion | | +| overrideEndpoints | [Endpoints](./search-core.endpoints.md) | | + diff --git a/docs/search-core.endpointsprovider.getendpoints.md b/docs/search-core.endpointsprovider.getendpoints.md new file mode 100644 index 00000000..0cdf4408 --- /dev/null +++ b/docs/search-core.endpointsprovider.getendpoints.md @@ -0,0 +1,29 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getEndpoints](./search-core.endpointsprovider.getendpoints.md) + +## EndpointsProvider.getEndpoints() method + +Provides all endpoints based on environment and cloud region. Include any custom overrides in overrideEndpoints. + +Signature: + +```typescript +getEndpoints(): { + universalSearch: string; + verticalSearch: string; + questionSubmission: string; + status: string; + universalAutocomplete: string; + verticalAutocomplete: string; + filterSearch: string; + }; +``` +Returns: + +{ universalSearch: string; verticalSearch: string; questionSubmission: string; status: string; universalAutocomplete: string; verticalAutocomplete: string; filterSearch: string; } + +## Remarks + +Returns an [Endpoints](./search-core.endpoints.md) instance. + diff --git a/docs/search-core.endpointsprovider.getfiltersearchendpoint.md b/docs/search-core.endpointsprovider.getfiltersearchendpoint.md new file mode 100644 index 00000000..57ee8110 --- /dev/null +++ b/docs/search-core.endpointsprovider.getfiltersearchendpoint.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getFilterSearchEndpoint](./search-core.endpointsprovider.getfiltersearchendpoint.md) + +## EndpointsProvider.getFilterSearchEndpoint() method + +Returns the endpoint for filter search. + +Signature: + +```typescript +getFilterSearchEndpoint(): string; +``` +Returns: + +string + diff --git a/docs/search-core.endpointsprovider.getquestionsubmissionendpoint.md b/docs/search-core.endpointsprovider.getquestionsubmissionendpoint.md new file mode 100644 index 00000000..2fb2ebe7 --- /dev/null +++ b/docs/search-core.endpointsprovider.getquestionsubmissionendpoint.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getQuestionSubmissionEndpoint](./search-core.endpointsprovider.getquestionsubmissionendpoint.md) + +## EndpointsProvider.getQuestionSubmissionEndpoint() method + +Returns the endpoint for question submission. + +Signature: + +```typescript +getQuestionSubmissionEndpoint(): string; +``` +Returns: + +string + diff --git a/docs/search-core.endpointsprovider.getstatusendpoint.md b/docs/search-core.endpointsprovider.getstatusendpoint.md new file mode 100644 index 00000000..b4dc4f87 --- /dev/null +++ b/docs/search-core.endpointsprovider.getstatusendpoint.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getStatusEndpoint](./search-core.endpointsprovider.getstatusendpoint.md) + +## EndpointsProvider.getStatusEndpoint() method + +Returns the endpoint for status. + +Signature: + +```typescript +getStatusEndpoint(): string; +``` +Returns: + +string + diff --git a/docs/search-core.endpointsprovider.getuniversalautocomplete.md b/docs/search-core.endpointsprovider.getuniversalautocomplete.md new file mode 100644 index 00000000..66a9f191 --- /dev/null +++ b/docs/search-core.endpointsprovider.getuniversalautocomplete.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getUniversalAutocomplete](./search-core.endpointsprovider.getuniversalautocomplete.md) + +## EndpointsProvider.getUniversalAutocomplete() method + +Returns the endpoint for universal autocomplete. + +Signature: + +```typescript +getUniversalAutocomplete(): string; +``` +Returns: + +string + diff --git a/docs/search-core.endpointsprovider.getuniversalsearchendpoint.md b/docs/search-core.endpointsprovider.getuniversalsearchendpoint.md new file mode 100644 index 00000000..47b9a1eb --- /dev/null +++ b/docs/search-core.endpointsprovider.getuniversalsearchendpoint.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getUniversalSearchEndpoint](./search-core.endpointsprovider.getuniversalsearchendpoint.md) + +## EndpointsProvider.getUniversalSearchEndpoint() method + +Returns the endpoint for universal search. + +Signature: + +```typescript +getUniversalSearchEndpoint(): string; +``` +Returns: + +string + diff --git a/docs/search-core.endpointsprovider.getverticalautocomplete.md b/docs/search-core.endpointsprovider.getverticalautocomplete.md new file mode 100644 index 00000000..0becb70a --- /dev/null +++ b/docs/search-core.endpointsprovider.getverticalautocomplete.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getVerticalAutocomplete](./search-core.endpointsprovider.getverticalautocomplete.md) + +## EndpointsProvider.getVerticalAutocomplete() method + +Returns the endpoint for vertical autocomplete. + +Signature: + +```typescript +getVerticalAutocomplete(): string; +``` +Returns: + +string + diff --git a/docs/search-core.endpointsprovider.getverticalsearchendpoint.md b/docs/search-core.endpointsprovider.getverticalsearchendpoint.md new file mode 100644 index 00000000..77f237d3 --- /dev/null +++ b/docs/search-core.endpointsprovider.getverticalsearchendpoint.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getVerticalSearchEndpoint](./search-core.endpointsprovider.getverticalsearchendpoint.md) + +## EndpointsProvider.getVerticalSearchEndpoint() method + +Returns the endpoint for vertical search. + +Signature: + +```typescript +getVerticalSearchEndpoint(): string; +``` +Returns: + +string + diff --git a/docs/search-core.endpointsprovider.md b/docs/search-core.endpointsprovider.md new file mode 100644 index 00000000..0f4e9ed9 --- /dev/null +++ b/docs/search-core.endpointsprovider.md @@ -0,0 +1,33 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) + +## EndpointsProvider class + +Provides methods for getting various endpoints. + +Signature: + +```typescript +export declare class EndpointsProvider +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(environment, cloudRegion, overrideEndpoints)](./search-core.endpointsprovider._constructor_.md) | | Constructs a new instance of the EndpointsProvider class | + +## Methods + +| Method | Modifiers | Description | +| --- | --- | --- | +| [getEndpoints()](./search-core.endpointsprovider.getendpoints.md) | | Provides all endpoints based on environment and cloud region. Include any custom overrides in overrideEndpoints. | +| [getFilterSearchEndpoint()](./search-core.endpointsprovider.getfiltersearchendpoint.md) | | Returns the endpoint for filter search. | +| [getQuestionSubmissionEndpoint()](./search-core.endpointsprovider.getquestionsubmissionendpoint.md) | | Returns the endpoint for question submission. | +| [getStatusEndpoint()](./search-core.endpointsprovider.getstatusendpoint.md) | | Returns the endpoint for status. | +| [getUniversalAutocomplete()](./search-core.endpointsprovider.getuniversalautocomplete.md) | | Returns the endpoint for universal autocomplete. | +| [getUniversalSearchEndpoint()](./search-core.endpointsprovider.getuniversalsearchendpoint.md) | | Returns the endpoint for universal search. | +| [getVerticalAutocomplete()](./search-core.endpointsprovider.getverticalautocomplete.md) | | Returns the endpoint for vertical autocomplete. | +| [getVerticalSearchEndpoint()](./search-core.endpointsprovider.getverticalsearchendpoint.md) | | Returns the endpoint for vertical search. | + 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.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..de9a51f1 100644 --- a/docs/search-core.md +++ b/docs/search-core.md @@ -8,6 +8,7 @@ | Class | Description | | --- | --- | +| [EndpointsProvider](./search-core.endpointsprovider.md) | Provides methods for getting various endpoints. | | [SearchCore](./search-core.searchcore.md) | Provides methods for executing searches, submitting questions, and performing autocompletes. | | [SearchError](./search-core.searcherror.md) | Represents an error | diff --git a/docs/search-core.sandboxendpoints.md b/docs/search-core.sandboxendpoints.md index 4b28fa12..ba28f17d 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 [EndpointsProvider](./search-core.endpointsprovider.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.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..aafa7857 100644 --- a/etc/search-core.api.md +++ b/etc/search-core.api.md @@ -263,6 +263,31 @@ export interface Endpoints { verticalSearch?: string; } +// @public +export class EndpointsProvider { + // Warning: (ae-forgotten-export) The symbol "Environment" needs to be exported by the entry point index.d.ts + // Warning: (ae-forgotten-export) The symbol "CloudRegion" needs to be exported by the entry point index.d.ts + constructor(environment?: Environment, cloudRegion?: CloudRegion, overrideEndpoints?: Endpoints); + // @internal (undocumented) + getDomain(): string; + getEndpoints(): { + universalSearch: string; + verticalSearch: string; + questionSubmission: string; + status: string; + universalAutocomplete: string; + verticalAutocomplete: string; + filterSearch: string; + }; + getFilterSearchEndpoint(): string; + getQuestionSubmissionEndpoint(): string; + getStatusEndpoint(): string; + getUniversalAutocomplete(): string; + getUniversalSearchEndpoint(): string; + getVerticalAutocomplete(): string; + getVerticalSearchEndpoint(): string; +} + // @public export type EnumOrLiteral = T | `${T}`; @@ -581,7 +606,7 @@ export interface RichTextSnippetDirectAnswer extends Omit; } -// @public +// @public @deprecated export const SandboxEndpoints: Required; // @public diff --git a/src/constants.ts b/src/constants.ts index fed7d675..f99f4c6e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,27 +2,125 @@ 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; +export enum CloudRegion { + US = 'us', + EU = 'eu', +} + +export enum Environment { + PROD = 'prod', + SANDBOX = 'sbx', +} /** - * The endpoints to use for sandbox experiences. + * Provides methods for getting various endpoints. * * @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 +export class EndpointsProvider { + private readonly environment: Environment; + private readonly cloudRegion: CloudRegion; + private readonly overrideEndpoints?: Endpoints; + + constructor(environment?: Environment, cloudRegion?: CloudRegion, overrideEndpoints?: Endpoints) { + this.environment = environment || Environment.PROD; + this.cloudRegion = cloudRegion || CloudRegion.US; + this.overrideEndpoints = overrideEndpoints; + } + + /** @internal */ + getDomain() { + return `https://${this.environment}-cdn.${this.cloudRegion}.yextapis.com`; + } + + /** + * Provides all endpoints based on environment and cloud region. Include any custom + * overrides in overrideEndpoints. + * + * @remarks + * Returns an {@link Endpoints} instance. + * + * @public + */ + getEndpoints() { + return { + universalSearch: this.getUniversalSearchEndpoint(), + verticalSearch: this.getVerticalSearchEndpoint(), + questionSubmission: this.getQuestionSubmissionEndpoint(), + status: this.getStatusEndpoint(), + universalAutocomplete: this.getUniversalAutocomplete(), + verticalAutocomplete: this.getVerticalAutocomplete(), + filterSearch: this.getFilterSearchEndpoint(), + }; + } + + /** + * Returns the endpoint for universal search. + * @public + * */ + getUniversalSearchEndpoint() { + return this.overrideEndpoints?.universalSearch || + `${this.getDomain()}/v2/accounts/me/search/query`; + } + + /** + * Returns the endpoint for vertical search. + * @public + * */ + getVerticalSearchEndpoint() { + return this.overrideEndpoints?.verticalSearch || + `${this.getDomain()}/v2/accounts/me/search/vertical/query`; + } + + /** + * Returns the endpoint for question submission. + * @public + * */ + getQuestionSubmissionEndpoint() { + return this.overrideEndpoints?.questionSubmission || + `${this.getDomain()}/v2/accounts/me/createQuestion`; + } + + /** + * Returns the endpoint for status. + * @public + * */ + getStatusEndpoint() { + return this.overrideEndpoints?.status || 'https://answersstatus.pagescdn.com'; + } + + /** + * Returns the endpoint for universal autocomplete. + * @public + * */ + getUniversalAutocomplete() { + return this.overrideEndpoints?.universalAutocomplete || + `${this.getDomain()}/v2/accounts/me/search/autocomplete`; + } + + /** + * Returns the endpoint for vertical autocomplete. + * @public + * */ + getVerticalAutocomplete() { + return this.overrideEndpoints?.verticalAutocomplete || + `${this.getDomain()}/v2/accounts/me/search/vertical/autocomplete`; + } + + /** + * Returns the endpoint for filter search. + * @public + * */ + getFilterSearchEndpoint() { + return this.overrideEndpoints?.filterSearch || + `${this.getDomain()}/v2/accounts/me/search/filtersearch`; + } +} + +/** + * The endpoints to use for sandbox experiences. + * @deprecated Use {@link EndpointsProvider} instead + * @public + */ +export const SandboxEndpoints: Required = + new EndpointsProvider(Environment.SANDBOX, CloudRegion.US).getEndpoints(); \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index fcff8109..242c2501 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 { EndpointsProvider, SandboxEndpoints } from './constants'; export * from './models'; export * from './services'; \ No newline at end of file diff --git a/src/provideCore.ts b/src/provideCore.ts index be1aac89..6591d4f5 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 { CloudRegion, EndpointsProvider, Environment } from './constants'; /** * The entrypoint to the search-core library. @@ -24,10 +24,8 @@ export function provideCore(config: SearchConfig): SearchCore { const defaultedConfig: SearchConfigWithDefaulting = { ...config, - endpoints: { - ...defaultEndpoints, - ...config.endpoints - } + endpoints: + new EndpointsProvider(Environment.PROD, CloudRegion.US, config.endpoints).getEndpoints() }; const httpService = new HttpServiceImpl(); diff --git a/tests/infra/AutocompleteServiceImpl.ts b/tests/infra/AutocompleteServiceImpl.ts index 5d2838ee..e72df560 100644 --- a/tests/infra/AutocompleteServiceImpl.ts +++ b/tests/infra/AutocompleteServiceImpl.ts @@ -11,12 +11,16 @@ 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, EndpointsProvider } from '../../src/constants'; 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 endpointsProvider: EndpointsProvider = new EndpointsProvider(); +const defaultEndpoints: Required = endpointsProvider.getEndpoints(); describe('AutocompleteService', () => { const config: SearchConfigWithDefaulting = { @@ -56,7 +60,7 @@ describe('AutocompleteService', () => { } describe('Universal Autocomplete', () => { - const expectedUniversalUrl = defaultEndpoints.universalAutocomplete; + const expectedUniversalUrl = endpointsProvider.getUniversalAutocomplete(); const request: UniversalAutocompleteRequest = { input: '', sessionTrackingEnabled: false @@ -131,7 +135,7 @@ describe('AutocompleteService', () => { }); describe('Vertical Autocomplete', () => { - const expectedVerticalUrl = defaultEndpoints.verticalAutocomplete; + const expectedVerticalUrl = endpointsProvider.getVerticalAutocomplete(); const request: VerticalAutocompleteRequest = { input: 'salesforce', sessionTrackingEnabled: false, @@ -181,7 +185,7 @@ describe('AutocompleteService', () => { }); describe('FilterSearch', () => { - const expectedFilterUrl = defaultEndpoints.filterSearch; + const expectedFilterUrl = endpointsProvider.getFilterSearchEndpoint(); it('query params are correct', async () => { const convertedSearchParams = { sectioned: false, diff --git a/tests/infra/QuestionSubmissionServiceImpl.ts b/tests/infra/QuestionSubmissionServiceImpl.ts index 87933a2a..1bf2794a 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, EndpointsProvider } from '../../src/constants'; const baseCoreConfig = { apiKey: 'anApiKey', experienceKey: 'anExperienceKey', locale: 'fr', experienceVersion: 'STAGING', - endpoints: defaultEndpoints + endpoints: new EndpointsProvider().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..0952b660 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 { CloudRegion, defaultApiVersion, EndpointsProvider, Environment } from '../../src/constants'; +import { Endpoints } from '../../src/models/core/Endpoints'; + +const defaultEndpoints: Required = new EndpointsProvider().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,13 @@ describe('SearchService', () => { const customUrl = 'http://custom.endpoint.com/api'; const config: SearchConfigWithDefaulting = { ...configWithRequiredApiKey, - endpoints: { - ...defaultEndpoints, - universalSearch: customUrl - } + endpoints: + new EndpointsProvider( + Environment.PROD, + CloudRegion.US, + { + universalSearch: customUrl + }).getEndpoints() }; const searchService: SearchServiceImpl = new SearchServiceImpl( config, @@ -200,7 +206,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..d4d0871b 100644 --- a/tests/provideCore.ts +++ b/tests/provideCore.ts @@ -1,4 +1,4 @@ -import { SandboxEndpoints } from '../src/constants'; +import { CloudRegion, EndpointsProvider, Environment } from '../src/constants'; import { AutocompleteServiceImpl } from '../src/infra/AutocompleteServiceImpl'; import { QuestionSubmissionServiceImpl } from '../src/infra/QuestionSubmissionServiceImpl'; import { SearchServiceImpl } from '../src/infra/SearchServiceImpl'; @@ -11,10 +11,13 @@ jest.mock('../src/infra/QuestionSubmissionServiceImpl'); jest.mock('../src/infra/SearchServiceImpl'); it('can specify custom endpoints', () => { - const customEndPoints: Required = { - ...SandboxEndpoints, - verticalSearch: '' - }; + const customEndPoints: Required = + new EndpointsProvider( + Environment.SANDBOX, + CloudRegion.US, + { + verticalSearch: '' + }).getEndpoints(); provideCore({ apiKey: '', From cc2c5cf90719affdcc6498c0ec51a0ac6543ad1c Mon Sep 17 00:00:00 2001 From: Emily Zhang Date: Wed, 3 May 2023 12:23:24 -0400 Subject: [PATCH 2/4] Expose provideEndpoints instead Change-Id: I27d289eecf66523ddde6cfcceaf905ae966f27cb --- THIRD-PARTY-NOTICES | 64 +++++++++ ...ch-core.endpointsprovider._constructor_.md | 22 --- ...rch-core.endpointsprovider.getendpoints.md | 29 ---- ...dpointsprovider.getfiltersearchendpoint.md | 17 --- ...sprovider.getquestionsubmissionendpoint.md | 17 --- ...ore.endpointsprovider.getstatusendpoint.md | 17 --- ...pointsprovider.getuniversalautocomplete.md | 17 --- ...intsprovider.getuniversalsearchendpoint.md | 17 --- ...dpointsprovider.getverticalautocomplete.md | 17 --- ...ointsprovider.getverticalsearchendpoint.md | 17 --- docs/search-core.endpointsprovider.md | 33 ----- docs/search-core.md | 2 +- docs/search-core.provideendpoints.md | 29 ++++ docs/search-core.sandboxendpoints.md | 2 +- etc/search-core.api.md | 31 +---- src/constants.ts | 129 +++++++----------- src/index.ts | 2 +- src/provideCore.ts | 8 +- tests/infra/AutocompleteServiceImpl.ts | 11 +- tests/infra/QuestionSubmissionServiceImpl.ts | 4 +- tests/infra/SearchServiceImpl.ts | 12 +- tests/provideCore.ts | 13 +- 22 files changed, 168 insertions(+), 342 deletions(-) delete mode 100644 docs/search-core.endpointsprovider._constructor_.md delete mode 100644 docs/search-core.endpointsprovider.getendpoints.md delete mode 100644 docs/search-core.endpointsprovider.getfiltersearchendpoint.md delete mode 100644 docs/search-core.endpointsprovider.getquestionsubmissionendpoint.md delete mode 100644 docs/search-core.endpointsprovider.getstatusendpoint.md delete mode 100644 docs/search-core.endpointsprovider.getuniversalautocomplete.md delete mode 100644 docs/search-core.endpointsprovider.getuniversalsearchendpoint.md delete mode 100644 docs/search-core.endpointsprovider.getverticalautocomplete.md delete mode 100644 docs/search-core.endpointsprovider.getverticalsearchendpoint.md delete mode 100644 docs/search-core.endpointsprovider.md create mode 100644 docs/search-core.provideendpoints.md diff --git a/THIRD-PARTY-NOTICES b/THIRD-PARTY-NOTICES index f7302a19..1e6e3867 100644 --- a/THIRD-PARTY-NOTICES +++ b/THIRD-PARTY-NOTICES @@ -169,6 +169,70 @@ Use [`typescript`](https://www.npmjs.com/package/typescript) to get access to th ----------- +The following NPM package may be included in this product: + + - typescript@5.0.4 + +This package contains the following license and notice below: + +Apache License + +Version 2.0, January 2004 + +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of this License; and + +You must cause any modified files to carry prominent notices stating that You changed the files; and + +You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + +If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +----------- + The following NPM package may be included in this product: - webidl-conversions@3.0.1 diff --git a/docs/search-core.endpointsprovider._constructor_.md b/docs/search-core.endpointsprovider._constructor_.md deleted file mode 100644 index 086a4026..00000000 --- a/docs/search-core.endpointsprovider._constructor_.md +++ /dev/null @@ -1,22 +0,0 @@ - - -[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [(constructor)](./search-core.endpointsprovider._constructor_.md) - -## EndpointsProvider.(constructor) - -Constructs a new instance of the `EndpointsProvider` class - -Signature: - -```typescript -constructor(environment?: Environment, cloudRegion?: CloudRegion, overrideEndpoints?: Endpoints); -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| environment | Environment | | -| cloudRegion | CloudRegion | | -| overrideEndpoints | [Endpoints](./search-core.endpoints.md) | | - diff --git a/docs/search-core.endpointsprovider.getendpoints.md b/docs/search-core.endpointsprovider.getendpoints.md deleted file mode 100644 index 0cdf4408..00000000 --- a/docs/search-core.endpointsprovider.getendpoints.md +++ /dev/null @@ -1,29 +0,0 @@ - - -[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getEndpoints](./search-core.endpointsprovider.getendpoints.md) - -## EndpointsProvider.getEndpoints() method - -Provides all endpoints based on environment and cloud region. Include any custom overrides in overrideEndpoints. - -Signature: - -```typescript -getEndpoints(): { - universalSearch: string; - verticalSearch: string; - questionSubmission: string; - status: string; - universalAutocomplete: string; - verticalAutocomplete: string; - filterSearch: string; - }; -``` -Returns: - -{ universalSearch: string; verticalSearch: string; questionSubmission: string; status: string; universalAutocomplete: string; verticalAutocomplete: string; filterSearch: string; } - -## Remarks - -Returns an [Endpoints](./search-core.endpoints.md) instance. - diff --git a/docs/search-core.endpointsprovider.getfiltersearchendpoint.md b/docs/search-core.endpointsprovider.getfiltersearchendpoint.md deleted file mode 100644 index 57ee8110..00000000 --- a/docs/search-core.endpointsprovider.getfiltersearchendpoint.md +++ /dev/null @@ -1,17 +0,0 @@ - - -[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getFilterSearchEndpoint](./search-core.endpointsprovider.getfiltersearchendpoint.md) - -## EndpointsProvider.getFilterSearchEndpoint() method - -Returns the endpoint for filter search. - -Signature: - -```typescript -getFilterSearchEndpoint(): string; -``` -Returns: - -string - diff --git a/docs/search-core.endpointsprovider.getquestionsubmissionendpoint.md b/docs/search-core.endpointsprovider.getquestionsubmissionendpoint.md deleted file mode 100644 index 2fb2ebe7..00000000 --- a/docs/search-core.endpointsprovider.getquestionsubmissionendpoint.md +++ /dev/null @@ -1,17 +0,0 @@ - - -[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getQuestionSubmissionEndpoint](./search-core.endpointsprovider.getquestionsubmissionendpoint.md) - -## EndpointsProvider.getQuestionSubmissionEndpoint() method - -Returns the endpoint for question submission. - -Signature: - -```typescript -getQuestionSubmissionEndpoint(): string; -``` -Returns: - -string - diff --git a/docs/search-core.endpointsprovider.getstatusendpoint.md b/docs/search-core.endpointsprovider.getstatusendpoint.md deleted file mode 100644 index b4dc4f87..00000000 --- a/docs/search-core.endpointsprovider.getstatusendpoint.md +++ /dev/null @@ -1,17 +0,0 @@ - - -[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getStatusEndpoint](./search-core.endpointsprovider.getstatusendpoint.md) - -## EndpointsProvider.getStatusEndpoint() method - -Returns the endpoint for status. - -Signature: - -```typescript -getStatusEndpoint(): string; -``` -Returns: - -string - diff --git a/docs/search-core.endpointsprovider.getuniversalautocomplete.md b/docs/search-core.endpointsprovider.getuniversalautocomplete.md deleted file mode 100644 index 66a9f191..00000000 --- a/docs/search-core.endpointsprovider.getuniversalautocomplete.md +++ /dev/null @@ -1,17 +0,0 @@ - - -[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getUniversalAutocomplete](./search-core.endpointsprovider.getuniversalautocomplete.md) - -## EndpointsProvider.getUniversalAutocomplete() method - -Returns the endpoint for universal autocomplete. - -Signature: - -```typescript -getUniversalAutocomplete(): string; -``` -Returns: - -string - diff --git a/docs/search-core.endpointsprovider.getuniversalsearchendpoint.md b/docs/search-core.endpointsprovider.getuniversalsearchendpoint.md deleted file mode 100644 index 47b9a1eb..00000000 --- a/docs/search-core.endpointsprovider.getuniversalsearchendpoint.md +++ /dev/null @@ -1,17 +0,0 @@ - - -[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getUniversalSearchEndpoint](./search-core.endpointsprovider.getuniversalsearchendpoint.md) - -## EndpointsProvider.getUniversalSearchEndpoint() method - -Returns the endpoint for universal search. - -Signature: - -```typescript -getUniversalSearchEndpoint(): string; -``` -Returns: - -string - diff --git a/docs/search-core.endpointsprovider.getverticalautocomplete.md b/docs/search-core.endpointsprovider.getverticalautocomplete.md deleted file mode 100644 index 0becb70a..00000000 --- a/docs/search-core.endpointsprovider.getverticalautocomplete.md +++ /dev/null @@ -1,17 +0,0 @@ - - -[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getVerticalAutocomplete](./search-core.endpointsprovider.getverticalautocomplete.md) - -## EndpointsProvider.getVerticalAutocomplete() method - -Returns the endpoint for vertical autocomplete. - -Signature: - -```typescript -getVerticalAutocomplete(): string; -``` -Returns: - -string - diff --git a/docs/search-core.endpointsprovider.getverticalsearchendpoint.md b/docs/search-core.endpointsprovider.getverticalsearchendpoint.md deleted file mode 100644 index 77f237d3..00000000 --- a/docs/search-core.endpointsprovider.getverticalsearchendpoint.md +++ /dev/null @@ -1,17 +0,0 @@ - - -[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) > [getVerticalSearchEndpoint](./search-core.endpointsprovider.getverticalsearchendpoint.md) - -## EndpointsProvider.getVerticalSearchEndpoint() method - -Returns the endpoint for vertical search. - -Signature: - -```typescript -getVerticalSearchEndpoint(): string; -``` -Returns: - -string - diff --git a/docs/search-core.endpointsprovider.md b/docs/search-core.endpointsprovider.md deleted file mode 100644 index 0f4e9ed9..00000000 --- a/docs/search-core.endpointsprovider.md +++ /dev/null @@ -1,33 +0,0 @@ - - -[Home](./index.md) > [@yext/search-core](./search-core.md) > [EndpointsProvider](./search-core.endpointsprovider.md) - -## EndpointsProvider class - -Provides methods for getting various endpoints. - -Signature: - -```typescript -export declare class EndpointsProvider -``` - -## Constructors - -| Constructor | Modifiers | Description | -| --- | --- | --- | -| [(constructor)(environment, cloudRegion, overrideEndpoints)](./search-core.endpointsprovider._constructor_.md) | | Constructs a new instance of the EndpointsProvider class | - -## Methods - -| Method | Modifiers | Description | -| --- | --- | --- | -| [getEndpoints()](./search-core.endpointsprovider.getendpoints.md) | | Provides all endpoints based on environment and cloud region. Include any custom overrides in overrideEndpoints. | -| [getFilterSearchEndpoint()](./search-core.endpointsprovider.getfiltersearchendpoint.md) | | Returns the endpoint for filter search. | -| [getQuestionSubmissionEndpoint()](./search-core.endpointsprovider.getquestionsubmissionendpoint.md) | | Returns the endpoint for question submission. | -| [getStatusEndpoint()](./search-core.endpointsprovider.getstatusendpoint.md) | | Returns the endpoint for status. | -| [getUniversalAutocomplete()](./search-core.endpointsprovider.getuniversalautocomplete.md) | | Returns the endpoint for universal autocomplete. | -| [getUniversalSearchEndpoint()](./search-core.endpointsprovider.getuniversalsearchendpoint.md) | | Returns the endpoint for universal search. | -| [getVerticalAutocomplete()](./search-core.endpointsprovider.getverticalautocomplete.md) | | Returns the endpoint for vertical autocomplete. | -| [getVerticalSearchEndpoint()](./search-core.endpointsprovider.getverticalsearchendpoint.md) | | Returns the endpoint for vertical search. | - diff --git a/docs/search-core.md b/docs/search-core.md index de9a51f1..135ff458 100644 --- a/docs/search-core.md +++ b/docs/search-core.md @@ -8,7 +8,6 @@ | Class | Description | | --- | --- | -| [EndpointsProvider](./search-core.endpointsprovider.md) | Provides methods for getting various endpoints. | | [SearchCore](./search-core.searchcore.md) | Provides methods for executing searches, submitting questions, and performing autocompletes. | | [SearchError](./search-core.searcherror.md) | Represents an error | @@ -36,6 +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. | ## Interfaces diff --git a/docs/search-core.provideendpoints.md b/docs/search-core.provideendpoints.md new file mode 100644 index 00000000..fcff8b30 --- /dev/null +++ b/docs/search-core.provideendpoints.md @@ -0,0 +1,29 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [provideEndpoints](./search-core.provideendpoints.md) + +## provideEndpoints() function + +Provides all endpoints based on environment and cloud region. + +Signature: + +```typescript +export declare function provideEndpoints(environment?: Environment, cloudRegion?: CloudRegion): Required; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| environment | Environment | environment of the domain to use, defaults to prod if not provided | +| cloudRegion | CloudRegion | cloud region of the domain to use, defaults to us if not provided | + +Returns: + +Required<[Endpoints](./search-core.endpoints.md)> + +## Remarks + +Returns an [Endpoints](./search-core.endpoints.md) instance. + diff --git a/docs/search-core.sandboxendpoints.md b/docs/search-core.sandboxendpoints.md index ba28f17d..f7fbcbb8 100644 --- a/docs/search-core.sandboxendpoints.md +++ b/docs/search-core.sandboxendpoints.md @@ -6,7 +6,7 @@ > Warning: This API is now obsolete. > -> Use [EndpointsProvider](./search-core.endpointsprovider.md) instead +> Use [provideEndpoints()](./search-core.provideendpoints.md) instead > The endpoints to use for sandbox experiences. diff --git a/etc/search-core.api.md b/etc/search-core.api.md index aafa7857..7f3ca3f9 100644 --- a/etc/search-core.api.md +++ b/etc/search-core.api.md @@ -263,31 +263,6 @@ export interface Endpoints { verticalSearch?: string; } -// @public -export class EndpointsProvider { - // Warning: (ae-forgotten-export) The symbol "Environment" needs to be exported by the entry point index.d.ts - // Warning: (ae-forgotten-export) The symbol "CloudRegion" needs to be exported by the entry point index.d.ts - constructor(environment?: Environment, cloudRegion?: CloudRegion, overrideEndpoints?: Endpoints); - // @internal (undocumented) - getDomain(): string; - getEndpoints(): { - universalSearch: string; - verticalSearch: string; - questionSubmission: string; - status: string; - universalAutocomplete: string; - verticalAutocomplete: string; - filterSearch: string; - }; - getFilterSearchEndpoint(): string; - getQuestionSubmissionEndpoint(): string; - getStatusEndpoint(): string; - getUniversalAutocomplete(): string; - getUniversalSearchEndpoint(): string; - getVerticalAutocomplete(): string; - getVerticalSearchEndpoint(): string; -} - // @public export type EnumOrLiteral = T | `${T}`; @@ -536,6 +511,12 @@ export interface PhoneDirectAnswer extends BaseFieldValueDirectAnswer { // @public export function provideCore(config: SearchConfig): SearchCore; +// Warning: (ae-forgotten-export) The symbol "Environment" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "CloudRegion" needs to be exported by the entry point index.d.ts +// +// @public +export function provideEndpoints(environment?: Environment, cloudRegion?: CloudRegion): Required; + // @public export interface QueryRulesActionsData { data?: Record; diff --git a/src/constants.ts b/src/constants.ts index f99f4c6e..282b3a15 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,11 +2,21 @@ 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', @@ -15,112 +25,65 @@ export enum Environment { /** * Provides methods for getting various endpoints. * - * @public + * @internal */ export class EndpointsProvider { private readonly environment: Environment; private readonly cloudRegion: CloudRegion; - private readonly overrideEndpoints?: Endpoints; - constructor(environment?: Environment, cloudRegion?: CloudRegion, overrideEndpoints?: Endpoints) { + constructor(environment?: Environment, cloudRegion?: CloudRegion) { this.environment = environment || Environment.PROD; this.cloudRegion = cloudRegion || CloudRegion.US; - this.overrideEndpoints = overrideEndpoints; } - /** @internal */ + /** 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. Include any custom - * overrides in overrideEndpoints. - * - * @remarks - * Returns an {@link Endpoints} instance. - * - * @public + * Provides all endpoints based on environment and cloud region. + * @internal */ getEndpoints() { return { - universalSearch: this.getUniversalSearchEndpoint(), - verticalSearch: this.getVerticalSearchEndpoint(), - questionSubmission: this.getQuestionSubmissionEndpoint(), - status: this.getStatusEndpoint(), - universalAutocomplete: this.getUniversalAutocomplete(), - verticalAutocomplete: this.getVerticalAutocomplete(), - filterSearch: this.getFilterSearchEndpoint(), + 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`, }; } - - /** - * Returns the endpoint for universal search. - * @public - * */ - getUniversalSearchEndpoint() { - return this.overrideEndpoints?.universalSearch || - `${this.getDomain()}/v2/accounts/me/search/query`; - } - - /** - * Returns the endpoint for vertical search. - * @public - * */ - getVerticalSearchEndpoint() { - return this.overrideEndpoints?.verticalSearch || - `${this.getDomain()}/v2/accounts/me/search/vertical/query`; - } - - /** - * Returns the endpoint for question submission. - * @public - * */ - getQuestionSubmissionEndpoint() { - return this.overrideEndpoints?.questionSubmission || - `${this.getDomain()}/v2/accounts/me/createQuestion`; - } - - /** - * Returns the endpoint for status. - * @public - * */ - getStatusEndpoint() { - return this.overrideEndpoints?.status || 'https://answersstatus.pagescdn.com'; - } - - /** - * Returns the endpoint for universal autocomplete. - * @public - * */ - getUniversalAutocomplete() { - return this.overrideEndpoints?.universalAutocomplete || - `${this.getDomain()}/v2/accounts/me/search/autocomplete`; - } - - /** - * Returns the endpoint for vertical autocomplete. - * @public - * */ - getVerticalAutocomplete() { - return this.overrideEndpoints?.verticalAutocomplete || - `${this.getDomain()}/v2/accounts/me/search/vertical/autocomplete`; - } - - /** - * Returns the endpoint for filter search. - * @public - * */ - getFilterSearchEndpoint() { - return this.overrideEndpoints?.filterSearch || - `${this.getDomain()}/v2/accounts/me/search/filtersearch`; - } } /** * The endpoints to use for sandbox experiences. - * @deprecated Use {@link EndpointsProvider} instead + * + * @deprecated Use {@link provideEndpoints} instead + * * @public */ export const SandboxEndpoints: Required = - new EndpointsProvider(Environment.SANDBOX, CloudRegion.US).getEndpoints(); \ No newline at end of file + 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 { + return new EndpointsProvider(environment, cloudRegion).getEndpoints(); +} diff --git a/src/index.ts b/src/index.ts index 242c2501..9ea0d3f8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ // main symbols export { SearchCore } from './SearchCore'; export { provideCore } from './provideCore'; -export { EndpointsProvider, SandboxEndpoints } from './constants'; +export { provideEndpoints, SandboxEndpoints } from './constants'; export * from './models'; export * from './services'; \ No newline at end of file diff --git a/src/provideCore.ts b/src/provideCore.ts index 6591d4f5..f602cb5d 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 { CloudRegion, EndpointsProvider, Environment } from './constants'; +import { provideEndpoints } from './constants'; /** * The entrypoint to the search-core library. @@ -24,8 +24,10 @@ export function provideCore(config: SearchConfig): SearchCore { const defaultedConfig: SearchConfigWithDefaulting = { ...config, - endpoints: - new EndpointsProvider(Environment.PROD, CloudRegion.US, config.endpoints).getEndpoints() + endpoints: { + ...provideEndpoints(), + ...config.endpoints + } }; const httpService = new HttpServiceImpl(); diff --git a/tests/infra/AutocompleteServiceImpl.ts b/tests/infra/AutocompleteServiceImpl.ts index e72df560..106210f5 100644 --- a/tests/infra/AutocompleteServiceImpl.ts +++ b/tests/infra/AutocompleteServiceImpl.ts @@ -11,7 +11,7 @@ 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, EndpointsProvider } from '../../src/constants'; +import { defaultApiVersion, provideEndpoints } from '../../src/constants'; import { ApiResponseValidator } from '../../src/validation/ApiResponseValidator'; import { ApiResponse } from '../../src/models/searchapi/ApiResponse'; import { SearchError } from '../../src/models/searchapi/SearchError'; @@ -19,8 +19,7 @@ import { getClientSdk } from '../../src/utils/getClientSdk'; import { Matcher } from '../../src/models/searchservice/common/Matcher'; import { Endpoints } from '../../src/models/core/Endpoints'; -const endpointsProvider: EndpointsProvider = new EndpointsProvider(); -const defaultEndpoints: Required = endpointsProvider.getEndpoints(); +const defaultEndpoints: Required = provideEndpoints(); describe('AutocompleteService', () => { const config: SearchConfigWithDefaulting = { @@ -60,7 +59,7 @@ describe('AutocompleteService', () => { } describe('Universal Autocomplete', () => { - const expectedUniversalUrl = endpointsProvider.getUniversalAutocomplete(); + const expectedUniversalUrl = defaultEndpoints.universalAutocomplete; const request: UniversalAutocompleteRequest = { input: '', sessionTrackingEnabled: false @@ -135,7 +134,7 @@ describe('AutocompleteService', () => { }); describe('Vertical Autocomplete', () => { - const expectedVerticalUrl = endpointsProvider.getVerticalAutocomplete(); + const expectedVerticalUrl = defaultEndpoints.verticalAutocomplete; const request: VerticalAutocompleteRequest = { input: 'salesforce', sessionTrackingEnabled: false, @@ -185,7 +184,7 @@ describe('AutocompleteService', () => { }); describe('FilterSearch', () => { - const expectedFilterUrl = endpointsProvider.getFilterSearchEndpoint(); + const expectedFilterUrl = defaultEndpoints.filterSearch; it('query params are correct', async () => { const convertedSearchParams = { sectioned: false, diff --git a/tests/infra/QuestionSubmissionServiceImpl.ts b/tests/infra/QuestionSubmissionServiceImpl.ts index 1bf2794a..ef551e21 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, EndpointsProvider } from '../../src/constants'; +import { defaultApiVersion, provideEndpoints } from '../../src/constants'; const baseCoreConfig = { apiKey: 'anApiKey', experienceKey: 'anExperienceKey', locale: 'fr', experienceVersion: 'STAGING', - endpoints: new EndpointsProvider().getEndpoints() + endpoints: provideEndpoints() }; const qaRequest = { diff --git a/tests/infra/SearchServiceImpl.ts b/tests/infra/SearchServiceImpl.ts index 0952b660..dd96d3d3 100644 --- a/tests/infra/SearchServiceImpl.ts +++ b/tests/infra/SearchServiceImpl.ts @@ -11,10 +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 { CloudRegion, defaultApiVersion, EndpointsProvider, Environment } from '../../src/constants'; +import { defaultApiVersion, provideEndpoints } from '../../src/constants'; import { Endpoints } from '../../src/models/core/Endpoints'; -const defaultEndpoints: Required = new EndpointsProvider().getEndpoints(); +const defaultEndpoints: Required = provideEndpoints(); describe('SearchService', () => { const configWithRequiredApiKey: SearchConfigWithDefaulting = { @@ -160,13 +160,7 @@ describe('SearchService', () => { const customUrl = 'http://custom.endpoint.com/api'; const config: SearchConfigWithDefaulting = { ...configWithRequiredApiKey, - endpoints: - new EndpointsProvider( - Environment.PROD, - CloudRegion.US, - { - universalSearch: customUrl - }).getEndpoints() + endpoints: { ...defaultEndpoints, universalSearch: customUrl } }; const searchService: SearchServiceImpl = new SearchServiceImpl( config, diff --git a/tests/provideCore.ts b/tests/provideCore.ts index d4d0871b..4e7e36dc 100644 --- a/tests/provideCore.ts +++ b/tests/provideCore.ts @@ -1,4 +1,4 @@ -import { CloudRegion, EndpointsProvider, Environment } from '../src/constants'; +import { provideEndpoints } from '../src/constants'; import { AutocompleteServiceImpl } from '../src/infra/AutocompleteServiceImpl'; import { QuestionSubmissionServiceImpl } from '../src/infra/QuestionSubmissionServiceImpl'; import { SearchServiceImpl } from '../src/infra/SearchServiceImpl'; @@ -11,13 +11,10 @@ jest.mock('../src/infra/QuestionSubmissionServiceImpl'); jest.mock('../src/infra/SearchServiceImpl'); it('can specify custom endpoints', () => { - const customEndPoints: Required = - new EndpointsProvider( - Environment.SANDBOX, - CloudRegion.US, - { - verticalSearch: '' - }).getEndpoints(); + const customEndPoints: Required = { + ...provideEndpoints(), + verticalSearch: '' + }; provideCore({ apiKey: '', From 7c97fffe8ad28a360e69086be233059da79684e5 Mon Sep 17 00:00:00 2001 From: Emily Zhang Date: Wed, 3 May 2023 14:39:36 -0400 Subject: [PATCH 3/4] Rename file Change-Id: I1b13509a1ffb48c8a7def438260825407d3f0779 --- docs/search-core.cloudregion.md | 21 ++++++++++++++++++++ docs/search-core.environment.md | 21 ++++++++++++++++++++ docs/search-core.md | 2 ++ docs/search-core.provideendpoints.md | 4 ++-- etc/search-core.api.md | 19 +++++++++++++++--- src/index.ts | 2 +- src/infra/AutocompleteServiceImpl.ts | 2 +- src/infra/QuestionSubmissionServiceImpl.ts | 2 +- src/infra/SearchServiceImpl.ts | 2 +- src/provideCore.ts | 2 +- src/{constants.ts => provideEndpoints.ts} | 0 tests/infra/AutocompleteServiceImpl.ts | 2 +- tests/infra/QuestionSubmissionServiceImpl.ts | 2 +- tests/infra/SearchServiceImpl.ts | 2 +- tests/provideCore.ts | 2 +- 15 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 docs/search-core.cloudregion.md create mode 100644 docs/search-core.environment.md rename src/{constants.ts => provideEndpoints.ts} (100%) 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.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.md b/docs/search-core.md index 135ff458..5ff6ad3c 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. | diff --git a/docs/search-core.provideendpoints.md b/docs/search-core.provideendpoints.md index fcff8b30..bf7e5d31 100644 --- a/docs/search-core.provideendpoints.md +++ b/docs/search-core.provideendpoints.md @@ -16,8 +16,8 @@ export declare function provideEndpoints(environment?: Environment, cloudRegion? | Parameter | Type | Description | | --- | --- | --- | -| environment | Environment | environment of the domain to use, defaults to prod if not provided | -| cloudRegion | CloudRegion | cloud region of the domain to use, defaults to us if not provided | +| 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 | Returns: diff --git a/etc/search-core.api.md b/etc/search-core.api.md index 7f3ca3f9..aa590ea3 100644 --- a/etc/search-core.api.md +++ b/etc/search-core.api.md @@ -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) @@ -266,6 +274,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", @@ -511,9 +527,6 @@ export interface PhoneDirectAnswer extends BaseFieldValueDirectAnswer { // @public export function provideCore(config: SearchConfig): SearchCore; -// Warning: (ae-forgotten-export) The symbol "Environment" needs to be exported by the entry point index.d.ts -// Warning: (ae-forgotten-export) The symbol "CloudRegion" needs to be exported by the entry point index.d.ts -// // @public export function provideEndpoints(environment?: Environment, cloudRegion?: CloudRegion): Required; diff --git a/src/index.ts b/src/index.ts index 9ea0d3f8..75068996 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, SandboxEndpoints } from './constants'; +export { provideEndpoints, Environment, CloudRegion, 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/provideCore.ts b/src/provideCore.ts index f602cb5d..e40706a2 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 { provideEndpoints } from './constants'; +import { provideEndpoints } from './provideEndpoints'; /** * The entrypoint to the search-core library. diff --git a/src/constants.ts b/src/provideEndpoints.ts similarity index 100% rename from src/constants.ts rename to src/provideEndpoints.ts diff --git a/tests/infra/AutocompleteServiceImpl.ts b/tests/infra/AutocompleteServiceImpl.ts index 106210f5..bbea5cdf 100644 --- a/tests/infra/AutocompleteServiceImpl.ts +++ b/tests/infra/AutocompleteServiceImpl.ts @@ -11,7 +11,7 @@ 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/constants'; +import { defaultApiVersion, provideEndpoints } from '../../src/provideEndpoints'; import { ApiResponseValidator } from '../../src/validation/ApiResponseValidator'; import { ApiResponse } from '../../src/models/searchapi/ApiResponse'; import { SearchError } from '../../src/models/searchapi/SearchError'; diff --git a/tests/infra/QuestionSubmissionServiceImpl.ts b/tests/infra/QuestionSubmissionServiceImpl.ts index ef551e21..ed129481 100644 --- a/tests/infra/QuestionSubmissionServiceImpl.ts +++ b/tests/infra/QuestionSubmissionServiceImpl.ts @@ -3,7 +3,7 @@ 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, provideEndpoints } from '../../src/constants'; +import { defaultApiVersion, provideEndpoints } from '../../src/provideEndpoints'; const baseCoreConfig = { apiKey: 'anApiKey', diff --git a/tests/infra/SearchServiceImpl.ts b/tests/infra/SearchServiceImpl.ts index dd96d3d3..abc18a54 100644 --- a/tests/infra/SearchServiceImpl.ts +++ b/tests/infra/SearchServiceImpl.ts @@ -11,7 +11,7 @@ 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, provideEndpoints } from '../../src/constants'; +import { defaultApiVersion, provideEndpoints } from '../../src/provideEndpoints'; import { Endpoints } from '../../src/models/core/Endpoints'; const defaultEndpoints: Required = provideEndpoints(); diff --git a/tests/provideCore.ts b/tests/provideCore.ts index 4e7e36dc..d06c4463 100644 --- a/tests/provideCore.ts +++ b/tests/provideCore.ts @@ -1,4 +1,4 @@ -import { provideEndpoints } from '../src/constants'; +import { provideEndpoints } from '../src/provideEndpoints'; import { AutocompleteServiceImpl } from '../src/infra/AutocompleteServiceImpl'; import { QuestionSubmissionServiceImpl } from '../src/infra/QuestionSubmissionServiceImpl'; import { SearchServiceImpl } from '../src/infra/SearchServiceImpl'; From 9580032920bf996a9d706e3c3cf463b0ed32ea74 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 3 May 2023 18:40:40 +0000 Subject: [PATCH 4/4] Automated update to THIRD-PARTY-NOTICES from github action's 3rd party notices check --- THIRD-PARTY-NOTICES | 76 --------------------------------------------- 1 file changed, 76 deletions(-) diff --git a/THIRD-PARTY-NOTICES b/THIRD-PARTY-NOTICES index 1e6e3867..7e7197aa 100644 --- a/THIRD-PARTY-NOTICES +++ b/THIRD-PARTY-NOTICES @@ -157,82 +157,6 @@ This package contains the following license and notice below: ----------- -The following NPM package may be included in this product: - - - tsc@2.0.4 - -This package contains the following license and notice below: - -## DEPRECATED. - -Use [`typescript`](https://www.npmjs.com/package/typescript) to get access to the `tsc` CLI command. - ------------ - -The following NPM package may be included in this product: - - - typescript@5.0.4 - -This package contains the following license and notice below: - -Apache License - -Version 2.0, January 2004 - -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. - -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - -You must give any other recipients of the Work or Derivative Works a copy of this License; and - -You must cause any modified files to carry prominent notices stating that You changed the files; and - -You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and - -If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - ------------ - The following NPM package may be included in this product: - webidl-conversions@3.0.1