@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.
@@ -24,12 +24,13 @@ __export(node_exports, {
24
24
  searchClient: () => searchClient
25
25
  });
26
26
  module.exports = __toCommonJS(node_exports);
27
+ var import_node_crypto = require("crypto");
27
28
  var import_requester_node_http = require("@algolia/requester-node-http");
28
29
  var import_client_common2 = require("@algolia/client-common");
29
30
 
30
31
  // src/searchClient.ts
31
32
  var import_client_common = require("@algolia/client-common");
32
- var apiClientVersion = "5.17.1";
33
+ var apiClientVersion = "5.19.0";
33
34
  function getDefaultHosts(appId) {
34
35
  return [
35
36
  {
@@ -94,6 +95,10 @@ function createSearchClient({
94
95
  * The `appId` currently in use.
95
96
  */
96
97
  appId: appIdOption,
98
+ /**
99
+ * The `apiKey` currently in use.
100
+ */
101
+ apiKey: apiKeyOption,
97
102
  /**
98
103
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
99
104
  */
@@ -452,57 +457,66 @@ function createSearchClient({
452
457
  * @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
453
458
  * @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
454
459
  * @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.
460
+ * @param replaceAllObjects.scopes - The `scopes` to keep from the index. Defaults to ['settings', 'rules', 'synonyms'].
455
461
  * @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.
456
462
  */
457
- async replaceAllObjects({ indexName, objects, batchSize }, requestOptions) {
463
+ async replaceAllObjects({ indexName, objects, batchSize, scopes }, requestOptions) {
458
464
  const randomSuffix = Math.floor(Math.random() * 1e6) + 1e5;
459
465
  const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
460
- let copyOperationResponse = await this.operationIndex(
461
- {
462
- indexName,
463
- operationIndexParams: {
464
- operation: "copy",
465
- destination: tmpIndexName,
466
- scope: ["settings", "rules", "synonyms"]
467
- }
468
- },
469
- requestOptions
470
- );
471
- const batchResponses = await this.chunkedBatch(
472
- { indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
473
- requestOptions
474
- );
475
- await this.waitForTask({
476
- indexName: tmpIndexName,
477
- taskID: copyOperationResponse.taskID
478
- });
479
- copyOperationResponse = await this.operationIndex(
480
- {
481
- indexName,
482
- operationIndexParams: {
483
- operation: "copy",
484
- destination: tmpIndexName,
485
- scope: ["settings", "rules", "synonyms"]
486
- }
487
- },
488
- requestOptions
489
- );
490
- await this.waitForTask({
491
- indexName: tmpIndexName,
492
- taskID: copyOperationResponse.taskID
493
- });
494
- const moveOperationResponse = await this.operationIndex(
495
- {
466
+ if (scopes === void 0) {
467
+ scopes = ["settings", "rules", "synonyms"];
468
+ }
469
+ try {
470
+ let copyOperationResponse = await this.operationIndex(
471
+ {
472
+ indexName,
473
+ operationIndexParams: {
474
+ operation: "copy",
475
+ destination: tmpIndexName,
476
+ scope: scopes
477
+ }
478
+ },
479
+ requestOptions
480
+ );
481
+ const batchResponses = await this.chunkedBatch(
482
+ { indexName: tmpIndexName, objects, waitForTasks: true, batchSize },
483
+ requestOptions
484
+ );
485
+ await this.waitForTask({
496
486
  indexName: tmpIndexName,
497
- operationIndexParams: { operation: "move", destination: indexName }
498
- },
499
- requestOptions
500
- );
501
- await this.waitForTask({
502
- indexName: tmpIndexName,
503
- taskID: moveOperationResponse.taskID
504
- });
505
- return { copyOperationResponse, batchResponses, moveOperationResponse };
487
+ taskID: copyOperationResponse.taskID
488
+ });
489
+ copyOperationResponse = await this.operationIndex(
490
+ {
491
+ indexName,
492
+ operationIndexParams: {
493
+ operation: "copy",
494
+ destination: tmpIndexName,
495
+ scope: scopes
496
+ }
497
+ },
498
+ requestOptions
499
+ );
500
+ await this.waitForTask({
501
+ indexName: tmpIndexName,
502
+ taskID: copyOperationResponse.taskID
503
+ });
504
+ const moveOperationResponse = await this.operationIndex(
505
+ {
506
+ indexName: tmpIndexName,
507
+ operationIndexParams: { operation: "move", destination: indexName }
508
+ },
509
+ requestOptions
510
+ );
511
+ await this.waitForTask({
512
+ indexName: tmpIndexName,
513
+ taskID: moveOperationResponse.taskID
514
+ });
515
+ return { copyOperationResponse, batchResponses, moveOperationResponse };
516
+ } catch (error) {
517
+ await this.deleteIndex({ indexName: tmpIndexName });
518
+ throw error;
519
+ }
506
520
  },
507
521
  async indexExists({ indexName }) {
508
522
  try {
@@ -2318,7 +2332,6 @@ function createSearchClient({
2318
2332
  }
2319
2333
 
2320
2334
  // builds/node.ts
2321
- var import_node_crypto = require("crypto");
2322
2335
  function searchClient(appId, apiKey, options) {
2323
2336
  if (!appId || typeof appId !== "string") {
2324
2337
  throw new Error("`appId` is missing.");
@@ -2380,7 +2393,7 @@ function searchClient(appId, apiKey, options) {
2380
2393
  * @param getSecuredApiKeyRemainingValidity.securedApiKey - The secured API key generated with the `generateSecuredApiKey` method.
2381
2394
  */
2382
2395
  getSecuredApiKeyRemainingValidity: ({ securedApiKey }) => {
2383
- const decodedString = Buffer.from(securedApiKey, "base64").toString("ascii");
2396
+ const decodedString = atob(securedApiKey);
2384
2397
  const regex = /validUntil=(\d+)/;
2385
2398
  const match = decodedString.match(regex);
2386
2399
  if (match === null) {