algoliasearch 5.0.0-alpha.3 → 5.0.0-alpha.4

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.
Files changed (105) hide show
  1. package/dist/algoliasearch/builds/browser.d.ts +14 -9
  2. package/dist/algoliasearch/builds/browser.d.ts.map +1 -1
  3. package/dist/algoliasearch/builds/node.d.ts +14 -9
  4. package/dist/algoliasearch/builds/node.d.ts.map +1 -1
  5. package/dist/algoliasearch/lite/model/acl.d.ts +3 -0
  6. package/dist/algoliasearch/lite/model/acl.d.ts.map +1 -1
  7. package/dist/algoliasearch/lite/model/addApiKeyResponse.d.ts +1 -1
  8. package/dist/algoliasearch/lite/model/attributeToUpdate.d.ts +3 -0
  9. package/dist/algoliasearch/lite/model/attributeToUpdate.d.ts.map +1 -0
  10. package/dist/algoliasearch/lite/model/baseGetApiKeyResponse.d.ts +11 -0
  11. package/dist/algoliasearch/lite/model/baseGetApiKeyResponse.d.ts.map +1 -0
  12. package/dist/algoliasearch/lite/model/getApiKeyResponse.d.ts +4 -0
  13. package/dist/algoliasearch/lite/model/getApiKeyResponse.d.ts.map +1 -0
  14. package/dist/algoliasearch/lite/model/index.d.ts +3 -3
  15. package/dist/algoliasearch/lite/model/index.d.ts.map +1 -1
  16. package/dist/algoliasearch/lite/src/liteClient.d.ts +9 -1
  17. package/dist/algoliasearch/lite/src/liteClient.d.ts.map +1 -1
  18. package/dist/algoliasearch.cjs.js +185 -24
  19. package/dist/algoliasearch.esm.browser.js +213 -52
  20. package/dist/algoliasearch.esm.node.js +186 -25
  21. package/dist/algoliasearch.umd.js +2 -2
  22. package/dist/builds/browser.d.ts +14 -9
  23. package/dist/builds/browser.d.ts.map +1 -1
  24. package/dist/builds/node.d.ts +14 -9
  25. package/dist/builds/node.d.ts.map +1 -1
  26. package/dist/client-abtesting/src/abtestingClient.d.ts +9 -1
  27. package/dist/client-abtesting/src/abtestingClient.d.ts.map +1 -1
  28. package/dist/client-analytics/src/analyticsClient.d.ts +9 -1
  29. package/dist/client-analytics/src/analyticsClient.d.ts.map +1 -1
  30. package/dist/client-personalization/src/personalizationClient.d.ts +9 -1
  31. package/dist/client-personalization/src/personalizationClient.d.ts.map +1 -1
  32. package/dist/client-search/model/acl.d.ts +3 -0
  33. package/dist/client-search/model/acl.d.ts.map +1 -1
  34. package/dist/client-search/model/addApiKeyResponse.d.ts +1 -1
  35. package/dist/client-search/model/attributeToUpdate.d.ts +3 -0
  36. package/dist/client-search/model/attributeToUpdate.d.ts.map +1 -0
  37. package/dist/client-search/model/baseGetApiKeyResponse.d.ts +11 -0
  38. package/dist/client-search/model/baseGetApiKeyResponse.d.ts.map +1 -0
  39. package/dist/client-search/model/batchParams.d.ts +1 -1
  40. package/dist/client-search/model/batchParams.d.ts.map +1 -1
  41. package/dist/client-search/model/clientMethodProps.d.ts +20 -7
  42. package/dist/client-search/model/clientMethodProps.d.ts.map +1 -1
  43. package/dist/client-search/model/getApiKeyResponse.d.ts +4 -0
  44. package/dist/client-search/model/getApiKeyResponse.d.ts.map +1 -0
  45. package/dist/client-search/model/getObjectsParams.d.ts +1 -1
  46. package/dist/client-search/model/getObjectsParams.d.ts.map +1 -1
  47. package/dist/client-search/model/index.d.ts +3 -3
  48. package/dist/client-search/model/index.d.ts.map +1 -1
  49. package/dist/client-search/model/listApiKeysResponse.d.ts +2 -2
  50. package/dist/client-search/model/listApiKeysResponse.d.ts.map +1 -1
  51. package/dist/client-search/model/multipleBatchRequest.d.ts +3 -3
  52. package/dist/client-search/model/multipleBatchRequest.d.ts.map +1 -1
  53. package/dist/client-search/model/multipleBatchResponse.d.ts +2 -2
  54. package/dist/client-search/model/multipleBatchResponse.d.ts.map +1 -1
  55. package/dist/client-search/model/updateApiKeyResponse.d.ts +1 -1
  56. package/dist/client-search/src/searchClient.d.ts +62 -15
  57. package/dist/client-search/src/searchClient.d.ts.map +1 -1
  58. package/dist/lite/builds/browser.d.ts +14 -9
  59. package/dist/lite/builds/browser.d.ts.map +1 -1
  60. package/dist/lite/builds/node.d.ts +14 -9
  61. package/dist/lite/builds/node.d.ts.map +1 -1
  62. package/dist/lite/lite/model/acl.d.ts +3 -0
  63. package/dist/lite/lite/model/acl.d.ts.map +1 -1
  64. package/dist/lite/lite/model/addApiKeyResponse.d.ts +1 -1
  65. package/dist/lite/lite/model/attributeToUpdate.d.ts +3 -0
  66. package/dist/lite/lite/model/attributeToUpdate.d.ts.map +1 -0
  67. package/dist/lite/lite/model/baseGetApiKeyResponse.d.ts +11 -0
  68. package/dist/lite/lite/model/baseGetApiKeyResponse.d.ts.map +1 -0
  69. package/dist/lite/lite/model/getApiKeyResponse.d.ts +4 -0
  70. package/dist/lite/lite/model/getApiKeyResponse.d.ts.map +1 -0
  71. package/dist/lite/lite/model/index.d.ts +3 -3
  72. package/dist/lite/lite/model/index.d.ts.map +1 -1
  73. package/dist/lite/lite/src/liteClient.d.ts +9 -1
  74. package/dist/lite/lite/src/liteClient.d.ts.map +1 -1
  75. package/dist/lite/lite.cjs.js +14 -1
  76. package/dist/lite/lite.esm.browser.js +14 -1
  77. package/dist/lite/lite.esm.node.js +14 -1
  78. package/dist/lite/lite.umd.js +2 -2
  79. package/lite/model/acl.ts +3 -0
  80. package/lite/model/addApiKeyResponse.ts +1 -1
  81. package/lite/model/{attributeOrBuiltInOperation.ts → attributeToUpdate.ts} +1 -1
  82. package/lite/model/baseGetApiKeyResponse.ts +13 -0
  83. package/lite/model/{key.ts → getApiKeyResponse.ts} +2 -2
  84. package/lite/model/index.ts +3 -3
  85. package/lite/src/liteClient.ts +19 -1
  86. package/package.json +9 -9
  87. package/dist/algoliasearch/lite/model/attributeOrBuiltInOperation.d.ts +0 -3
  88. package/dist/algoliasearch/lite/model/attributeOrBuiltInOperation.d.ts.map +0 -1
  89. package/dist/algoliasearch/lite/model/createdAtObject.d.ts +0 -7
  90. package/dist/algoliasearch/lite/model/createdAtObject.d.ts.map +0 -1
  91. package/dist/algoliasearch/lite/model/key.d.ts +0 -4
  92. package/dist/algoliasearch/lite/model/key.d.ts.map +0 -1
  93. package/dist/client-search/model/attributeOrBuiltInOperation.d.ts +0 -3
  94. package/dist/client-search/model/attributeOrBuiltInOperation.d.ts.map +0 -1
  95. package/dist/client-search/model/createdAtObject.d.ts +0 -7
  96. package/dist/client-search/model/createdAtObject.d.ts.map +0 -1
  97. package/dist/client-search/model/key.d.ts +0 -4
  98. package/dist/client-search/model/key.d.ts.map +0 -1
  99. package/dist/lite/lite/model/attributeOrBuiltInOperation.d.ts +0 -3
  100. package/dist/lite/lite/model/attributeOrBuiltInOperation.d.ts.map +0 -1
  101. package/dist/lite/lite/model/createdAtObject.d.ts +0 -7
  102. package/dist/lite/lite/model/createdAtObject.d.ts.map +0 -1
  103. package/dist/lite/lite/model/key.d.ts +0 -4
  104. package/dist/lite/lite/model/key.d.ts.map +0 -1
  105. package/lite/model/createdAtObject.ts +0 -8
@@ -15,43 +15,43 @@ function createAuth(appId, apiKey, authMode = 'WithinHeaders') {
15
15
  };
16
16
  }
17
17
 
18
- const DEFAULT_MAX_RETRIES = 50;
19
- const DEFAULT_TIMEOUT = retryCount => Math.min(retryCount * 200, 5000);
20
18
  /**
21
- * Return a promise that retry a task until it meets the condition.
19
+ * Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.
22
20
  *
23
- * @param createRetryablePromiseOptions - The createRetryablePromise options.
24
- * @param createRetryablePromiseOptions.func - The function to run, which returns a promise.
25
- * @param createRetryablePromiseOptions.validate - The validator function. It receives the resolved return of `func`.
26
- * @param createRetryablePromiseOptions.maxRetries - The maximum number of retries. 50 by default.
27
- * @param createRetryablePromiseOptions.timeout - The function to decide how long to wait between retries.
21
+ * @param createIterator - The createIterator options.
22
+ * @param createIterator.func - The function to run, which returns a promise.
23
+ * @param createIterator.validate - The validator function. It receives the resolved return of `func`.
24
+ * @param createIterator.aggregator - The function that runs right after the `func` method has been executed, allows you to do anything with the response before `validate`.
25
+ * @param createIterator.error - The `validate` condition to throw an error, and its message.
26
+ * @param createIterator.timeout - The function to decide how long to wait between iterations.
28
27
  */
29
-
30
- function createRetryablePromise({
28
+ function createIterablePromise({
31
29
  func,
32
30
  validate,
33
- maxRetries = DEFAULT_MAX_RETRIES,
34
- timeout = DEFAULT_TIMEOUT
31
+ aggregator,
32
+ error,
33
+ timeout = () => 0
35
34
  }) {
36
- let retryCount = 0;
37
-
38
- const retry = () => {
35
+ const retry = previousResponse => {
39
36
  return new Promise((resolve, reject) => {
40
- func().then(response => {
41
- const isValid = validate(response);
37
+ func(previousResponse).then(response => {
38
+ if (aggregator) {
39
+ aggregator(response);
40
+ }
42
41
 
43
- if (isValid) {
44
- resolve(response);
45
- } else if (retryCount + 1 >= maxRetries) {
46
- reject(new Error(`The maximum number of retries exceeded. (${retryCount + 1}/${maxRetries})`));
47
- } else {
48
- retryCount += 1;
49
- setTimeout(() => {
50
- retry().then(resolve).catch(reject);
51
- }, timeout(retryCount));
42
+ if (validate(response)) {
43
+ return resolve(response);
52
44
  }
53
- }).catch(error => {
54
- reject(error);
45
+
46
+ if (error && error.validate(response)) {
47
+ return reject(new Error(error.message(response)));
48
+ }
49
+
50
+ return setTimeout(() => {
51
+ retry(response).then(resolve).catch(reject);
52
+ }, timeout());
53
+ }).catch(err => {
54
+ reject(err);
55
55
  });
56
56
  });
57
57
  };
@@ -715,7 +715,7 @@ const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
715
715
  const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
716
716
 
717
717
  // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
718
- const apiClientVersion$4 = '5.0.0-alpha.3';
718
+ const apiClientVersion$4 = '5.0.0-alpha.4';
719
719
  const REGIONS$2 = ['de', 'us'];
720
720
  function getDefaultHosts$3(region) {
721
721
  const url = !region
@@ -746,6 +746,19 @@ function createAbtestingClient({ appId: appIdOption, apiKey: apiKeyOption, authM
746
746
  });
747
747
  return {
748
748
  transporter,
749
+ /**
750
+ * The `appId` currently in use.
751
+ */
752
+ appId: appIdOption,
753
+ /**
754
+ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
755
+ */
756
+ clearCache() {
757
+ return Promise.all([
758
+ transporter.requestsCache.clear(),
759
+ transporter.responsesCache.clear(),
760
+ ]).then(() => undefined);
761
+ },
749
762
  /**
750
763
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
751
764
  */
@@ -993,7 +1006,7 @@ function createAbtestingClient({ appId: appIdOption, apiKey: apiKeyOption, authM
993
1006
  }
994
1007
 
995
1008
  // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
996
- const apiClientVersion$3 = '5.0.0-alpha.3';
1009
+ const apiClientVersion$3 = '5.0.0-alpha.4';
997
1010
  const REGIONS$1 = ['de', 'us'];
998
1011
  function getDefaultHosts$2(region) {
999
1012
  const url = !region
@@ -1024,6 +1037,19 @@ function createAnalyticsClient({ appId: appIdOption, apiKey: apiKeyOption, authM
1024
1037
  });
1025
1038
  return {
1026
1039
  transporter,
1040
+ /**
1041
+ * The `appId` currently in use.
1042
+ */
1043
+ appId: appIdOption,
1044
+ /**
1045
+ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
1046
+ */
1047
+ clearCache() {
1048
+ return Promise.all([
1049
+ transporter.requestsCache.clear(),
1050
+ transporter.responsesCache.clear(),
1051
+ ]).then(() => undefined);
1052
+ },
1027
1053
  /**
1028
1054
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
1029
1055
  */
@@ -1877,7 +1903,7 @@ function createAnalyticsClient({ appId: appIdOption, apiKey: apiKeyOption, authM
1877
1903
  }
1878
1904
 
1879
1905
  // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
1880
- const apiClientVersion$2 = '5.0.0-alpha.3';
1906
+ const apiClientVersion$2 = '5.0.0-alpha.4';
1881
1907
  const REGIONS = ['eu', 'us'];
1882
1908
  function getDefaultHosts$1(region) {
1883
1909
  const url = 'personalization.{region}.algolia.com'.replace('{region}', region);
@@ -1906,6 +1932,19 @@ function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption,
1906
1932
  });
1907
1933
  return {
1908
1934
  transporter,
1935
+ /**
1936
+ * The `appId` currently in use.
1937
+ */
1938
+ appId: appIdOption,
1939
+ /**
1940
+ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
1941
+ */
1942
+ clearCache() {
1943
+ return Promise.all([
1944
+ transporter.requestsCache.clear(),
1945
+ transporter.responsesCache.clear(),
1946
+ ]).then(() => undefined);
1947
+ },
1909
1948
  /**
1910
1949
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
1911
1950
  */
@@ -2121,7 +2160,7 @@ function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption,
2121
2160
  }
2122
2161
 
2123
2162
  // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
2124
- const apiClientVersion$1 = '5.0.0-alpha.3';
2163
+ const apiClientVersion$1 = '5.0.0-alpha.4';
2125
2164
  function getDefaultHosts(appId) {
2126
2165
  return [
2127
2166
  {
@@ -2175,6 +2214,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2175
2214
  });
2176
2215
  return {
2177
2216
  transporter,
2217
+ /**
2218
+ * The `appId` currently in use.
2219
+ */
2220
+ appId: appIdOption,
2221
+ /**
2222
+ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
2223
+ */
2224
+ clearCache() {
2225
+ return Promise.all([
2226
+ transporter.requestsCache.clear(),
2227
+ transporter.responsesCache.clear(),
2228
+ ]).then(() => undefined);
2229
+ },
2178
2230
  /**
2179
2231
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
2180
2232
  */
@@ -2191,38 +2243,57 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2191
2243
  transporter.algoliaAgent.add({ segment, version });
2192
2244
  },
2193
2245
  /**
2194
- * Helper: Wait for a task to complete with `indexName` and `taskID`.
2246
+ * Helper: Wait for a task to be published (completed) for a given `indexName` and `taskID`.
2195
2247
  *
2196
- * @summary Wait for a task to complete.
2248
+ * @summary Helper method that waits for a task to be published (completed).
2197
2249
  * @param waitForTaskOptions - The waitForTaskOptions object.
2198
2250
  * @param waitForTaskOptions.indexName - The `indexName` where the operation was performed.
2199
2251
  * @param waitForTaskOptions.taskID - The `taskID` returned in the method response.
2252
+ * @param waitForTaskOptions.maxRetries - The maximum number of retries. 50 by default.
2253
+ * @param waitForTaskOptions.timeout - The function to decide how long to wait between retries.
2200
2254
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
2201
2255
  */
2202
- waitForTask({ indexName, taskID, ...createRetryablePromiseOptions }, requestOptions) {
2203
- return createRetryablePromise({
2204
- ...createRetryablePromiseOptions,
2256
+ waitForTask({ indexName, taskID, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
2257
+ let retryCount = 0;
2258
+ return createIterablePromise({
2205
2259
  func: () => this.getTask({ indexName, taskID }, requestOptions),
2206
2260
  validate: (response) => response.status === 'published',
2261
+ aggregator: () => (retryCount += 1),
2262
+ error: {
2263
+ validate: () => retryCount >= maxRetries,
2264
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
2265
+ },
2266
+ timeout: () => timeout(retryCount),
2207
2267
  });
2208
2268
  },
2209
2269
  /**
2210
2270
  * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
2211
2271
  *
2212
- * @summary Wait for an API key task to be processed.
2272
+ * @summary Helper method that waits for an API key task to be processed.
2213
2273
  * @param waitForApiKeyOptions - The waitForApiKeyOptions object.
2214
2274
  * @param waitForApiKeyOptions.operation - The `operation` that was done on a `key`.
2215
2275
  * @param waitForApiKeyOptions.key - The `key` that has been added, deleted or updated.
2216
2276
  * @param waitForApiKeyOptions.apiKey - Necessary to know if an `update` operation has been processed, compare fields of the response with it.
2277
+ * @param waitForApiKeyOptions.maxRetries - The maximum number of retries. 50 by default.
2278
+ * @param waitForApiKeyOptions.timeout - The function to decide how long to wait between retries.
2217
2279
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getApikey` method and merged with the transporter requestOptions.
2218
2280
  */
2219
- waitForApiKey({ operation, key, apiKey, ...createRetryablePromiseOptions }, requestOptions) {
2281
+ waitForApiKey({ operation, key, apiKey, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
2282
+ let retryCount = 0;
2283
+ const baseIteratorOptions = {
2284
+ aggregator: () => (retryCount += 1),
2285
+ error: {
2286
+ validate: () => retryCount >= maxRetries,
2287
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
2288
+ },
2289
+ timeout: () => timeout(retryCount),
2290
+ };
2220
2291
  if (operation === 'update') {
2221
2292
  if (!apiKey) {
2222
2293
  throw new Error('`apiKey` is required when waiting for an `update` operation.');
2223
2294
  }
2224
- return createRetryablePromise({
2225
- ...createRetryablePromiseOptions,
2295
+ return createIterablePromise({
2296
+ ...baseIteratorOptions,
2226
2297
  func: () => this.getApiKey({ key }, requestOptions),
2227
2298
  validate: (response) => {
2228
2299
  for (const field of Object.keys(apiKey)) {
@@ -2240,12 +2311,99 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2240
2311
  },
2241
2312
  });
2242
2313
  }
2243
- return createRetryablePromise({
2244
- ...createRetryablePromiseOptions,
2314
+ return createIterablePromise({
2315
+ ...baseIteratorOptions,
2245
2316
  func: () => this.getApiKey({ key }, requestOptions).catch((error) => error),
2246
2317
  validate: (error) => operation === 'add' ? error.status !== 404 : error.status === 404,
2247
2318
  });
2248
2319
  },
2320
+ /**
2321
+ * Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
2322
+ *
2323
+ * @summary Helper method that iterates on the `browse` method.
2324
+ * @param browseObjects - The browseObjects object.
2325
+ * @param browseObjects.indexName - The index in which to perform the request.
2326
+ * @param browseObjects.browseRequest - The `browse` method parameters.
2327
+ * @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
2328
+ * @param browseObjects.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
2329
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
2330
+ */
2331
+ browseObjects({ indexName, browseRequest, ...browseObjectsOptions }, requestOptions) {
2332
+ return createIterablePromise({
2333
+ func: (previousResponse) => {
2334
+ return this.browse({
2335
+ indexName,
2336
+ browseRequest: {
2337
+ cursor: previousResponse ? previousResponse.cursor : undefined,
2338
+ ...browseRequest,
2339
+ },
2340
+ }, requestOptions);
2341
+ },
2342
+ validate: (response) => response.cursor === undefined,
2343
+ ...browseObjectsOptions,
2344
+ });
2345
+ },
2346
+ /**
2347
+ * Helper: Iterate on the `searchRules` method of the client to allow aggregating rules of an index.
2348
+ *
2349
+ * @summary Helper method that iterates on the `searchRules` method.
2350
+ * @param browseObjects - The browseObjects object.
2351
+ * @param browseObjects.indexName - The index in which to perform the request.
2352
+ * @param browseObjects.searchRulesParams - The `searchRules` method parameters.
2353
+ * @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
2354
+ * @param browseObjects.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
2355
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchRules` method and merged with the transporter requestOptions.
2356
+ */
2357
+ browseRules({ indexName, searchRulesParams, ...browseRulesOptions }, requestOptions) {
2358
+ const params = {
2359
+ hitsPerPage: 1000,
2360
+ ...searchRulesParams,
2361
+ };
2362
+ return createIterablePromise({
2363
+ func: (previousResponse) => {
2364
+ return this.searchRules({
2365
+ indexName,
2366
+ searchRulesParams: {
2367
+ ...params,
2368
+ page: previousResponse
2369
+ ? previousResponse.page + 1
2370
+ : params.page || 0,
2371
+ },
2372
+ }, requestOptions);
2373
+ },
2374
+ validate: (response) => response.nbHits < params.hitsPerPage,
2375
+ ...browseRulesOptions,
2376
+ });
2377
+ },
2378
+ /**
2379
+ * Helper: Iterate on the `searchSynonyms` method of the client to allow aggregating rules of an index.
2380
+ *
2381
+ * @summary Helper method that iterates on the `searchSynonyms` method.
2382
+ * @param browseObjects - The browseObjects object.
2383
+ * @param browseObjects.indexName - The index in which to perform the request.
2384
+ * @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
2385
+ * @param browseObjects.aggregator - The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
2386
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method and merged with the transporter requestOptions.
2387
+ */
2388
+ browseSynonyms({ indexName, validate, aggregator, ...browseSynonymsOptions }, requestOptions) {
2389
+ const params = {
2390
+ hitsPerPage: 1000,
2391
+ ...browseSynonymsOptions,
2392
+ };
2393
+ return createIterablePromise({
2394
+ func: (previousResponse) => {
2395
+ return this.searchSynonyms({
2396
+ ...params,
2397
+ indexName,
2398
+ page: previousResponse
2399
+ ? previousResponse.page + 1
2400
+ : browseSynonymsOptions.page || 0,
2401
+ }, requestOptions);
2402
+ },
2403
+ validate: (response) => response.nbHits < params.hitsPerPage,
2404
+ ...browseSynonymsOptions,
2405
+ });
2406
+ },
2249
2407
  /**
2250
2408
  * Add a new API Key with specific permissions/restrictions.
2251
2409
  *
@@ -2939,6 +3097,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2939
3097
  if (!getObjectsParams) {
2940
3098
  throw new Error('Parameter `getObjectsParams` is required when calling `getObjects`.');
2941
3099
  }
3100
+ if (!getObjectsParams.requests) {
3101
+ throw new Error('Parameter `getObjectsParams.requests` is required when calling `getObjects`.');
3102
+ }
2942
3103
  const requestPath = '/1/indexes/*/objects';
2943
3104
  const headers = {};
2944
3105
  const queryParameters = {};
@@ -3242,6 +3403,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
3242
3403
  if (!batchParams) {
3243
3404
  throw new Error('Parameter `batchParams` is required when calling `multipleBatch`.');
3244
3405
  }
3406
+ if (!batchParams.requests) {
3407
+ throw new Error('Parameter `batchParams.requests` is required when calling `multipleBatch`.');
3408
+ }
3245
3409
  const requestPath = '/1/indexes/*/batch';
3246
3410
  const headers = {};
3247
3411
  const queryParameters = {};
@@ -3295,19 +3459,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
3295
3459
  * @param partialUpdateObject - The partialUpdateObject object.
3296
3460
  * @param partialUpdateObject.indexName - The index in which to perform the request.
3297
3461
  * @param partialUpdateObject.objectID - Unique identifier of an object.
3298
- * @param partialUpdateObject.attributeOrBuiltInOperation - List of attributes to update.
3462
+ * @param partialUpdateObject.attributeToUpdate - List of attributes to update.
3299
3463
  * @param partialUpdateObject.createIfNotExists - Creates the record if it does not exist yet.
3300
3464
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
3301
3465
  */
3302
- partialUpdateObject({ indexName, objectID, attributeOrBuiltInOperation, createIfNotExists, }, requestOptions) {
3466
+ partialUpdateObject({ indexName, objectID, attributeToUpdate, createIfNotExists, }, requestOptions) {
3303
3467
  if (!indexName) {
3304
3468
  throw new Error('Parameter `indexName` is required when calling `partialUpdateObject`.');
3305
3469
  }
3306
3470
  if (!objectID) {
3307
3471
  throw new Error('Parameter `objectID` is required when calling `partialUpdateObject`.');
3308
3472
  }
3309
- if (!attributeOrBuiltInOperation) {
3310
- throw new Error('Parameter `attributeOrBuiltInOperation` is required when calling `partialUpdateObject`.');
3473
+ if (!attributeToUpdate) {
3474
+ throw new Error('Parameter `attributeToUpdate` is required when calling `partialUpdateObject`.');
3311
3475
  }
3312
3476
  const requestPath = '/1/indexes/{indexName}/{objectID}/partial'
3313
3477
  .replace('{indexName}', encodeURIComponent(indexName))
@@ -3322,7 +3486,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
3322
3486
  path: requestPath,
3323
3487
  queryParameters,
3324
3488
  headers,
3325
- data: attributeOrBuiltInOperation,
3489
+ data: attributeToUpdate,
3326
3490
  };
3327
3491
  return transporter.request(request, requestOptions);
3328
3492
  },
@@ -3760,9 +3924,6 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
3760
3924
  if (!indexName) {
3761
3925
  throw new Error('Parameter `indexName` is required when calling `searchRules`.');
3762
3926
  }
3763
- if (!searchRulesParams) {
3764
- throw new Error('Parameter `searchRulesParams` is required when calling `searchRules`.');
3765
- }
3766
3927
  const requestPath = '/1/indexes/{indexName}/rules/search'.replace('{indexName}', encodeURIComponent(indexName));
3767
3928
  const headers = {};
3768
3929
  const queryParameters = {};
@@ -3771,7 +3932,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
3771
3932
  path: requestPath,
3772
3933
  queryParameters,
3773
3934
  headers,
3774
- data: searchRulesParams,
3935
+ data: searchRulesParams ? searchRulesParams : {},
3775
3936
  useReadTransporter: true,
3776
3937
  cacheable: true,
3777
3938
  };