@algolia/client-search 5.17.1 → 5.19.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.
@@ -1,4 +1,5 @@
1
1
  // builds/node.ts
2
+ import { createHmac } from "node:crypto";
2
3
  import { createHttpRequester } from "@algolia/requester-node-http";
3
4
  import { createMemoryCache, createNullCache, createNullLogger, serializeQueryParameters } from "@algolia/client-common";
4
5
 
@@ -11,7 +12,7 @@ import {
11
12
  getAlgoliaAgent,
12
13
  shuffle
13
14
  } from "@algolia/client-common";
14
- var apiClientVersion = "5.17.1";
15
+ var apiClientVersion = "5.19.0";
15
16
  function getDefaultHosts(appId) {
16
17
  return [
17
18
  {
@@ -76,6 +77,10 @@ function createSearchClient({
76
77
  * The `appId` currently in use.
77
78
  */
78
79
  appId: appIdOption,
80
+ /**
81
+ * The `apiKey` currently in use.
82
+ */
83
+ apiKey: apiKeyOption,
79
84
  /**
80
85
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
81
86
  */
@@ -434,57 +439,66 @@ function createSearchClient({
434
439
  * @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
435
440
  * @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
436
441
  * @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `objects.length / batchSize`. Defaults to 1000.
442
+ * @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
437
443
  * @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.
438
444
  */
439
- async replaceAllObjects({ indexName, objects, batchSize }, requestOptions) {
445
+ async replaceAllObjects({ indexName, objects, batchSize, scopes }, requestOptions) {
440
446
  const randomSuffix = Math.floor(Math.random() * 1e6) + 1e5;
441
447
  const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
442
- let copyOperationResponse = await this.operationIndex(
443
- {
444
- indexName,
445
- operationIndexParams: {
446
- operation: "copy",
447
- destination: tmpIndexName,
448
- scope: ["settings", "rules", "synonyms"]
449
- }
450
- },
451
- requestOptions
452
- );
453
- const batchResponses = await this.chunkedBatch(
454
- { indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
455
- requestOptions
456
- );
457
- await this.waitForTask({
458
- indexName: tmpIndexName,
459
- taskID: copyOperationResponse.taskID
460
- });
461
- copyOperationResponse = await this.operationIndex(
462
- {
463
- indexName,
464
- operationIndexParams: {
465
- operation: "copy",
466
- destination: tmpIndexName,
467
- scope: ["settings", "rules", "synonyms"]
468
- }
469
- },
470
- requestOptions
471
- );
472
- await this.waitForTask({
473
- indexName: tmpIndexName,
474
- taskID: copyOperationResponse.taskID
475
- });
476
- const moveOperationResponse = await this.operationIndex(
477
- {
448
+ if (scopes === void 0) {
449
+ scopes = ["settings", "rules", "synonyms"];
450
+ }
451
+ try {
452
+ let copyOperationResponse = await this.operationIndex(
453
+ {
454
+ indexName,
455
+ operationIndexParams: {
456
+ operation: "copy",
457
+ destination: tmpIndexName,
458
+ scope: scopes
459
+ }
460
+ },
461
+ requestOptions
462
+ );
463
+ const batchResponses = await this.chunkedBatch(
464
+ { indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
465
+ requestOptions
466
+ );
467
+ await this.waitForTask({
478
468
  indexName: tmpIndexName,
479
- operationIndexParams: { operation: "move", destination: indexName }
480
- },
481
- requestOptions
482
- );
483
- await this.waitForTask({
484
- indexName: tmpIndexName,
485
- taskID: moveOperationResponse.taskID
486
- });
487
- return { copyOperationResponse, batchResponses, moveOperationResponse };
469
+ taskID: copyOperationResponse.taskID
470
+ });
471
+ copyOperationResponse = await this.operationIndex(
472
+ {
473
+ indexName,
474
+ operationIndexParams: {
475
+ operation: "copy",
476
+ destination: tmpIndexName,
477
+ scope: scopes
478
+ }
479
+ },
480
+ requestOptions
481
+ );
482
+ await this.waitForTask({
483
+ indexName: tmpIndexName,
484
+ taskID: copyOperationResponse.taskID
485
+ });
486
+ const moveOperationResponse = await this.operationIndex(
487
+ {
488
+ indexName: tmpIndexName,
489
+ operationIndexParams: { operation: "move", destination: indexName }
490
+ },
491
+ requestOptions
492
+ );
493
+ await this.waitForTask({
494
+ indexName: tmpIndexName,
495
+ taskID: moveOperationResponse.taskID
496
+ });
497
+ return { copyOperationResponse, batchResponses, moveOperationResponse };
498
+ } catch (error) {
499
+ await this.deleteIndex({ indexName: tmpIndexName });
500
+ throw error;
501
+ }
488
502
  },
489
503
  async indexExists({ indexName }) {
490
504
  try {
@@ -2300,7 +2314,6 @@ function createSearchClient({
2300
2314
  }
2301
2315
 
2302
2316
  // builds/node.ts
2303
- import { createHmac } from "node:crypto";
2304
2317
  function searchClient(appId, apiKey, options) {
2305
2318
  if (!appId || typeof appId !== "string") {
2306
2319
  throw new Error("`appId` is missing.");
@@ -2362,7 +2375,7 @@ function searchClient(appId, apiKey, options) {
2362
2375
  * @param getSecuredApiKeyRemainingValidity.securedApiKey - The secured API key generated with the `generateSecuredApiKey` method.
2363
2376
  */
2364
2377
  getSecuredApiKeyRemainingValidity: ({ securedApiKey }) => {
2365
- const decodedString = Buffer.from(securedApiKey, "base64").toString("ascii");
2378
+ const decodedString = atob(securedApiKey);
2366
2379
  const regex = /validUntil=(\d+)/;
2367
2380
  const match = decodedString.match(regex);
2368
2381
  if (match === null) {