File tree Expand file tree Collapse file tree 3 files changed +41
-4
lines changed
client-common/src/__tests__ Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,34 @@ describe('default preset', () => {
146146 expect ( recommendation . transporter . userAgent ) . toBe ( client . transporter . userAgent ) ;
147147 } ) ;
148148
149+ test ( 'allows clients to override credentials' , ( ) => {
150+ const clientWithOptions = algoliasearch ( 'appId' , 'apiKey' ) ;
151+
152+ expect ( clientWithOptions . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'apiKey' ) ;
153+
154+ const analytics = clientWithOptions . initAnalytics ( {
155+ apiKey : 'analytics' ,
156+ } ) ;
157+ const recommendation = clientWithOptions . initRecommendation ( {
158+ apiKey : 'recommendation' ,
159+ } ) ;
160+
161+ expect ( analytics . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'analytics' ) ;
162+ expect ( recommendation . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'recommendation' ) ;
163+ } ) ;
164+
165+ test ( 'allows clients to keep default credentials' , ( ) => {
166+ const clientWithOptions = algoliasearch ( 'appId' , 'apiKey' ) ;
167+
168+ expect ( clientWithOptions . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'apiKey' ) ;
169+
170+ const analytics = clientWithOptions . initAnalytics ( ) ;
171+ const recommendation = clientWithOptions . initRecommendation ( ) ;
172+
173+ expect ( analytics . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'apiKey' ) ;
174+ expect ( recommendation . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'apiKey' ) ;
175+ } ) ;
176+
149177 it ( 'can be destroyed' , ( ) => {
150178 if ( ! testing . isBrowser ( ) ) {
151179 expect ( client ) . toHaveProperty ( 'destroy' ) ;
Original file line number Diff line number Diff line change @@ -3,13 +3,22 @@ import { ClientTransporterOptions } from '@algolia/client-common';
33import { RecommendationClientOptions } from '@algolia/client-recommendation' ;
44import { SearchClientOptions } from '@algolia/client-search' ;
55
6- export type WithoutCredentials < TClient > = Omit < TClient , 'appId' | 'apiKey' > ;
6+ type Credentials = { readonly appId : string ; readonly apiKey : string } ;
7+ export type WithoutCredentials < TClientOptions extends Credentials > = Omit <
8+ TClientOptions ,
9+ keyof Credentials
10+ > ;
11+ export type OptionalCredentials < TClientOptions extends Credentials > = Omit <
12+ TClientOptions ,
13+ keyof Credentials
14+ > &
15+ Pick < Partial < TClientOptions > , keyof Credentials > ;
716
817export type AlgoliaSearchOptions = Partial < ClientTransporterOptions > &
918 WithoutCredentials < SearchClientOptions > ;
1019
1120export type InitAnalyticsOptions = Partial < ClientTransporterOptions > &
12- WithoutCredentials < AnalyticsClientOptions > ;
21+ OptionalCredentials < AnalyticsClientOptions > ;
1322
1423export type InitRecommendationOptions = Partial < ClientTransporterOptions > &
15- WithoutCredentials < RecommendationClientOptions > ;
24+ OptionalCredentials < RecommendationClientOptions > ;
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ export class TestSuite {
4949 client . transporter . hosts = [ client . transporter . hosts [ 2 ] ] ;
5050
5151 // Also, since we are targeting always the same host, the
52- // server may take a litle more than expected to answer.
52+ // server may take a little more than expected to answer.
5353 // To avoid timeouts we increase the timeouts duration
5454 // @ts -ignore
5555 client . transporter . timeouts = {
You can’t perform that action at this time.
0 commit comments