1
- { {#nodeSearchHelpers} }
2
- import { createHmac } from 'node:crypto';
3
- { {/nodeSearchHelpers} }
4
-
5
- import {
6
- DEFAULT_CONNECT_TIMEOUT_BROWSER,
7
- DEFAULT_CONNECT_TIMEOUT_NODE,
8
- DEFAULT_READ_TIMEOUT_BROWSER,
9
- DEFAULT_READ_TIMEOUT_NODE,
10
- DEFAULT_WRITE_TIMEOUT_BROWSER,
11
- DEFAULT_WRITE_TIMEOUT_NODE,
12
- createBrowserLocalStorageCache,
13
- createFallbackableCache,
14
- createMemoryCache,
15
- createNullCache,
16
- serializeQueryParameters,
17
- } from '@algolia/client-common';
1
+ // { {{generationBanner} }}
18
2
19
3
import type { ClientOptions } from '@algolia/client-common';
20
4
import type { AbtestingClient, Region as AbtestingRegion } from "@algolia/client-abtesting"
21
5
import type { AnalyticsClient, Region as AnalyticsRegion } from "@algolia/client-analytics"
22
6
import type { PersonalizationClient, Region as PersonalizationRegion } from "@algolia/client-personalization"
23
7
import type { RecommendClient } from "@algolia/recommend"
8
+ import type { SearchClient } from "@algolia/client-search"
24
9
25
- import { createXhrRequester } from '@algolia/requester-browser-xhr';
26
- import { createHttpRequester } from '@algolia/requester-node-http';
27
10
import { abtestingClient } from '@algolia/client-abtesting';
28
11
import { analyticsClient } from '@algolia/client-analytics';
29
12
import { personalizationClient } from '@algolia/client-personalization';
@@ -33,29 +16,65 @@ import { recommendClient } from '@algolia/recommend';
33
16
import type {
34
17
InitClientOptions,
35
18
InitClientRegion,
36
- GenerateSecuredApiKeyOptions,
37
- GetSecuredApiKeyRemainingValidityOptions,
38
19
} from './models';
39
20
40
- import { apiClientVersion } from './models';
41
-
42
21
export * from './models';
43
22
44
- /**
45
- * The client type.
46
- */
47
- export type Algoliasearch = ReturnType<typeof algoliasearch >;
48
-
49
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
50
- export function algoliasearch(
51
- appId: string,
52
- apiKey: string,
53
- options?: ClientOptions
54
- ) {
23
+ export type Algoliasearch = SearchClient & {
24
+ initRecommend: (initOptions: InitClientOptions)=> RecommendClient;
25
+ initAnalytics: (initOptions: InitClientOptions & InitClientRegion< AnalyticsRegion> )=> AnalyticsClient;
26
+ initAbtesting: (initOptions: InitClientOptions & InitClientRegion< AbtestingRegion> )=> AbtestingClient;
27
+ initPersonalization: (initOptions: InitClientOptions & Required< InitClientRegion< PersonalizationRegion>> )=> PersonalizationClient;
28
+ } ;
29
+
30
+ export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions): Algoliasearch {
55
31
if (! appId || typeof appId !== ' string' ) {
56
32
throw new Error(' `appId` is missing.' );
57
33
}
58
34
59
35
if (!apiKey || typeof apiKey !== 'string') {
60
36
throw new Error(' `apiKey` is missing.' );
61
- }
37
+ }
38
+
39
+ return {
40
+ ...searchClient(appId, apiKey, options),
41
+ /**
42
+ * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
43
+ */
44
+ get _ua(): string {
45
+ return this.transporter.algoliaAgent.value;
46
+ } ,
47
+ initRecommend: (initOptions: InitClientOptions = { } ): RecommendClient => {
48
+ return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
49
+ } ,
50
+
51
+ initAnalytics: (initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion > = { } ): AnalyticsClient => {
52
+ return analyticsClient(
53
+ initOptions.appId || appId,
54
+ initOptions.apiKey || apiKey,
55
+ initOptions.region,
56
+ initOptions.options,
57
+ );
58
+ } ,
59
+
60
+ initAbtesting: (initOptions: InitClientOptions & InitClientRegion<AbtestingRegion > = { } ): AbtestingClient => {
61
+ return abtestingClient(
62
+ initOptions.appId || appId,
63
+ initOptions.apiKey || apiKey,
64
+ initOptions.region,
65
+ initOptions.options,
66
+ );
67
+ } ,
68
+
69
+ initPersonalization: (
70
+ initOptions: InitClientOptions & Required<InitClientRegion <PersonalizationRegion >>,
71
+ ): PersonalizationClient => {
72
+ return personalizationClient(
73
+ initOptions.appId || appId,
74
+ initOptions.apiKey || apiKey,
75
+ initOptions.region,
76
+ initOptions.options,
77
+ );
78
+ } ,
79
+ }
80
+ }
0 commit comments