11// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
22
3- import type { AbtestingClient } from '@algolia/client-abtesting' ;
4- import type { Region as AbtestingRegion } from '@algolia/client-abtesting/src/abtestingClient' ;
5- import { createAbtestingClient , REGIONS as abtestingRegions } from '@algolia/client-abtesting/src/abtestingClient' ;
6- import type { AnalyticsClient } from '@algolia/client-analytics' ;
7- import { createAnalyticsClient , REGIONS as analyticsRegions } from '@algolia/client-analytics/src/analyticsClient' ;
8- import type { Region as AnalyticsRegion } from '@algolia/client-analytics/src/analyticsClient' ;
3+ import type { AbtestingClient , Region as AbtestingRegion } from '@algolia/client-abtesting' ;
4+ import { abtestingClient } from '@algolia/client-abtesting' ;
5+ import type { AnalyticsClient , Region as AnalyticsRegion } from '@algolia/client-analytics' ;
6+ import { analyticsClient } from '@algolia/client-analytics' ;
7+ import type { ClientOptions } from '@algolia/client-common' ;
98import {
109 DEFAULT_CONNECT_TIMEOUT_BROWSER ,
1110 DEFAULT_READ_TIMEOUT_BROWSER ,
@@ -14,16 +13,11 @@ import {
1413 createFallbackableCache ,
1514 createMemoryCache ,
1615} from '@algolia/client-common' ;
17- import type { ClientOptions , CreateClientOptions } from '@algolia/client-common' ;
18- import type { PersonalizationClient } from '@algolia/client-personalization' ;
19- import type { Region as PersonalizationRegion } from '@algolia/client-personalization/src/personalizationClient' ;
20- import {
21- createPersonalizationClient ,
22- REGIONS as personalizationRegions ,
23- } from '@algolia/client-personalization/src/personalizationClient' ;
24- import { createSearchClient , apiClientVersion as searchClientVersion } from '@algolia/client-search/src/searchClient' ;
16+ import type { PersonalizationClient , Region as PersonalizationRegion } from '@algolia/client-personalization' ;
17+ import { personalizationClient } from '@algolia/client-personalization' ;
18+ import { searchClient , apiClientVersion as searchClientVersion } from '@algolia/client-search' ;
2519import type { RecommendClient } from '@algolia/recommend' ;
26- import { createRecommendClient } from '@algolia/recommend/src/recommendClient ' ;
20+ import { recommendClient } from '@algolia/recommend' ;
2721import { createXhrRequester } from '@algolia/requester-browser-xhr' ;
2822
2923import type { InitClientOptions , InitClientRegion } from './models' ;
@@ -46,83 +40,57 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt
4640 if ( ! apiKey || typeof apiKey !== 'string' ) {
4741 throw new Error ( '`apiKey` is missing.' ) ;
4842 }
49- const commonOptions : CreateClientOptions = {
50- apiKey,
51- appId,
52- timeouts : {
53- connect : DEFAULT_CONNECT_TIMEOUT_BROWSER ,
54- read : DEFAULT_READ_TIMEOUT_BROWSER ,
55- write : DEFAULT_WRITE_TIMEOUT_BROWSER ,
56- } ,
57- requester : createXhrRequester ( ) ,
58- algoliaAgents : [ { segment : 'Browser' } ] ,
59- authMode : 'WithinQueryParameters' ,
60- responsesCache : createMemoryCache ( ) ,
61- requestsCache : createMemoryCache ( { serializable : false } ) ,
62- hostsCache : createFallbackableCache ( {
63- caches : [ createBrowserLocalStorageCache ( { key : `${ apiClientVersion } -${ appId } ` } ) , createMemoryCache ( ) ] ,
64- } ) ,
65- ...options ,
66- } ;
6743
6844 function initRecommend ( initOptions : InitClientOptions = { } ) : RecommendClient {
69- return createRecommendClient ( {
70- ...commonOptions ,
71- ...initOptions . options ,
72- ...initOptions ,
73- } ) ;
45+ return recommendClient ( initOptions . appId || appId , initOptions . apiKey || apiKey , initOptions . options ) ;
7446 }
7547
7648 function initAnalytics ( initOptions : InitClientOptions & InitClientRegion < AnalyticsRegion > = { } ) : AnalyticsClient {
77- if (
78- initOptions . region &&
79- ( typeof initOptions . region !== 'string' || ! analyticsRegions . includes ( initOptions . region ) )
80- ) {
81- throw new Error ( `\`region\` must be one of the following: ${ analyticsRegions . join ( ', ' ) } ` ) ;
82- }
83-
84- return createAnalyticsClient ( {
85- ...commonOptions ,
86- ...initOptions . options ,
87- ...initOptions ,
88- } ) ;
49+ return analyticsClient (
50+ initOptions . appId || appId ,
51+ initOptions . apiKey || apiKey ,
52+ initOptions . region ,
53+ initOptions . options ,
54+ ) ;
8955 }
9056
9157 function initAbtesting ( initOptions : InitClientOptions & InitClientRegion < AbtestingRegion > = { } ) : AbtestingClient {
92- if (
93- initOptions . region &&
94- ( typeof initOptions . region !== 'string' || ! abtestingRegions . includes ( initOptions . region ) )
95- ) {
96- throw new Error ( `\`region\` must be one of the following: ${ abtestingRegions . join ( ', ' ) } ` ) ;
97- }
98-
99- return createAbtestingClient ( {
100- ...commonOptions ,
101- ...initOptions . options ,
102- ...initOptions ,
103- } ) ;
58+ return abtestingClient (
59+ initOptions . appId || appId ,
60+ initOptions . apiKey || apiKey ,
61+ initOptions . region ,
62+ initOptions . options ,
63+ ) ;
10464 }
10565
10666 function initPersonalization (
10767 initOptions : InitClientOptions & Required < InitClientRegion < PersonalizationRegion > > ,
10868 ) : PersonalizationClient {
109- if (
110- ! initOptions . region ||
111- ( initOptions . region &&
112- ( typeof initOptions . region !== 'string' || ! personalizationRegions . includes ( initOptions . region ) ) )
113- ) {
114- throw new Error ( `\`region\` is required and must be one of the following: ${ personalizationRegions . join ( ', ' ) } ` ) ;
115- }
116-
117- return createPersonalizationClient ( {
118- ...commonOptions ,
119- ...initOptions . options ,
120- ...initOptions ,
121- } ) ;
69+ return personalizationClient (
70+ initOptions . appId || appId ,
71+ initOptions . apiKey || apiKey ,
72+ initOptions . region ,
73+ initOptions . options ,
74+ ) ;
12275 }
12376
12477 return {
125- ...createSearchClient ( commonOptions ) ,
78+ ...searchClient ( appId , apiKey , {
79+ timeouts : {
80+ connect : DEFAULT_CONNECT_TIMEOUT_BROWSER ,
81+ read : DEFAULT_READ_TIMEOUT_BROWSER ,
82+ write : DEFAULT_WRITE_TIMEOUT_BROWSER ,
83+ } ,
84+ requester : createXhrRequester ( ) ,
85+ algoliaAgents : [ { segment : 'Browser' } ] ,
86+ authMode : 'WithinQueryParameters' ,
87+ responsesCache : createMemoryCache ( ) ,
88+ requestsCache : createMemoryCache ( { serializable : false } ) ,
89+ hostsCache : createFallbackableCache ( {
90+ caches : [ createBrowserLocalStorageCache ( { key : `${ apiClientVersion } -${ appId } ` } ) , createMemoryCache ( ) ] ,
91+ } ) ,
92+ ...options ,
93+ } ) ,
12694 /**
12795 * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
12896 */
0 commit comments