@algolia/client-search 5.56.0 → 5.57.0

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/README.md CHANGED
@@ -40,11 +40,11 @@ All of our clients comes with type definition, and are available for both browse
40
40
  ### With a package manager
41
41
 
42
42
  ```bash
43
- yarn add @algolia/client-search@5.56.0
43
+ yarn add @algolia/client-search@5.57.0
44
44
  # or
45
- npm install @algolia/client-search@5.56.0
45
+ npm install @algolia/client-search@5.57.0
46
46
  # or
47
- pnpm add @algolia/client-search@5.56.0
47
+ pnpm add @algolia/client-search@5.57.0
48
48
  ```
49
49
 
50
50
  ### Without a package manager
@@ -52,7 +52,7 @@ pnpm add @algolia/client-search@5.56.0
52
52
  Add the following JavaScript snippet to the <head> of your website:
53
53
 
54
54
  ```html
55
- <script src="https://cdn.jsdelivr.net/npm/@algolia/client-search@5.56.0/dist/builds/browser.umd.js"></script>
55
+ <script src="https://cdn.jsdelivr.net/npm/@algolia/client-search@5.57.0/dist/builds/browser.umd.js"></script>
56
56
  ```
57
57
 
58
58
  ### Usage
package/dist/browser.d.ts CHANGED
@@ -3242,7 +3242,7 @@ type AccountCopyIndexOptions = ChunkedHelperOptions & {
3242
3242
  batchSize?: number | undefined;
3243
3243
  };
3244
3244
 
3245
- declare const apiClientVersion = "5.56.0";
3245
+ declare const apiClientVersion = "5.57.0";
3246
3246
  declare function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, ...options }: CreateClientOptions): {
3247
3247
  transporter: _algolia_client_common.TransporterWithHttpInfo;
3248
3248
  /**
@@ -3407,6 +3407,8 @@ declare function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption,
3407
3407
  * Helper: Replaces all objects (records) in the given `index_name` with the given `objects`. A temporary index is created during this process in order to backup your data.
3408
3408
  * See https://api-clients-automation.netlify.app/docs/custom-helpers/#replaceallobjects for implementation details.
3409
3409
  *
3410
+ * Warning: calling this method with an empty `objects` list replaces the index with an empty one, deleting all existing records.
3411
+ *
3410
3412
  * @summary Helper: Replaces all objects (records) in the given `index_name` with the given `objects`. A temporary index is created during this process in order to backup your data.
3411
3413
  * @param replaceAllObjects - The `replaceAllObjects` object.
3412
3414
  * @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
@@ -3417,7 +3419,7 @@ declare function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption,
3417
3419
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch`, `operationIndex` and `getTask` method and merged with the transporter requestOptions.
3418
3420
  */
3419
3421
  replaceAllObjects({ indexName, objects, batchSize, scopes, maxRetries, }: ReplaceAllObjectsOptions, requestOptions?: RequestOptions | undefined): Promise<ReplaceAllObjectsResponse>;
3420
- indexExists({ indexName }: GetSettingsProps): Promise<boolean>;
3422
+ indexExists({ indexName }: GetSettingsProps, requestOptions?: RequestOptions | undefined): Promise<boolean>;
3421
3423
  /**
3422
3424
  * Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets.
3423
3425
  * Disclaimer: We don't assert that the parameters you pass to this method only contains `hits` requests to prevent impacting search performances, this helper is purely for typing purposes.
@@ -15,10 +15,12 @@ import {
15
15
  createIterablePromise,
16
16
  createTransporter,
17
17
  getAlgoliaAgent,
18
+ logWarning,
18
19
  shuffle,
19
- validateRequired
20
+ validateRequired,
21
+ withRequestId
20
22
  } from "@algolia/client-common";
21
- var apiClientVersion = "5.56.0";
23
+ var apiClientVersion = "5.57.0";
22
24
  function getDefaultHosts(appId) {
23
25
  return [
24
26
  {
@@ -138,6 +140,7 @@ function createSearchClient({
138
140
  maxRetries = 100,
139
141
  timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
140
142
  }, requestOptions) {
143
+ requestOptions = withRequestId(transporter, requestOptions);
141
144
  let retryCount = 0;
142
145
  return createIterablePromise({
143
146
  func: () => this.getTask({ indexName, taskID }, requestOptions),
@@ -165,6 +168,7 @@ function createSearchClient({
165
168
  maxRetries = 100,
166
169
  timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
167
170
  }, requestOptions) {
171
+ requestOptions = withRequestId(transporter, requestOptions);
168
172
  let retryCount = 0;
169
173
  return createIterablePromise({
170
174
  func: () => this.getAppTask({ taskID }, requestOptions),
@@ -196,6 +200,7 @@ function createSearchClient({
196
200
  maxRetries = 100,
197
201
  timeout = (retryCount) => Math.min(retryCount * 200, 5e3)
198
202
  }, requestOptions) {
203
+ requestOptions = withRequestId(transporter, requestOptions);
199
204
  let retryCount = 0;
200
205
  const baseIteratorOptions = {
201
206
  aggregator: () => retryCount += 1,
@@ -251,6 +256,7 @@ function createSearchClient({
251
256
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
252
257
  */
253
258
  browseObjects({ indexName, browseParams, ...browseObjectsOptions }, requestOptions) {
259
+ requestOptions = withRequestId(transporter, requestOptions);
254
260
  return createIterablePromise({
255
261
  func: (previousResponse) => {
256
262
  return this.browse(
@@ -281,6 +287,7 @@ function createSearchClient({
281
287
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchRules` method and merged with the transporter requestOptions.
282
288
  */
283
289
  browseRules({ indexName, searchRulesParams, ...browseRulesOptions }, requestOptions) {
290
+ requestOptions = withRequestId(transporter, requestOptions);
284
291
  const params = {
285
292
  ...searchRulesParams,
286
293
  hitsPerPage: searchRulesParams?.hitsPerPage || 1e3
@@ -318,6 +325,7 @@ function createSearchClient({
318
325
  searchSynonymsParams,
319
326
  ...browseSynonymsOptions
320
327
  }, requestOptions) {
328
+ requestOptions = withRequestId(transporter, requestOptions);
321
329
  const params = {
322
330
  ...searchSynonymsParams,
323
331
  page: searchSynonymsParams?.page || 0,
@@ -363,6 +371,7 @@ function createSearchClient({
363
371
  batchSize = 1e3,
364
372
  maxRetries = 100
365
373
  }, requestOptions) {
374
+ requestOptions = withRequestId(transporter, requestOptions);
366
375
  let requests = [];
367
376
  const responses = [];
368
377
  const objectEntries = objects.entries();
@@ -375,7 +384,7 @@ function createSearchClient({
375
384
  }
376
385
  if (waitForTasks) {
377
386
  for (const resp of responses) {
378
- await this.waitForTask({ indexName, taskID: resp.taskID, maxRetries });
387
+ await this.waitForTask({ indexName, taskID: resp.taskID, maxRetries }, requestOptions);
379
388
  }
380
389
  }
381
390
  return responses;
@@ -453,6 +462,8 @@ function createSearchClient({
453
462
  * Helper: Replaces all objects (records) in the given `index_name` with the given `objects`. A temporary index is created during this process in order to backup your data.
454
463
  * See https://api-clients-automation.netlify.app/docs/custom-helpers/#replaceallobjects for implementation details.
455
464
  *
465
+ * Warning: calling this method with an empty `objects` list replaces the index with an empty one, deleting all existing records.
466
+ *
456
467
  * @summary Helper: Replaces all objects (records) in the given `index_name` with the given `objects`. A temporary index is created during this process in order to backup your data.
457
468
  * @param replaceAllObjects - The `replaceAllObjects` object.
458
469
  * @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
@@ -469,6 +480,13 @@ function createSearchClient({
469
480
  scopes,
470
481
  maxRetries = DEFAULT_REPLACE_ALL_OBJECTS_MAX_RETRIES
471
482
  }, requestOptions) {
483
+ requestOptions = withRequestId(transporter, requestOptions);
484
+ if (objects.length === 0) {
485
+ logWarning(
486
+ transporter.logger,
487
+ `replaceAllObjects was called with an empty list of objects, which will delete all records currently in the "${indexName}" index.`
488
+ );
489
+ }
472
490
  const randomSuffix = Math.floor(Math.random() * 1e6) + 1e5;
473
491
  const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
474
492
  if (scopes === void 0) {
@@ -490,11 +508,14 @@ function createSearchClient({
490
508
  { indexName: tmpIndexName, objects, waitForTasks: true, batchSize, maxRetries },
491
509
  requestOptions
492
510
  );
493
- await this.waitForTask({
494
- indexName: tmpIndexName,
495
- taskID: copyOperationResponse.taskID,
496
- maxRetries
497
- });
511
+ await this.waitForTask(
512
+ {
513
+ indexName: tmpIndexName,
514
+ taskID: copyOperationResponse.taskID,
515
+ maxRetries
516
+ },
517
+ requestOptions
518
+ );
498
519
  copyOperationResponse = await this.operationIndex(
499
520
  {
500
521
  indexName,
@@ -506,11 +527,14 @@ function createSearchClient({
506
527
  },
507
528
  requestOptions
508
529
  );
509
- await this.waitForTask({
510
- indexName: tmpIndexName,
511
- taskID: copyOperationResponse.taskID,
512
- maxRetries
513
- });
530
+ await this.waitForTask(
531
+ {
532
+ indexName: tmpIndexName,
533
+ taskID: copyOperationResponse.taskID,
534
+ maxRetries
535
+ },
536
+ requestOptions
537
+ );
514
538
  const moveOperationResponse = await this.operationIndex(
515
539
  {
516
540
  indexName: tmpIndexName,
@@ -518,20 +542,23 @@ function createSearchClient({
518
542
  },
519
543
  requestOptions
520
544
  );
521
- await this.waitForTask({
522
- indexName: tmpIndexName,
523
- taskID: moveOperationResponse.taskID,
524
- maxRetries
525
- });
545
+ await this.waitForTask(
546
+ {
547
+ indexName: tmpIndexName,
548
+ taskID: moveOperationResponse.taskID,
549
+ maxRetries
550
+ },
551
+ requestOptions
552
+ );
526
553
  return { copyOperationResponse, batchResponses, moveOperationResponse };
527
554
  } catch (error) {
528
- await this.deleteIndex({ indexName: tmpIndexName });
555
+ await this.deleteIndex({ indexName: tmpIndexName }, requestOptions);
529
556
  throw error;
530
557
  }
531
558
  },
532
- async indexExists({ indexName }) {
559
+ async indexExists({ indexName }, requestOptions) {
533
560
  try {
534
- await this.getSettings({ indexName });
561
+ await this.getSettings({ indexName }, requestOptions);
535
562
  } catch (error) {
536
563
  if (error instanceof ApiError && error.status === 404) {
537
564
  return false;
@@ -4016,6 +4043,7 @@ function searchClient(appId, apiKey, options) {
4016
4043
  requester: createXhrRequester(),
4017
4044
  algoliaAgents: [{ segment: "Browser" }],
4018
4045
  authMode: "WithinQueryParameters",
4046
+ requestIdChannel: "queryParameters",
4019
4047
  responsesCache: createMemoryCache(),
4020
4048
  requestsCache: createMemoryCache({ serializable: false }),
4021
4049
  hostsCache: createFallbackableCache({