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.
@@ -22,7 +22,7 @@ import type { SearchMethodParams } from '../model/searchMethodParams';
22
22
  import type { SearchResponse } from '../model/searchResponse';
23
23
  import type { SearchResponses } from '../model/searchResponses';
24
24
 
25
- export const apiClientVersion = '5.2.5';
25
+ export const apiClientVersion = '5.3.1';
26
26
 
27
27
  function getDefaultHosts(appId: string): Host[] {
28
28
  return (
@@ -68,27 +68,26 @@ export function createLiteClient({
68
68
  ...options
69
69
  }: CreateClientOptions) {
70
70
  const auth = createAuth(appIdOption, apiKeyOption, authMode);
71
- const transporter = createTransporter({
72
- hosts: getDefaultHosts(appIdOption),
73
- ...options,
74
- algoliaAgent: getAlgoliaAgent({
75
- algoliaAgents,
76
- client: 'Lite',
77
- version: apiClientVersion,
78
- }),
79
- baseHeaders: {
80
- 'content-type': 'text/plain',
81
- ...auth.headers(),
82
- ...options.baseHeaders,
83
- },
84
- baseQueryParameters: {
85
- ...auth.queryParameters(),
86
- ...options.baseQueryParameters,
87
- },
88
- });
89
71
 
90
72
  return {
91
- transporter,
73
+ transporter: createTransporter({
74
+ hosts: getDefaultHosts(appIdOption),
75
+ ...options,
76
+ algoliaAgent: getAlgoliaAgent({
77
+ algoliaAgents,
78
+ client: 'Lite',
79
+ version: apiClientVersion,
80
+ }),
81
+ baseHeaders: {
82
+ 'content-type': 'text/plain',
83
+ ...auth.headers(),
84
+ ...options.baseHeaders,
85
+ },
86
+ baseQueryParameters: {
87
+ ...auth.queryParameters(),
88
+ ...options.baseQueryParameters,
89
+ },
90
+ }),
92
91
 
93
92
  /**
94
93
  * The `appId` currently in use.
@@ -99,14 +98,16 @@ export function createLiteClient({
99
98
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
100
99
  */
101
100
  clearCache(): Promise<void> {
102
- return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined);
101
+ return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
102
+ () => undefined,
103
+ );
103
104
  },
104
105
 
105
106
  /**
106
107
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
107
108
  */
108
109
  get _ua(): string {
109
- return transporter.algoliaAgent.value;
110
+ return this.transporter.algoliaAgent.value;
110
111
  },
111
112
 
112
113
  /**
@@ -116,7 +117,21 @@ export function createLiteClient({
116
117
  * @param version - The version of the agent.
117
118
  */
118
119
  addAlgoliaAgent(segment: string, version?: string): void {
119
- transporter.algoliaAgent.add({ segment, version });
120
+ this.transporter.algoliaAgent.add({ segment, version });
121
+ },
122
+
123
+ /**
124
+ * Helper method to switch the API key used to authenticate the requests.
125
+ *
126
+ * @param params - Method params.
127
+ * @param params.apiKey - The new API Key to use.
128
+ */
129
+ setClientApiKey({ apiKey }: { apiKey: string }): void {
130
+ if (!authMode || authMode === 'WithinHeaders') {
131
+ this.transporter.baseHeaders['x-algolia-api-key'] = apiKey;
132
+ } else {
133
+ this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey;
134
+ }
120
135
  },
121
136
  /**
122
137
  * Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets.
@@ -178,7 +193,7 @@ export function createLiteClient({
178
193
  data: body ? body : {},
179
194
  };
180
195
 
181
- return transporter.request(request, requestOptions);
196
+ return this.transporter.request(request, requestOptions);
182
197
  },
183
198
 
184
199
  /**
@@ -225,7 +240,7 @@ export function createLiteClient({
225
240
  cacheable: true,
226
241
  };
227
242
 
228
- return transporter.request(request, requestOptions);
243
+ return this.transporter.request(request, requestOptions);
229
244
  },
230
245
 
231
246
  /**
@@ -288,7 +303,7 @@ export function createLiteClient({
288
303
  cacheable: true,
289
304
  };
290
305
 
291
- return transporter.request(request, requestOptions);
306
+ return this.transporter.request(request, requestOptions);
292
307
  },
293
308
  };
294
309
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.2.5",
2
+ "version": "5.3.1",
3
3
  "repository": {
4
4
  "type": "git",
5
5
  "url": "git+https://github.com/algolia/algoliasearch-client-javascript.git"
@@ -65,14 +65,14 @@
65
65
  "lite.d.ts"
66
66
  ],
67
67
  "dependencies": {
68
- "@algolia/client-abtesting": "5.2.5",
69
- "@algolia/client-analytics": "5.2.5",
70
- "@algolia/client-common": "5.2.5",
71
- "@algolia/client-personalization": "5.2.5",
72
- "@algolia/client-search": "5.2.5",
73
- "@algolia/recommend": "5.2.5",
74
- "@algolia/requester-browser-xhr": "5.2.5",
75
- "@algolia/requester-node-http": "5.2.5"
68
+ "@algolia/client-abtesting": "5.3.1",
69
+ "@algolia/client-analytics": "5.3.1",
70
+ "@algolia/client-common": "5.3.1",
71
+ "@algolia/client-personalization": "5.3.1",
72
+ "@algolia/client-search": "5.3.1",
73
+ "@algolia/recommend": "5.3.1",
74
+ "@algolia/requester-browser-xhr": "5.3.1",
75
+ "@algolia/requester-node-http": "5.3.1"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@arethetypeswrong/cli": "0.15.4",