@algolia/client-search 5.0.0-beta.2 → 5.0.0-beta.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.
@@ -12,6 +12,7 @@ export declare function searchClient(appId: string, apiKey: string, options?: Cl
12
12
  readonly _ua: string;
13
13
  addAlgoliaAgent(segment: string, version?: string | undefined): void;
14
14
  waitForTask({ indexName, taskID, maxRetries, timeout, }: import("../model").WaitForTaskOptions, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetTaskResponse>;
15
+ waitForAppTask({ taskID, maxRetries, timeout, }: import("../model").WaitForAppTaskOptions, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetTaskResponse>;
15
16
  waitForApiKey({ operation, key, apiKey, maxRetries, timeout, }: import("../model").WaitForApiKeyOptions, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("@algolia/client-common").ApiError | import("../model").GetApiKeyResponse>;
16
17
  browseObjects<T>({ indexName, browseParams, ...browseObjectsOptions }: Partial<Pick<import("@algolia/client-common").CreateIterablePromise<import("../model").BrowseResponse<T>>, "validate">> & Required<Pick<import("@algolia/client-common").CreateIterablePromise<import("../model").BrowseResponse<T>>, "aggregator">> & import("../model").BrowseProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").BrowseResponse<T>>;
17
18
  browseRules({ indexName, searchRulesParams, ...browseRulesOptions }: Partial<Pick<import("@algolia/client-common").CreateIterablePromise<import("../model").SearchRulesResponse>, "validate">> & Required<Pick<import("@algolia/client-common").CreateIterablePromise<import("../model").SearchRulesResponse>, "aggregator">> & import("../model").SearchRulesProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").SearchRulesResponse>;
@@ -47,6 +48,7 @@ export declare function searchClient(appId: string, apiKey: string, options?: Cl
47
48
  deleteSource({ source }: import("../model").DeleteSourceProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").DeleteSourceResponse>;
48
49
  deleteSynonym({ indexName, objectID, forwardToReplicas }: import("../model").DeleteSynonymProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").DeletedAtResponse>;
49
50
  getApiKey({ key }: import("../model").GetApiKeyProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetApiKeyResponse>;
51
+ getAppTask({ taskID }: import("../model").GetAppTaskProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetTaskResponse>;
50
52
  getDictionaryLanguages(requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<Record<string, import("../model").Languages>>;
51
53
  getDictionarySettings(requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetDictionarySettingsResponse>;
52
54
  getLogs({ offset, length, indexName, type }?: import("../model").GetLogsProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetLogsResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../builds/browser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAa5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,UAAU,CAAC;AAEzB;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAG3D,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BxB"}
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../builds/browser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAa5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,UAAU,CAAC;AAEzB;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAG3D,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BxB"}
@@ -30,6 +30,7 @@ export declare function searchClient(appId: string, apiKey: string, options?: Cl
30
30
  _ua: string;
31
31
  addAlgoliaAgent(segment: string, version?: string | undefined): void;
32
32
  waitForTask({ indexName, taskID, maxRetries, timeout, }: import("../model").WaitForTaskOptions, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetTaskResponse>;
33
+ waitForAppTask({ taskID, maxRetries, timeout, }: import("../model").WaitForAppTaskOptions, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetTaskResponse>;
33
34
  waitForApiKey({ operation, key, apiKey, maxRetries, timeout, }: import("../model").WaitForApiKeyOptions, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("@algolia/client-common").ApiError | import("../model").GetApiKeyResponse>;
34
35
  browseObjects<T>({ indexName, browseParams, ...browseObjectsOptions }: Partial<Pick<import("@algolia/client-common").CreateIterablePromise<import("../model").BrowseResponse<T>>, "validate">> & Required<Pick<import("@algolia/client-common").CreateIterablePromise<import("../model").BrowseResponse<T>>, "aggregator">> & import("../model").BrowseProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").BrowseResponse<T>>;
35
36
  browseRules({ indexName, searchRulesParams, ...browseRulesOptions }: Partial<Pick<import("@algolia/client-common").CreateIterablePromise<import("../model").SearchRulesResponse>, "validate">> & Required<Pick<import("@algolia/client-common").CreateIterablePromise<import("../model").SearchRulesResponse>, "aggregator">> & import("../model").SearchRulesProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").SearchRulesResponse>;
@@ -65,6 +66,7 @@ export declare function searchClient(appId: string, apiKey: string, options?: Cl
65
66
  deleteSource({ source }: import("../model").DeleteSourceProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").DeleteSourceResponse>;
66
67
  deleteSynonym({ indexName, objectID, forwardToReplicas }: import("../model").DeleteSynonymProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").DeletedAtResponse>;
67
68
  getApiKey({ key }: import("../model").GetApiKeyProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetApiKeyResponse>;
69
+ getAppTask({ taskID }: import("../model").GetAppTaskProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetTaskResponse>;
68
70
  getDictionaryLanguages(requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<Record<string, import("../model").Languages>>;
69
71
  getDictionarySettings(requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetDictionarySettingsResponse>;
70
72
  getLogs({ offset, length, indexName, type }?: import("../model").GetLogsProps, requestOptions?: import("@algolia/client-common").RequestOptions | undefined): Promise<import("../model").GetLogsResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../builds/node.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAW5D,OAAO,KAAK,EACV,4BAA4B,EAC5B,wCAAwC,EACzC,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,UAAU,CAAC;AAEzB;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAG3D,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa;IA2BrB;;;;;;;OAOG;2DAIA,4BAA4B,GAAG,MAAM;IASxC;;;;;;OAMG;0DAGA,wCAAwC,GAAG,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcvD"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../builds/node.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAW5D,OAAO,KAAK,EACV,4BAA4B,EAC5B,wCAAwC,EACzC,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,UAAU,CAAC;AAEzB;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAG3D,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,aAAa;IA2BrB;;;;;;;OAOG;2DAIA,4BAA4B,GAAG,MAAM;IASxC;;;;;;OAMG;0DAGA,wCAAwC,GAAG,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcvD"}
@@ -5,7 +5,7 @@ var clientCommon = require('@algolia/client-common');
5
5
  var requesterNodeHttp = require('@algolia/requester-node-http');
6
6
 
7
7
  // Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
8
- const apiClientVersion = '5.0.0-beta.2';
8
+ const apiClientVersion = '5.0.0-beta.4';
9
9
  function getDefaultHosts(appId) {
10
10
  return [
11
11
  {
@@ -111,6 +111,29 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
111
111
  timeout: () => timeout(retryCount),
112
112
  });
113
113
  },
114
+ /**
115
+ * Helper: Wait for an application-level task to complete for a given `taskID`.
116
+ *
117
+ * @summary Helper method that waits for a task to be published (completed).
118
+ * @param waitForAppTaskOptions - The `waitForTaskOptions` object.
119
+ * @param waitForAppTaskOptions.taskID - The `taskID` returned in the method response.
120
+ * @param waitForAppTaskOptions.maxRetries - The maximum number of retries. 50 by default.
121
+ * @param waitForAppTaskOptions.timeout - The function to decide how long to wait between retries.
122
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
123
+ */
124
+ waitForAppTask({ taskID, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
125
+ let retryCount = 0;
126
+ return clientCommon.createIterablePromise({
127
+ func: () => this.getAppTask({ taskID }, requestOptions),
128
+ validate: (response) => response.status === 'published',
129
+ aggregator: () => (retryCount += 1),
130
+ error: {
131
+ validate: () => retryCount >= maxRetries,
132
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
133
+ },
134
+ timeout: () => timeout(retryCount),
135
+ });
136
+ },
114
137
  /**
115
138
  * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
116
139
  *
@@ -292,9 +315,10 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
292
315
  async chunkedBatch({ indexName, objects, action = 'addObject', waitForTasks, batchSize = 1000, }, requestOptions) {
293
316
  let requests = [];
294
317
  const responses = [];
295
- for (const [i, obj] of objects.entries()) {
318
+ const objectEntries = objects.entries();
319
+ for (const [i, obj] of objectEntries) {
296
320
  requests.push({ action, body: obj });
297
- if (i % batchSize === 0) {
321
+ if (requests.length === batchSize || i === objects.length - 1) {
298
322
  responses.push(await this.batch({ indexName, batchWriteParams: { requests } }, requestOptions));
299
323
  requests = [];
300
324
  }
@@ -308,18 +332,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
308
332
  },
309
333
  /**
310
334
  * 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.
335
+ * See https://api-clients-automation.netlify.app/docs/contributing/add-new-api-client#5-helpers for implementation details.
311
336
  *
312
337
  * @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.
313
338
  * @param replaceAllObjects - The `replaceAllObjects` object.
314
339
  * @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
315
340
  * @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
316
- * @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
341
+ * @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.
317
342
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
318
343
  */
319
344
  async replaceAllObjects({ indexName, objects, batchSize }, requestOptions) {
320
345
  const randomSuffix = Math.random().toString(36).substring(7);
321
346
  const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
322
- const copyOperationResponse = await this.operationIndex({
347
+ let copyOperationResponse = await this.operationIndex({
323
348
  indexName,
324
349
  operationIndexParams: {
325
350
  operation: 'copy',
@@ -327,17 +352,29 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
327
352
  scope: ['settings', 'rules', 'synonyms'],
328
353
  },
329
354
  }, requestOptions);
355
+ const batchResponses = await this.chunkedBatch({ indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, requestOptions);
330
356
  await this.waitForTask({
357
+ indexName: tmpIndexName,
358
+ taskID: copyOperationResponse.taskID,
359
+ });
360
+ copyOperationResponse = await this.operationIndex({
331
361
  indexName,
362
+ operationIndexParams: {
363
+ operation: 'copy',
364
+ destination: tmpIndexName,
365
+ scope: ['settings', 'rules', 'synonyms'],
366
+ },
367
+ }, requestOptions);
368
+ await this.waitForTask({
369
+ indexName: tmpIndexName,
332
370
  taskID: copyOperationResponse.taskID,
333
371
  });
334
- const batchResponses = await this.chunkedBatch({ indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, requestOptions);
335
372
  const moveOperationResponse = await this.operationIndex({
336
373
  indexName: tmpIndexName,
337
374
  operationIndexParams: { operation: 'move', destination: indexName },
338
375
  }, requestOptions);
339
376
  await this.waitForTask({
340
- indexName,
377
+ indexName: tmpIndexName,
341
378
  taskID: moveOperationResponse.taskID,
342
379
  });
343
380
  return { copyOperationResponse, batchResponses, moveOperationResponse };
@@ -1006,6 +1043,31 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1006
1043
  };
1007
1044
  return transporter.request(request, requestOptions);
1008
1045
  },
1046
+ /**
1047
+ * Checks the status of a given application task.
1048
+ *
1049
+ * Required API Key ACLs:
1050
+ * - editSettings.
1051
+ *
1052
+ * @param getAppTask - The getAppTask object.
1053
+ * @param getAppTask.taskID - Unique task identifier.
1054
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1055
+ */
1056
+ getAppTask({ taskID }, requestOptions) {
1057
+ if (!taskID) {
1058
+ throw new Error('Parameter `taskID` is required when calling `getAppTask`.');
1059
+ }
1060
+ const requestPath = '/1/task/{taskID}'.replace('{taskID}', encodeURIComponent(taskID));
1061
+ const headers = {};
1062
+ const queryParameters = {};
1063
+ const request = {
1064
+ method: 'GET',
1065
+ path: requestPath,
1066
+ queryParameters,
1067
+ headers,
1068
+ };
1069
+ return transporter.request(request, requestOptions);
1070
+ },
1009
1071
  /**
1010
1072
  * Lists supported languages with their supported dictionary types and number of custom entries.
1011
1073
  *
@@ -1480,7 +1542,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1480
1542
  return transporter.request(request, requestOptions);
1481
1543
  },
1482
1544
  /**
1483
- * Copies or moves (renames) an index within the same Algolia application. - Existing destination indices are overwritten, except for index-specific API keys and analytics data. - If the destination index doesn\'t exist yet, it\'ll be created. **Copy** - Copying a source index that doesn\'t exist creates a new index with 0 records and default settings. - The API keys of the source index are merged with the existing keys in the destination index. - You can\'t copy the `enableReRanking`, `mode`, and `replicas` settings. - You can\'t copy to a destination index that already has replicas. - Be aware of the [size limits](https://www.algolia.com/doc/guides/scaling/algolia-service-limits/#application-record-and-index-limits). - Related guide: [Copy indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/copy-indices/) **Move** - Moving a source index that doesn\'t exist is ignored without returning an error. - When moving an index, the analytics data keep their original name and a new set of analytics data is started for the new name. To access the original analytics in the dashboard, create an index with the original name. - If the destination index has replicas, moving will overwrite the existing index and copy the data to the replica indices. - Related guide: [Move indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/move-indices/).
1545
+ * Copies or moves (renames) an index within the same Algolia application. - Existing destination indices are overwritten, except for their analytics data. - If the destination index doesn\'t exist yet, it\'ll be created. **Copy** - Copying a source index that doesn\'t exist creates a new index with 0 records and default settings. - The API keys of the source index are merged with the existing keys in the destination index. - You can\'t copy the `enableReRanking`, `mode`, and `replicas` settings. - You can\'t copy to a destination index that already has replicas. - Be aware of the [size limits](https://www.algolia.com/doc/guides/scaling/algolia-service-limits/#application-record-and-index-limits). - Related guide: [Copy indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/copy-indices/) **Move** - Moving a source index that doesn\'t exist is ignored without returning an error. - When moving an index, the analytics data keep their original name and a new set of analytics data is started for the new name. To access the original analytics in the dashboard, create an index with the original name. - If the destination index has replicas, moving will overwrite the existing index and copy the data to the replica indices. - Related guide: [Move indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/move-indices/).
1484
1546
  *
1485
1547
  * Required API Key ACLs:
1486
1548
  * - addObject.
@@ -235,6 +235,14 @@ function createStatefulHost(host, status = 'up') {
235
235
  };
236
236
  }
237
237
 
238
+ function _defineProperty(e, r, t) {
239
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
240
+ value: t,
241
+ enumerable: !0,
242
+ configurable: !0,
243
+ writable: !0
244
+ }) : e[r] = t, e;
245
+ }
238
246
  function _toPrimitive(t, r) {
239
247
  if ("object" != typeof t || !t) return t;
240
248
  var e = t[Symbol.toPrimitive];
@@ -249,20 +257,6 @@ function _toPropertyKey(t) {
249
257
  var i = _toPrimitive(t, "string");
250
258
  return "symbol" == typeof i ? i : i + "";
251
259
  }
252
- function _defineProperty(obj, key, value) {
253
- key = _toPropertyKey(key);
254
- if (key in obj) {
255
- Object.defineProperty(obj, key, {
256
- value: value,
257
- enumerable: true,
258
- configurable: true,
259
- writable: true
260
- });
261
- } else {
262
- obj[key] = value;
263
- }
264
- return obj;
265
- }
266
260
 
267
261
  class AlgoliaError extends Error {
268
262
  constructor(message, name) {
@@ -283,7 +277,7 @@ class ErrorWithStackTrace extends AlgoliaError {
283
277
  }
284
278
  class RetryError extends ErrorWithStackTrace {
285
279
  constructor(stackTrace) {
286
- super('Unreachable hosts - your application id may be incorrect. If the error persists, please create a ticket at https://support.algolia.com/ sharing steps we can use to reproduce the issue.', stackTrace, 'RetryError');
280
+ super('Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.', stackTrace, 'RetryError');
287
281
  }
288
282
  }
289
283
  class ApiError extends ErrorWithStackTrace {
@@ -734,7 +728,7 @@ function createXhrRequester() {
734
728
  }
735
729
 
736
730
  // Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
737
- const apiClientVersion = '5.0.0-beta.2';
731
+ const apiClientVersion = '5.0.0-beta.4';
738
732
  function getDefaultHosts(appId) {
739
733
  return [
740
734
  {
@@ -840,6 +834,29 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
840
834
  timeout: () => timeout(retryCount),
841
835
  });
842
836
  },
837
+ /**
838
+ * Helper: Wait for an application-level task to complete for a given `taskID`.
839
+ *
840
+ * @summary Helper method that waits for a task to be published (completed).
841
+ * @param waitForAppTaskOptions - The `waitForTaskOptions` object.
842
+ * @param waitForAppTaskOptions.taskID - The `taskID` returned in the method response.
843
+ * @param waitForAppTaskOptions.maxRetries - The maximum number of retries. 50 by default.
844
+ * @param waitForAppTaskOptions.timeout - The function to decide how long to wait between retries.
845
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
846
+ */
847
+ waitForAppTask({ taskID, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
848
+ let retryCount = 0;
849
+ return createIterablePromise({
850
+ func: () => this.getAppTask({ taskID }, requestOptions),
851
+ validate: (response) => response.status === 'published',
852
+ aggregator: () => (retryCount += 1),
853
+ error: {
854
+ validate: () => retryCount >= maxRetries,
855
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
856
+ },
857
+ timeout: () => timeout(retryCount),
858
+ });
859
+ },
843
860
  /**
844
861
  * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
845
862
  *
@@ -1021,9 +1038,10 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1021
1038
  async chunkedBatch({ indexName, objects, action = 'addObject', waitForTasks, batchSize = 1000, }, requestOptions) {
1022
1039
  let requests = [];
1023
1040
  const responses = [];
1024
- for (const [i, obj] of objects.entries()) {
1041
+ const objectEntries = objects.entries();
1042
+ for (const [i, obj] of objectEntries) {
1025
1043
  requests.push({ action, body: obj });
1026
- if (i % batchSize === 0) {
1044
+ if (requests.length === batchSize || i === objects.length - 1) {
1027
1045
  responses.push(await this.batch({ indexName, batchWriteParams: { requests } }, requestOptions));
1028
1046
  requests = [];
1029
1047
  }
@@ -1037,18 +1055,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1037
1055
  },
1038
1056
  /**
1039
1057
  * 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.
1058
+ * See https://api-clients-automation.netlify.app/docs/contributing/add-new-api-client#5-helpers for implementation details.
1040
1059
  *
1041
1060
  * @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.
1042
1061
  * @param replaceAllObjects - The `replaceAllObjects` object.
1043
1062
  * @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
1044
1063
  * @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
1045
- * @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
1064
+ * @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.
1046
1065
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
1047
1066
  */
1048
1067
  async replaceAllObjects({ indexName, objects, batchSize }, requestOptions) {
1049
1068
  const randomSuffix = Math.random().toString(36).substring(7);
1050
1069
  const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
1051
- const copyOperationResponse = await this.operationIndex({
1070
+ let copyOperationResponse = await this.operationIndex({
1052
1071
  indexName,
1053
1072
  operationIndexParams: {
1054
1073
  operation: 'copy',
@@ -1056,17 +1075,29 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1056
1075
  scope: ['settings', 'rules', 'synonyms'],
1057
1076
  },
1058
1077
  }, requestOptions);
1078
+ const batchResponses = await this.chunkedBatch({ indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, requestOptions);
1059
1079
  await this.waitForTask({
1080
+ indexName: tmpIndexName,
1081
+ taskID: copyOperationResponse.taskID,
1082
+ });
1083
+ copyOperationResponse = await this.operationIndex({
1060
1084
  indexName,
1085
+ operationIndexParams: {
1086
+ operation: 'copy',
1087
+ destination: tmpIndexName,
1088
+ scope: ['settings', 'rules', 'synonyms'],
1089
+ },
1090
+ }, requestOptions);
1091
+ await this.waitForTask({
1092
+ indexName: tmpIndexName,
1061
1093
  taskID: copyOperationResponse.taskID,
1062
1094
  });
1063
- const batchResponses = await this.chunkedBatch({ indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, requestOptions);
1064
1095
  const moveOperationResponse = await this.operationIndex({
1065
1096
  indexName: tmpIndexName,
1066
1097
  operationIndexParams: { operation: 'move', destination: indexName },
1067
1098
  }, requestOptions);
1068
1099
  await this.waitForTask({
1069
- indexName,
1100
+ indexName: tmpIndexName,
1070
1101
  taskID: moveOperationResponse.taskID,
1071
1102
  });
1072
1103
  return { copyOperationResponse, batchResponses, moveOperationResponse };
@@ -1735,6 +1766,31 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1735
1766
  };
1736
1767
  return transporter.request(request, requestOptions);
1737
1768
  },
1769
+ /**
1770
+ * Checks the status of a given application task.
1771
+ *
1772
+ * Required API Key ACLs:
1773
+ * - editSettings.
1774
+ *
1775
+ * @param getAppTask - The getAppTask object.
1776
+ * @param getAppTask.taskID - Unique task identifier.
1777
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1778
+ */
1779
+ getAppTask({ taskID }, requestOptions) {
1780
+ if (!taskID) {
1781
+ throw new Error('Parameter `taskID` is required when calling `getAppTask`.');
1782
+ }
1783
+ const requestPath = '/1/task/{taskID}'.replace('{taskID}', encodeURIComponent(taskID));
1784
+ const headers = {};
1785
+ const queryParameters = {};
1786
+ const request = {
1787
+ method: 'GET',
1788
+ path: requestPath,
1789
+ queryParameters,
1790
+ headers,
1791
+ };
1792
+ return transporter.request(request, requestOptions);
1793
+ },
1738
1794
  /**
1739
1795
  * Lists supported languages with their supported dictionary types and number of custom entries.
1740
1796
  *
@@ -2209,7 +2265,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2209
2265
  return transporter.request(request, requestOptions);
2210
2266
  },
2211
2267
  /**
2212
- * Copies or moves (renames) an index within the same Algolia application. - Existing destination indices are overwritten, except for index-specific API keys and analytics data. - If the destination index doesn\'t exist yet, it\'ll be created. **Copy** - Copying a source index that doesn\'t exist creates a new index with 0 records and default settings. - The API keys of the source index are merged with the existing keys in the destination index. - You can\'t copy the `enableReRanking`, `mode`, and `replicas` settings. - You can\'t copy to a destination index that already has replicas. - Be aware of the [size limits](https://www.algolia.com/doc/guides/scaling/algolia-service-limits/#application-record-and-index-limits). - Related guide: [Copy indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/copy-indices/) **Move** - Moving a source index that doesn\'t exist is ignored without returning an error. - When moving an index, the analytics data keep their original name and a new set of analytics data is started for the new name. To access the original analytics in the dashboard, create an index with the original name. - If the destination index has replicas, moving will overwrite the existing index and copy the data to the replica indices. - Related guide: [Move indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/move-indices/).
2268
+ * Copies or moves (renames) an index within the same Algolia application. - Existing destination indices are overwritten, except for their analytics data. - If the destination index doesn\'t exist yet, it\'ll be created. **Copy** - Copying a source index that doesn\'t exist creates a new index with 0 records and default settings. - The API keys of the source index are merged with the existing keys in the destination index. - You can\'t copy the `enableReRanking`, `mode`, and `replicas` settings. - You can\'t copy to a destination index that already has replicas. - Be aware of the [size limits](https://www.algolia.com/doc/guides/scaling/algolia-service-limits/#application-record-and-index-limits). - Related guide: [Copy indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/copy-indices/) **Move** - Moving a source index that doesn\'t exist is ignored without returning an error. - When moving an index, the analytics data keep their original name and a new set of analytics data is started for the new name. To access the original analytics in the dashboard, create an index with the original name. - If the destination index has replicas, moving will overwrite the existing index and copy the data to the replica indices. - Related guide: [Move indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/move-indices/).
2213
2269
  *
2214
2270
  * Required API Key ACLs:
2215
2271
  * - addObject.
@@ -3,7 +3,7 @@ import { createAuth, createTransporter, getAlgoliaAgent, createIterablePromise,
3
3
  import { createHttpRequester } from '@algolia/requester-node-http';
4
4
 
5
5
  // Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
6
- const apiClientVersion = '5.0.0-beta.2';
6
+ const apiClientVersion = '5.0.0-beta.4';
7
7
  function getDefaultHosts(appId) {
8
8
  return [
9
9
  {
@@ -109,6 +109,29 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
109
109
  timeout: () => timeout(retryCount),
110
110
  });
111
111
  },
112
+ /**
113
+ * Helper: Wait for an application-level task to complete for a given `taskID`.
114
+ *
115
+ * @summary Helper method that waits for a task to be published (completed).
116
+ * @param waitForAppTaskOptions - The `waitForTaskOptions` object.
117
+ * @param waitForAppTaskOptions.taskID - The `taskID` returned in the method response.
118
+ * @param waitForAppTaskOptions.maxRetries - The maximum number of retries. 50 by default.
119
+ * @param waitForAppTaskOptions.timeout - The function to decide how long to wait between retries.
120
+ * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
121
+ */
122
+ waitForAppTask({ taskID, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
123
+ let retryCount = 0;
124
+ return createIterablePromise({
125
+ func: () => this.getAppTask({ taskID }, requestOptions),
126
+ validate: (response) => response.status === 'published',
127
+ aggregator: () => (retryCount += 1),
128
+ error: {
129
+ validate: () => retryCount >= maxRetries,
130
+ message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
131
+ },
132
+ timeout: () => timeout(retryCount),
133
+ });
134
+ },
112
135
  /**
113
136
  * Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
114
137
  *
@@ -290,9 +313,10 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
290
313
  async chunkedBatch({ indexName, objects, action = 'addObject', waitForTasks, batchSize = 1000, }, requestOptions) {
291
314
  let requests = [];
292
315
  const responses = [];
293
- for (const [i, obj] of objects.entries()) {
316
+ const objectEntries = objects.entries();
317
+ for (const [i, obj] of objectEntries) {
294
318
  requests.push({ action, body: obj });
295
- if (i % batchSize === 0) {
319
+ if (requests.length === batchSize || i === objects.length - 1) {
296
320
  responses.push(await this.batch({ indexName, batchWriteParams: { requests } }, requestOptions));
297
321
  requests = [];
298
322
  }
@@ -306,18 +330,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
306
330
  },
307
331
  /**
308
332
  * 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.
333
+ * See https://api-clients-automation.netlify.app/docs/contributing/add-new-api-client#5-helpers for implementation details.
309
334
  *
310
335
  * @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.
311
336
  * @param replaceAllObjects - The `replaceAllObjects` object.
312
337
  * @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
313
338
  * @param replaceAllObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
314
- * @param replaceAllObjects.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000.
339
+ * @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.
315
340
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
316
341
  */
317
342
  async replaceAllObjects({ indexName, objects, batchSize }, requestOptions) {
318
343
  const randomSuffix = Math.random().toString(36).substring(7);
319
344
  const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
320
- const copyOperationResponse = await this.operationIndex({
345
+ let copyOperationResponse = await this.operationIndex({
321
346
  indexName,
322
347
  operationIndexParams: {
323
348
  operation: 'copy',
@@ -325,17 +350,29 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
325
350
  scope: ['settings', 'rules', 'synonyms'],
326
351
  },
327
352
  }, requestOptions);
353
+ const batchResponses = await this.chunkedBatch({ indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, requestOptions);
328
354
  await this.waitForTask({
355
+ indexName: tmpIndexName,
356
+ taskID: copyOperationResponse.taskID,
357
+ });
358
+ copyOperationResponse = await this.operationIndex({
329
359
  indexName,
360
+ operationIndexParams: {
361
+ operation: 'copy',
362
+ destination: tmpIndexName,
363
+ scope: ['settings', 'rules', 'synonyms'],
364
+ },
365
+ }, requestOptions);
366
+ await this.waitForTask({
367
+ indexName: tmpIndexName,
330
368
  taskID: copyOperationResponse.taskID,
331
369
  });
332
- const batchResponses = await this.chunkedBatch({ indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, requestOptions);
333
370
  const moveOperationResponse = await this.operationIndex({
334
371
  indexName: tmpIndexName,
335
372
  operationIndexParams: { operation: 'move', destination: indexName },
336
373
  }, requestOptions);
337
374
  await this.waitForTask({
338
- indexName,
375
+ indexName: tmpIndexName,
339
376
  taskID: moveOperationResponse.taskID,
340
377
  });
341
378
  return { copyOperationResponse, batchResponses, moveOperationResponse };
@@ -1004,6 +1041,31 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1004
1041
  };
1005
1042
  return transporter.request(request, requestOptions);
1006
1043
  },
1044
+ /**
1045
+ * Checks the status of a given application task.
1046
+ *
1047
+ * Required API Key ACLs:
1048
+ * - editSettings.
1049
+ *
1050
+ * @param getAppTask - The getAppTask object.
1051
+ * @param getAppTask.taskID - Unique task identifier.
1052
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1053
+ */
1054
+ getAppTask({ taskID }, requestOptions) {
1055
+ if (!taskID) {
1056
+ throw new Error('Parameter `taskID` is required when calling `getAppTask`.');
1057
+ }
1058
+ const requestPath = '/1/task/{taskID}'.replace('{taskID}', encodeURIComponent(taskID));
1059
+ const headers = {};
1060
+ const queryParameters = {};
1061
+ const request = {
1062
+ method: 'GET',
1063
+ path: requestPath,
1064
+ queryParameters,
1065
+ headers,
1066
+ };
1067
+ return transporter.request(request, requestOptions);
1068
+ },
1007
1069
  /**
1008
1070
  * Lists supported languages with their supported dictionary types and number of custom entries.
1009
1071
  *
@@ -1478,7 +1540,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1478
1540
  return transporter.request(request, requestOptions);
1479
1541
  },
1480
1542
  /**
1481
- * Copies or moves (renames) an index within the same Algolia application. - Existing destination indices are overwritten, except for index-specific API keys and analytics data. - If the destination index doesn\'t exist yet, it\'ll be created. **Copy** - Copying a source index that doesn\'t exist creates a new index with 0 records and default settings. - The API keys of the source index are merged with the existing keys in the destination index. - You can\'t copy the `enableReRanking`, `mode`, and `replicas` settings. - You can\'t copy to a destination index that already has replicas. - Be aware of the [size limits](https://www.algolia.com/doc/guides/scaling/algolia-service-limits/#application-record-and-index-limits). - Related guide: [Copy indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/copy-indices/) **Move** - Moving a source index that doesn\'t exist is ignored without returning an error. - When moving an index, the analytics data keep their original name and a new set of analytics data is started for the new name. To access the original analytics in the dashboard, create an index with the original name. - If the destination index has replicas, moving will overwrite the existing index and copy the data to the replica indices. - Related guide: [Move indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/move-indices/).
1543
+ * Copies or moves (renames) an index within the same Algolia application. - Existing destination indices are overwritten, except for their analytics data. - If the destination index doesn\'t exist yet, it\'ll be created. **Copy** - Copying a source index that doesn\'t exist creates a new index with 0 records and default settings. - The API keys of the source index are merged with the existing keys in the destination index. - You can\'t copy the `enableReRanking`, `mode`, and `replicas` settings. - You can\'t copy to a destination index that already has replicas. - Be aware of the [size limits](https://www.algolia.com/doc/guides/scaling/algolia-service-limits/#application-record-and-index-limits). - Related guide: [Copy indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/copy-indices/) **Move** - Moving a source index that doesn\'t exist is ignored without returning an error. - When moving an index, the analytics data keep their original name and a new set of analytics data is started for the new name. To access the original analytics in the dashboard, create an index with the original name. - If the destination index has replicas, moving will overwrite the existing index and copy the data to the replica indices. - Related guide: [Move indices](https://www.algolia.com/doc/guides/sending-and-managing-data/manage-indices-and-apps/manage-indices/how-to/move-indices/).
1482
1544
  *
1483
1545
  * Required API Key ACLs:
1484
1546
  * - addObject.