algoliasearch 5.2.5 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/builds/browser.ts CHANGED
@@ -4,34 +4,28 @@ import type { AbtestingClient, Region as AbtestingRegion } from '@algolia/client
4
4
  import { abtestingClient } from '@algolia/client-abtesting';
5
5
  import type { AnalyticsClient, Region as AnalyticsRegion } from '@algolia/client-analytics';
6
6
  import { analyticsClient } from '@algolia/client-analytics';
7
- import {
8
- DEFAULT_CONNECT_TIMEOUT_BROWSER,
9
- DEFAULT_READ_TIMEOUT_BROWSER,
10
- DEFAULT_WRITE_TIMEOUT_BROWSER,
11
- createBrowserLocalStorageCache,
12
- createFallbackableCache,
13
- createMemoryCache,
14
- } from '@algolia/client-common';
15
7
  import type { ClientOptions } from '@algolia/client-common';
16
8
  import type { PersonalizationClient, Region as PersonalizationRegion } from '@algolia/client-personalization';
17
9
  import { personalizationClient } from '@algolia/client-personalization';
10
+ import type { SearchClient } from '@algolia/client-search';
18
11
  import { searchClient } from '@algolia/client-search';
19
12
  import type { RecommendClient } from '@algolia/recommend';
20
13
  import { recommendClient } from '@algolia/recommend';
21
- import { createXhrRequester } from '@algolia/requester-browser-xhr';
22
14
 
23
15
  import type { InitClientOptions, InitClientRegion } from './models';
24
- import { apiClientVersion } from './models';
25
16
 
26
17
  export * from './models';
27
18
 
28
- /**
29
- * The client type.
30
- */
31
- export type Algoliasearch = ReturnType<typeof algoliasearch>;
19
+ export type Algoliasearch = SearchClient & {
20
+ initRecommend: (initOptions: InitClientOptions) => RecommendClient;
21
+ initAnalytics: (initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion>) => AnalyticsClient;
22
+ initAbtesting: (initOptions: InitClientOptions & InitClientRegion<AbtestingRegion>) => AbtestingClient;
23
+ initPersonalization: (
24
+ initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
25
+ ) => PersonalizationClient;
26
+ };
32
27
 
33
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
34
- export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions) {
28
+ export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions): Algoliasearch {
35
29
  if (!appId || typeof appId !== 'string') {
36
30
  throw new Error('`appId` is missing.');
37
31
  }
@@ -39,65 +33,46 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt
39
33
  if (!apiKey || typeof apiKey !== 'string') {
40
34
  throw new Error('`apiKey` is missing.');
41
35
  }
42
- function initRecommend(initOptions: InitClientOptions = {}): RecommendClient {
43
- return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
44
- }
45
-
46
- function initAnalytics(initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion> = {}): AnalyticsClient {
47
- return analyticsClient(
48
- initOptions.appId || appId,
49
- initOptions.apiKey || apiKey,
50
- initOptions.region,
51
- initOptions.options,
52
- );
53
- }
54
-
55
- function initAbtesting(initOptions: InitClientOptions & InitClientRegion<AbtestingRegion> = {}): AbtestingClient {
56
- return abtestingClient(
57
- initOptions.appId || appId,
58
- initOptions.apiKey || apiKey,
59
- initOptions.region,
60
- initOptions.options,
61
- );
62
- }
63
-
64
- function initPersonalization(
65
- initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
66
- ): PersonalizationClient {
67
- return personalizationClient(
68
- initOptions.appId || appId,
69
- initOptions.apiKey || apiKey,
70
- initOptions.region,
71
- initOptions.options,
72
- );
73
- }
74
36
 
75
37
  return {
76
- ...searchClient(appId, apiKey, {
77
- timeouts: {
78
- connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
79
- read: DEFAULT_READ_TIMEOUT_BROWSER,
80
- write: DEFAULT_WRITE_TIMEOUT_BROWSER,
81
- },
82
- requester: createXhrRequester(),
83
- algoliaAgents: [{ segment: 'Browser' }],
84
- authMode: 'WithinQueryParameters',
85
- responsesCache: createMemoryCache(),
86
- requestsCache: createMemoryCache({ serializable: false }),
87
- hostsCache: createFallbackableCache({
88
- caches: [createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), createMemoryCache()],
89
- }),
90
- ...options,
91
- }),
38
+ ...searchClient(appId, apiKey, options),
92
39
  /**
93
40
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
94
41
  */
95
42
  get _ua(): string {
96
43
  return this.transporter.algoliaAgent.value;
97
44
  },
98
- initAbtesting,
99
- initAnalytics,
100
- initPersonalization,
101
- initRecommend,
45
+ initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => {
46
+ return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
47
+ },
48
+
49
+ initAnalytics: (initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion> = {}): AnalyticsClient => {
50
+ return analyticsClient(
51
+ initOptions.appId || appId,
52
+ initOptions.apiKey || apiKey,
53
+ initOptions.region,
54
+ initOptions.options,
55
+ );
56
+ },
57
+
58
+ initAbtesting: (initOptions: InitClientOptions & InitClientRegion<AbtestingRegion> = {}): AbtestingClient => {
59
+ return abtestingClient(
60
+ initOptions.appId || appId,
61
+ initOptions.apiKey || apiKey,
62
+ initOptions.region,
63
+ initOptions.options,
64
+ );
65
+ },
66
+
67
+ initPersonalization: (
68
+ initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
69
+ ): PersonalizationClient => {
70
+ return personalizationClient(
71
+ initOptions.appId || appId,
72
+ initOptions.apiKey || apiKey,
73
+ initOptions.region,
74
+ initOptions.options,
75
+ );
76
+ },
102
77
  };
103
78
  }
package/builds/models.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // 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.
2
2
 
3
- import type { Region as ABTestingRegion } from '@algolia/client-abtesting';
3
+ import type { Region as AbTestingRegion } from '@algolia/client-abtesting';
4
4
  import type { Region as AnalyticsRegion } from '@algolia/client-analytics';
5
5
  import type { ClientOptions } from '@algolia/client-common';
6
6
  import type {
@@ -79,7 +79,7 @@ import type {
79
79
  } from '@algolia/client-search';
80
80
  import { apiClientVersion } from '@algolia/client-search';
81
81
 
82
- type Region = ABTestingRegion | AnalyticsRegion;
82
+ type Region = AbTestingRegion | AnalyticsRegion;
83
83
 
84
84
  export * from '@algolia/client-search';
85
85
  export * from '@algolia/recommend';
@@ -161,7 +161,7 @@ export {
161
161
  TypoToleranceEnum,
162
162
  Value,
163
163
  AnalyticsRegion,
164
- ABTestingRegion,
164
+ AbTestingRegion,
165
165
  Region,
166
166
  apiClientVersion,
167
167
  };
package/builds/node.ts CHANGED
@@ -1,43 +1,31 @@
1
1
  // 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.
2
2
 
3
- import { createHmac } from 'node:crypto';
4
-
5
3
  import type { AbtestingClient, Region as AbtestingRegion } from '@algolia/client-abtesting';
6
4
  import { abtestingClient } from '@algolia/client-abtesting';
7
5
  import type { AnalyticsClient, Region as AnalyticsRegion } from '@algolia/client-analytics';
8
6
  import { analyticsClient } from '@algolia/client-analytics';
9
- import {
10
- DEFAULT_CONNECT_TIMEOUT_NODE,
11
- DEFAULT_READ_TIMEOUT_NODE,
12
- DEFAULT_WRITE_TIMEOUT_NODE,
13
- createMemoryCache,
14
- createNullCache,
15
- serializeQueryParameters,
16
- } from '@algolia/client-common';
17
7
  import type { ClientOptions } from '@algolia/client-common';
18
8
  import type { PersonalizationClient, Region as PersonalizationRegion } from '@algolia/client-personalization';
19
9
  import { personalizationClient } from '@algolia/client-personalization';
10
+ import type { SearchClient } from '@algolia/client-search';
20
11
  import { searchClient } from '@algolia/client-search';
21
12
  import type { RecommendClient } from '@algolia/recommend';
22
13
  import { recommendClient } from '@algolia/recommend';
23
- import { createHttpRequester } from '@algolia/requester-node-http';
24
14
 
25
- import type {
26
- InitClientOptions,
27
- InitClientRegion,
28
- GenerateSecuredApiKeyOptions,
29
- GetSecuredApiKeyRemainingValidityOptions,
30
- } from './models';
15
+ import type { InitClientOptions, InitClientRegion } from './models';
31
16
 
32
17
  export * from './models';
33
18
 
34
- /**
35
- * The client type.
36
- */
37
- export type Algoliasearch = ReturnType<typeof algoliasearch>;
19
+ export type Algoliasearch = SearchClient & {
20
+ initRecommend: (initOptions: InitClientOptions) => RecommendClient;
21
+ initAnalytics: (initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion>) => AnalyticsClient;
22
+ initAbtesting: (initOptions: InitClientOptions & InitClientRegion<AbtestingRegion>) => AbtestingClient;
23
+ initPersonalization: (
24
+ initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
25
+ ) => PersonalizationClient;
26
+ };
38
27
 
39
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
40
- export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions) {
28
+ export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions): Algoliasearch {
41
29
  if (!appId || typeof appId !== 'string') {
42
30
  throw new Error('`appId` is missing.');
43
31
  }
@@ -45,117 +33,46 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt
45
33
  if (!apiKey || typeof apiKey !== 'string') {
46
34
  throw new Error('`apiKey` is missing.');
47
35
  }
48
- function initRecommend(initOptions: InitClientOptions = {}): RecommendClient {
49
- return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
50
- }
51
-
52
- function initAnalytics(initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion> = {}): AnalyticsClient {
53
- return analyticsClient(
54
- initOptions.appId || appId,
55
- initOptions.apiKey || apiKey,
56
- initOptions.region,
57
- initOptions.options,
58
- );
59
- }
60
-
61
- function initAbtesting(initOptions: InitClientOptions & InitClientRegion<AbtestingRegion> = {}): AbtestingClient {
62
- return abtestingClient(
63
- initOptions.appId || appId,
64
- initOptions.apiKey || apiKey,
65
- initOptions.region,
66
- initOptions.options,
67
- );
68
- }
69
-
70
- function initPersonalization(
71
- initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
72
- ): PersonalizationClient {
73
- return personalizationClient(
74
- initOptions.appId || appId,
75
- initOptions.apiKey || apiKey,
76
- initOptions.region,
77
- initOptions.options,
78
- );
79
- }
80
36
 
81
37
  return {
82
- ...searchClient(appId, apiKey, {
83
- timeouts: {
84
- connect: DEFAULT_CONNECT_TIMEOUT_NODE,
85
- read: DEFAULT_READ_TIMEOUT_NODE,
86
- write: DEFAULT_WRITE_TIMEOUT_NODE,
87
- },
88
- requester: createHttpRequester(),
89
- algoliaAgents: [{ segment: 'Node.js', version: process.versions.node }],
90
- responsesCache: createNullCache(),
91
- requestsCache: createNullCache(),
92
- hostsCache: createMemoryCache(),
93
- ...options,
94
- }),
38
+ ...searchClient(appId, apiKey, options),
95
39
  /**
96
40
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
97
41
  */
98
42
  get _ua(): string {
99
43
  return this.transporter.algoliaAgent.value;
100
44
  },
101
- initAbtesting,
102
- initAnalytics,
103
- initPersonalization,
104
- initRecommend,
105
- /**
106
- * Helper: Generates a secured API key based on the given `parentApiKey` and given `restrictions`.
107
- *
108
- * @summary Helper: Generates a secured API key based on the given `parentApiKey` and given `restrictions`.
109
- * @param generateSecuredApiKey - The `generateSecuredApiKey` object.
110
- * @param generateSecuredApiKey.parentApiKey - The base API key from which to generate the new secured one.
111
- * @param generateSecuredApiKey.restrictions - A set of properties defining the restrictions of the secured API key.
112
- */
113
- generateSecuredApiKey({ parentApiKey, restrictions = {} }: GenerateSecuredApiKeyOptions): string {
114
- let mergedRestrictions = restrictions;
115
- if (restrictions.searchParams) {
116
- // merge searchParams with the root restrictions
117
- mergedRestrictions = {
118
- ...restrictions,
119
- ...restrictions.searchParams,
120
- };
121
-
122
- delete mergedRestrictions.searchParams;
123
- }
124
-
125
- mergedRestrictions = Object.keys(mergedRestrictions)
126
- .sort()
127
- .reduce(
128
- (acc, key) => {
129
- // eslint-disable-next-line no-param-reassign
130
- acc[key] = (mergedRestrictions as any)[key];
131
- return acc;
132
- },
133
- {} as Record<string, unknown>,
134
- );
135
-
136
- const queryParameters = serializeQueryParameters(mergedRestrictions);
137
- return Buffer.from(
138
- createHmac('sha256', parentApiKey).update(queryParameters).digest('hex') + queryParameters,
139
- ).toString('base64');
45
+ initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => {
46
+ return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options);
140
47
  },
141
48
 
142
- /**
143
- * Helper: Retrieves the remaining validity of the previous generated `securedApiKey`, the `ValidUntil` parameter must have been provided.
144
- *
145
- * @summary Helper: Retrieves the remaining validity of the previous generated `secured_api_key`, the `ValidUntil` parameter must have been provided.
146
- * @param getSecuredApiKeyRemainingValidity - The `getSecuredApiKeyRemainingValidity` object.
147
- * @param getSecuredApiKeyRemainingValidity.securedApiKey - The secured API key generated with the `generateSecuredApiKey` method.
148
- */
149
- getSecuredApiKeyRemainingValidity({ securedApiKey }: GetSecuredApiKeyRemainingValidityOptions): number {
150
- const decodedString = Buffer.from(securedApiKey, 'base64').toString('ascii');
151
- const regex = /validUntil=(\d+)/;
152
- const match = decodedString.match(regex);
49
+ initAnalytics: (initOptions: InitClientOptions & InitClientRegion<AnalyticsRegion> = {}): AnalyticsClient => {
50
+ return analyticsClient(
51
+ initOptions.appId || appId,
52
+ initOptions.apiKey || apiKey,
53
+ initOptions.region,
54
+ initOptions.options,
55
+ );
56
+ },
153
57
 
154
- if (match === null) {
155
- throw new Error('validUntil not found in given secured api key.');
156
- }
58
+ initAbtesting: (initOptions: InitClientOptions & InitClientRegion<AbtestingRegion> = {}): AbtestingClient => {
59
+ return abtestingClient(
60
+ initOptions.appId || appId,
61
+ initOptions.apiKey || apiKey,
62
+ initOptions.region,
63
+ initOptions.options,
64
+ );
65
+ },
157
66
 
158
- return parseInt(match[1], 10) - Math.round(new Date().getTime() / 1000);
67
+ initPersonalization: (
68
+ initOptions: InitClientOptions & Required<InitClientRegion<PersonalizationRegion>>,
69
+ ): PersonalizationClient => {
70
+ return personalizationClient(
71
+ initOptions.appId || appId,
72
+ initOptions.apiKey || apiKey,
73
+ initOptions.region,
74
+ initOptions.options,
75
+ );
159
76
  },
160
77
  };
161
78
  }