@algolia/client-search 5.0.0-beta.1 → 5.0.0-beta.10
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/LICENSE +21 -0
- package/dist/builds/browser.d.ts +73 -68
- package/dist/builds/browser.d.ts.map +1 -1
- package/dist/builds/node.d.ts +73 -68
- package/dist/builds/node.d.ts.map +1 -1
- package/dist/client-search.cjs +137 -12
- package/dist/client-search.esm.browser.js +130 -28
- package/dist/client-search.esm.node.js +137 -12
- package/dist/client-search.umd.js +2 -2
- package/dist/model/baseIndexSettings.d.ts +2 -2
- package/dist/model/baseIndexSettings.d.ts.map +1 -1
- package/dist/model/baseSearchResponse.d.ts +2 -18
- package/dist/model/baseSearchResponse.d.ts.map +1 -1
- package/dist/model/browsePagination.d.ts +19 -0
- package/dist/model/browsePagination.d.ts.map +1 -0
- package/dist/model/browseResponse.d.ts +2 -1
- package/dist/model/browseResponse.d.ts.map +1 -1
- package/dist/model/clientMethodProps.d.ts +31 -23
- package/dist/model/clientMethodProps.d.ts.map +1 -1
- package/dist/model/facetFilters.d.ts +1 -2
- package/dist/model/facetFilters.d.ts.map +1 -1
- package/dist/model/fetchedIndex.d.ts +4 -0
- package/dist/model/fetchedIndex.d.ts.map +1 -1
- package/dist/model/index.d.ts +5 -2
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/numericFilters.d.ts +1 -2
- package/dist/model/numericFilters.d.ts.map +1 -1
- package/dist/model/optionalFilters.d.ts +1 -2
- package/dist/model/optionalFilters.d.ts.map +1 -1
- package/dist/model/rankingInfo.d.ts +3 -3
- package/dist/model/rankingInfo.d.ts.map +1 -1
- package/dist/model/reRankingApplyFilter.d.ts +1 -2
- package/dist/model/reRankingApplyFilter.d.ts.map +1 -1
- package/dist/model/redirect.d.ts +1 -1
- package/dist/model/redirectURL.d.ts +7 -0
- package/dist/model/redirectURL.d.ts.map +1 -0
- package/dist/model/renderingContent.d.ts +2 -0
- package/dist/model/renderingContent.d.ts.map +1 -1
- package/dist/model/replaceAllObjectsResponse.d.ts +11 -0
- package/dist/model/replaceAllObjectsResponse.d.ts.map +1 -0
- package/dist/model/searchForFacetValuesResponse.d.ts +1 -1
- package/dist/model/searchPagination.d.ts +19 -0
- package/dist/model/searchPagination.d.ts.map +1 -0
- package/dist/model/searchResponse.d.ts +2 -1
- package/dist/model/searchResponse.d.ts.map +1 -1
- package/dist/model/{securedAPIKeyRestrictions.d.ts → securedApiKeyRestrictions.d.ts} +2 -2
- package/dist/model/{securedAPIKeyRestrictions.d.ts.map → securedApiKeyRestrictions.d.ts.map} +1 -1
- package/dist/model/tagFilters.d.ts +1 -2
- package/dist/model/tagFilters.d.ts.map +1 -1
- package/dist/model/value.d.ts +4 -0
- package/dist/model/value.d.ts.map +1 -1
- package/dist/src/searchClient.d.ts +67 -12
- package/dist/src/searchClient.d.ts.map +1 -1
- package/model/baseIndexSettings.ts +2 -2
- package/model/baseSearchResponse.ts +2 -22
- package/model/browsePagination.ts +23 -0
- package/model/browseResponse.ts +2 -0
- package/model/clientMethodProps.ts +42 -26
- package/model/facetFilters.ts +1 -3
- package/model/fetchedIndex.ts +5 -0
- package/model/index.ts +5 -2
- package/model/numericFilters.ts +1 -3
- package/model/optionalFilters.ts +1 -3
- package/model/rankingInfo.ts +3 -3
- package/model/reRankingApplyFilter.ts +1 -3
- package/model/redirect.ts +1 -1
- package/model/{mixedSearchFilters.ts → redirectURL.ts} +6 -1
- package/model/renderingContent.ts +3 -0
- package/model/replaceAllObjectsResponse.ts +15 -0
- package/model/searchForFacetValuesResponse.ts +1 -1
- package/model/searchPagination.ts +23 -0
- package/model/searchResponse.ts +3 -1
- package/model/{securedAPIKeyRestrictions.ts → securedApiKeyRestrictions.ts} +1 -1
- package/model/tagFilters.ts +1 -3
- package/model/value.ts +5 -0
- package/package.json +11 -8
- package/dist/model/mixedSearchFilters.d.ts +0 -2
- package/dist/model/mixedSearchFilters.d.ts.map +0 -1
package/dist/client-search.cjs
CHANGED
|
@@ -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.
|
|
8
|
+
const apiClientVersion = '5.0.0-beta.10';
|
|
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
|
-
|
|
318
|
+
const objectEntries = objects.entries();
|
|
319
|
+
for (const [i, obj] of objectEntries) {
|
|
296
320
|
requests.push({ action, body: obj });
|
|
297
|
-
if (
|
|
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
|
}
|
|
@@ -306,20 +330,68 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
306
330
|
}
|
|
307
331
|
return responses;
|
|
308
332
|
},
|
|
333
|
+
/**
|
|
334
|
+
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
|
|
335
|
+
*
|
|
336
|
+
* @summary Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
|
|
337
|
+
* @param saveObjects - The `saveObjects` object.
|
|
338
|
+
* @param saveObjects.indexName - The `indexName` to save `objects` in.
|
|
339
|
+
* @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
|
|
340
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
|
|
341
|
+
*/
|
|
342
|
+
async saveObjects({ indexName, objects }, requestOptions) {
|
|
343
|
+
return await this.chunkedBatch({ indexName, objects, action: 'addObject' }, requestOptions);
|
|
344
|
+
},
|
|
345
|
+
/**
|
|
346
|
+
* Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
|
|
347
|
+
*
|
|
348
|
+
* @summary Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
|
|
349
|
+
* @param deleteObjects - The `deleteObjects` object.
|
|
350
|
+
* @param deleteObjects.indexName - The `indexName` to delete `objectIDs` from.
|
|
351
|
+
* @param deleteObjects.objectIDs - The objectIDs to delete.
|
|
352
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
|
|
353
|
+
*/
|
|
354
|
+
async deleteObjects({ indexName, objectIDs }, requestOptions) {
|
|
355
|
+
return await this.chunkedBatch({
|
|
356
|
+
indexName,
|
|
357
|
+
objects: objectIDs.map((objectID) => ({ objectID })),
|
|
358
|
+
action: 'deleteObject',
|
|
359
|
+
}, requestOptions);
|
|
360
|
+
},
|
|
361
|
+
/**
|
|
362
|
+
* Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
|
|
363
|
+
*
|
|
364
|
+
* @summary Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
|
|
365
|
+
* @param partialUpdateObjects - The `partialUpdateObjects` object.
|
|
366
|
+
* @param partialUpdateObjects.indexName - The `indexName` to update `objects` in.
|
|
367
|
+
* @param partialUpdateObjects.objects - The array of `objects` to update in the given Algolia `indexName`.
|
|
368
|
+
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail..
|
|
369
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
|
|
370
|
+
*/
|
|
371
|
+
async partialUpdateObjects({ indexName, objects, createIfNotExists }, requestOptions) {
|
|
372
|
+
return await this.chunkedBatch({
|
|
373
|
+
indexName,
|
|
374
|
+
objects,
|
|
375
|
+
action: createIfNotExists
|
|
376
|
+
? 'partialUpdateObject'
|
|
377
|
+
: 'partialUpdateObjectNoCreate',
|
|
378
|
+
}, requestOptions);
|
|
379
|
+
},
|
|
309
380
|
/**
|
|
310
381
|
* 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.
|
|
382
|
+
* See https://api-clients-automation.netlify.app/docs/contributing/add-new-api-client#5-helpers for implementation details.
|
|
311
383
|
*
|
|
312
384
|
* @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
385
|
* @param replaceAllObjects - The `replaceAllObjects` object.
|
|
314
386
|
* @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
|
|
315
387
|
* @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
|
|
317
|
-
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
|
|
388
|
+
* @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.
|
|
389
|
+
* @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.
|
|
318
390
|
*/
|
|
319
391
|
async replaceAllObjects({ indexName, objects, batchSize }, requestOptions) {
|
|
320
|
-
const randomSuffix = Math.
|
|
392
|
+
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;
|
|
321
393
|
const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
|
|
322
|
-
|
|
394
|
+
let copyOperationResponse = await this.operationIndex({
|
|
323
395
|
indexName,
|
|
324
396
|
operationIndexParams: {
|
|
325
397
|
operation: 'copy',
|
|
@@ -327,17 +399,29 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
327
399
|
scope: ['settings', 'rules', 'synonyms'],
|
|
328
400
|
},
|
|
329
401
|
}, requestOptions);
|
|
402
|
+
const batchResponses = await this.chunkedBatch({ indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, requestOptions);
|
|
330
403
|
await this.waitForTask({
|
|
404
|
+
indexName: tmpIndexName,
|
|
405
|
+
taskID: copyOperationResponse.taskID,
|
|
406
|
+
});
|
|
407
|
+
copyOperationResponse = await this.operationIndex({
|
|
331
408
|
indexName,
|
|
409
|
+
operationIndexParams: {
|
|
410
|
+
operation: 'copy',
|
|
411
|
+
destination: tmpIndexName,
|
|
412
|
+
scope: ['settings', 'rules', 'synonyms'],
|
|
413
|
+
},
|
|
414
|
+
}, requestOptions);
|
|
415
|
+
await this.waitForTask({
|
|
416
|
+
indexName: tmpIndexName,
|
|
332
417
|
taskID: copyOperationResponse.taskID,
|
|
333
418
|
});
|
|
334
|
-
const batchResponses = await this.chunkedBatch({ indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, requestOptions);
|
|
335
419
|
const moveOperationResponse = await this.operationIndex({
|
|
336
420
|
indexName: tmpIndexName,
|
|
337
421
|
operationIndexParams: { operation: 'move', destination: indexName },
|
|
338
422
|
}, requestOptions);
|
|
339
423
|
await this.waitForTask({
|
|
340
|
-
indexName,
|
|
424
|
+
indexName: tmpIndexName,
|
|
341
425
|
taskID: moveOperationResponse.taskID,
|
|
342
426
|
});
|
|
343
427
|
return { copyOperationResponse, batchResponses, moveOperationResponse };
|
|
@@ -573,7 +657,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
573
657
|
return transporter.request(request, requestOptions);
|
|
574
658
|
},
|
|
575
659
|
/**
|
|
576
|
-
* Retrieves records from an index, up to 1,000 per request. While searching retrieves _hits_ (records augmented with attributes for highlighting and ranking details), browsing _just_ returns matching records. This can be useful if you want to export your indices. - The Analytics API doesn\'t collect data when using `browse`. - Records are ranked by attributes and custom ranking. -
|
|
660
|
+
* Retrieves records from an index, up to 1,000 per request. While searching retrieves _hits_ (records augmented with attributes for highlighting and ranking details), browsing _just_ returns matching records. This can be useful if you want to export your indices. - The Analytics API doesn\'t collect data when using `browse`. - Records are ranked by attributes and custom ranking. - There\'s no ranking for: typo-tolerance, number of matched words, proximity, geo distance. Browse requests automatically apply these settings: - `advancedSyntax`: `false` - `attributesToHighlight`: `[]` - `attributesToSnippet`: `[]` - `distinct`: `false` - `enablePersonalization`: `false` - `enableRules`: `false` - `facets`: `[]` - `getRankingInfo`: `false` - `ignorePlurals`: `false` - `optionalFilters`: `[]` - `typoTolerance`: `true` or `false` (`min` and `strict` is evaluated to `true`) If you send these parameters with your browse requests, they\'ll be ignored.
|
|
577
661
|
*
|
|
578
662
|
* Required API Key ACLs:
|
|
579
663
|
* - browse.
|
|
@@ -1006,6 +1090,31 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1006
1090
|
};
|
|
1007
1091
|
return transporter.request(request, requestOptions);
|
|
1008
1092
|
},
|
|
1093
|
+
/**
|
|
1094
|
+
* Checks the status of a given application task.
|
|
1095
|
+
*
|
|
1096
|
+
* Required API Key ACLs:
|
|
1097
|
+
* - editSettings.
|
|
1098
|
+
*
|
|
1099
|
+
* @param getAppTask - The getAppTask object.
|
|
1100
|
+
* @param getAppTask.taskID - Unique task identifier.
|
|
1101
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1102
|
+
*/
|
|
1103
|
+
getAppTask({ taskID }, requestOptions) {
|
|
1104
|
+
if (!taskID) {
|
|
1105
|
+
throw new Error('Parameter `taskID` is required when calling `getAppTask`.');
|
|
1106
|
+
}
|
|
1107
|
+
const requestPath = '/1/task/{taskID}'.replace('{taskID}', encodeURIComponent(taskID));
|
|
1108
|
+
const headers = {};
|
|
1109
|
+
const queryParameters = {};
|
|
1110
|
+
const request = {
|
|
1111
|
+
method: 'GET',
|
|
1112
|
+
path: requestPath,
|
|
1113
|
+
queryParameters,
|
|
1114
|
+
headers,
|
|
1115
|
+
};
|
|
1116
|
+
return transporter.request(request, requestOptions);
|
|
1117
|
+
},
|
|
1009
1118
|
/**
|
|
1010
1119
|
* Lists supported languages with their supported dictionary types and number of custom entries.
|
|
1011
1120
|
*
|
|
@@ -1480,7 +1589,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1480
1589
|
return transporter.request(request, requestOptions);
|
|
1481
1590
|
},
|
|
1482
1591
|
/**
|
|
1483
|
-
* Copies or moves (renames) an index within the same Algolia application. - Existing destination indices are overwritten, except for
|
|
1592
|
+
* 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
1593
|
*
|
|
1485
1594
|
* Required API Key ACLs:
|
|
1486
1595
|
* - addObject.
|
|
@@ -2198,7 +2307,23 @@ function searchClient(appId, apiKey, options) {
|
|
|
2198
2307
|
* @param generateSecuredApiKey.restrictions - A set of properties defining the restrictions of the secured API key.
|
|
2199
2308
|
*/
|
|
2200
2309
|
generateSecuredApiKey({ parentApiKey, restrictions = {}, }) {
|
|
2201
|
-
|
|
2310
|
+
let mergedRestrictions = restrictions;
|
|
2311
|
+
if (restrictions.searchParams) {
|
|
2312
|
+
// merge searchParams with the root restrictions
|
|
2313
|
+
mergedRestrictions = {
|
|
2314
|
+
...restrictions,
|
|
2315
|
+
...restrictions.searchParams,
|
|
2316
|
+
};
|
|
2317
|
+
delete mergedRestrictions.searchParams;
|
|
2318
|
+
}
|
|
2319
|
+
mergedRestrictions = Object.keys(mergedRestrictions)
|
|
2320
|
+
.sort()
|
|
2321
|
+
.reduce((acc, key) => {
|
|
2322
|
+
// eslint-disable-next-line no-param-reassign
|
|
2323
|
+
acc[key] = mergedRestrictions[key];
|
|
2324
|
+
return acc;
|
|
2325
|
+
}, {});
|
|
2326
|
+
const queryParameters = clientCommon.serializeQueryParameters(mergedRestrictions);
|
|
2202
2327
|
return Buffer.from(crypto.createHmac('sha256', parentApiKey)
|
|
2203
2328
|
.update(queryParameters)
|
|
2204
2329
|
.digest('hex') + queryParameters).toString('base64');
|
|
@@ -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
|
|
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 {
|
|
@@ -328,8 +322,7 @@ function serializeUrl(host, path, queryParameters) {
|
|
|
328
322
|
return url;
|
|
329
323
|
}
|
|
330
324
|
function serializeQueryParameters(parameters) {
|
|
331
|
-
|
|
332
|
-
return Object.keys(parameters).map(key => `${key}=${encodeURIComponent(isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]).replaceAll('+', '%20')}`).join('&');
|
|
325
|
+
return Object.keys(parameters).filter(key => parameters[key] !== undefined).sort().map(key => `${key}=${encodeURIComponent(Object.prototype.toString.call(parameters[key]) === '[object Array]' ? parameters[key].join(',') : parameters[key]).replaceAll('+', '%20')}`).join('&');
|
|
333
326
|
}
|
|
334
327
|
function serializeData(request, requestOptions) {
|
|
335
328
|
if (request.method === 'GET' || request.data === undefined && requestOptions.data === undefined) {
|
|
@@ -734,7 +727,7 @@ function createXhrRequester() {
|
|
|
734
727
|
}
|
|
735
728
|
|
|
736
729
|
// 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.
|
|
730
|
+
const apiClientVersion = '5.0.0-beta.10';
|
|
738
731
|
function getDefaultHosts(appId) {
|
|
739
732
|
return [
|
|
740
733
|
{
|
|
@@ -840,6 +833,29 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
840
833
|
timeout: () => timeout(retryCount),
|
|
841
834
|
});
|
|
842
835
|
},
|
|
836
|
+
/**
|
|
837
|
+
* Helper: Wait for an application-level task to complete for a given `taskID`.
|
|
838
|
+
*
|
|
839
|
+
* @summary Helper method that waits for a task to be published (completed).
|
|
840
|
+
* @param waitForAppTaskOptions - The `waitForTaskOptions` object.
|
|
841
|
+
* @param waitForAppTaskOptions.taskID - The `taskID` returned in the method response.
|
|
842
|
+
* @param waitForAppTaskOptions.maxRetries - The maximum number of retries. 50 by default.
|
|
843
|
+
* @param waitForAppTaskOptions.timeout - The function to decide how long to wait between retries.
|
|
844
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
|
|
845
|
+
*/
|
|
846
|
+
waitForAppTask({ taskID, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
|
|
847
|
+
let retryCount = 0;
|
|
848
|
+
return createIterablePromise({
|
|
849
|
+
func: () => this.getAppTask({ taskID }, requestOptions),
|
|
850
|
+
validate: (response) => response.status === 'published',
|
|
851
|
+
aggregator: () => (retryCount += 1),
|
|
852
|
+
error: {
|
|
853
|
+
validate: () => retryCount >= maxRetries,
|
|
854
|
+
message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
|
|
855
|
+
},
|
|
856
|
+
timeout: () => timeout(retryCount),
|
|
857
|
+
});
|
|
858
|
+
},
|
|
843
859
|
/**
|
|
844
860
|
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
|
|
845
861
|
*
|
|
@@ -1021,9 +1037,10 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1021
1037
|
async chunkedBatch({ indexName, objects, action = 'addObject', waitForTasks, batchSize = 1000, }, requestOptions) {
|
|
1022
1038
|
let requests = [];
|
|
1023
1039
|
const responses = [];
|
|
1024
|
-
|
|
1040
|
+
const objectEntries = objects.entries();
|
|
1041
|
+
for (const [i, obj] of objectEntries) {
|
|
1025
1042
|
requests.push({ action, body: obj });
|
|
1026
|
-
if (
|
|
1043
|
+
if (requests.length === batchSize || i === objects.length - 1) {
|
|
1027
1044
|
responses.push(await this.batch({ indexName, batchWriteParams: { requests } }, requestOptions));
|
|
1028
1045
|
requests = [];
|
|
1029
1046
|
}
|
|
@@ -1035,20 +1052,68 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1035
1052
|
}
|
|
1036
1053
|
return responses;
|
|
1037
1054
|
},
|
|
1055
|
+
/**
|
|
1056
|
+
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
|
|
1057
|
+
*
|
|
1058
|
+
* @summary Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
|
|
1059
|
+
* @param saveObjects - The `saveObjects` object.
|
|
1060
|
+
* @param saveObjects.indexName - The `indexName` to save `objects` in.
|
|
1061
|
+
* @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`.
|
|
1062
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
|
|
1063
|
+
*/
|
|
1064
|
+
async saveObjects({ indexName, objects }, requestOptions) {
|
|
1065
|
+
return await this.chunkedBatch({ indexName, objects, action: 'addObject' }, requestOptions);
|
|
1066
|
+
},
|
|
1067
|
+
/**
|
|
1068
|
+
* Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
|
|
1069
|
+
*
|
|
1070
|
+
* @summary Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objectIDs in it.
|
|
1071
|
+
* @param deleteObjects - The `deleteObjects` object.
|
|
1072
|
+
* @param deleteObjects.indexName - The `indexName` to delete `objectIDs` from.
|
|
1073
|
+
* @param deleteObjects.objectIDs - The objectIDs to delete.
|
|
1074
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions.
|
|
1075
|
+
*/
|
|
1076
|
+
async deleteObjects({ indexName, objectIDs }, requestOptions) {
|
|
1077
|
+
return await this.chunkedBatch({
|
|
1078
|
+
indexName,
|
|
1079
|
+
objects: objectIDs.map((objectID) => ({ objectID })),
|
|
1080
|
+
action: 'deleteObject',
|
|
1081
|
+
}, requestOptions);
|
|
1082
|
+
},
|
|
1083
|
+
/**
|
|
1084
|
+
* Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
|
|
1085
|
+
*
|
|
1086
|
+
* @summary Helper: Replaces object content of all the given objects according to their respective `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` requests with at most 1000 objects in it.
|
|
1087
|
+
* @param partialUpdateObjects - The `partialUpdateObjects` object.
|
|
1088
|
+
* @param partialUpdateObjects.indexName - The `indexName` to update `objects` in.
|
|
1089
|
+
* @param partialUpdateObjects.objects - The array of `objects` to update in the given Algolia `indexName`.
|
|
1090
|
+
* @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail..
|
|
1091
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
|
|
1092
|
+
*/
|
|
1093
|
+
async partialUpdateObjects({ indexName, objects, createIfNotExists }, requestOptions) {
|
|
1094
|
+
return await this.chunkedBatch({
|
|
1095
|
+
indexName,
|
|
1096
|
+
objects,
|
|
1097
|
+
action: createIfNotExists
|
|
1098
|
+
? 'partialUpdateObject'
|
|
1099
|
+
: 'partialUpdateObjectNoCreate',
|
|
1100
|
+
}, requestOptions);
|
|
1101
|
+
},
|
|
1038
1102
|
/**
|
|
1039
1103
|
* 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.
|
|
1104
|
+
* See https://api-clients-automation.netlify.app/docs/contributing/add-new-api-client#5-helpers for implementation details.
|
|
1040
1105
|
*
|
|
1041
1106
|
* @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
1107
|
* @param replaceAllObjects - The `replaceAllObjects` object.
|
|
1043
1108
|
* @param replaceAllObjects.indexName - The `indexName` to replace `objects` in.
|
|
1044
1109
|
* @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
|
|
1046
|
-
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
|
|
1110
|
+
* @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.
|
|
1111
|
+
* @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.
|
|
1047
1112
|
*/
|
|
1048
1113
|
async replaceAllObjects({ indexName, objects, batchSize }, requestOptions) {
|
|
1049
|
-
const randomSuffix = Math.
|
|
1114
|
+
const randomSuffix = Math.floor(Math.random() * 1000000) + 100000;
|
|
1050
1115
|
const tmpIndexName = `${indexName}_tmp_${randomSuffix}`;
|
|
1051
|
-
|
|
1116
|
+
let copyOperationResponse = await this.operationIndex({
|
|
1052
1117
|
indexName,
|
|
1053
1118
|
operationIndexParams: {
|
|
1054
1119
|
operation: 'copy',
|
|
@@ -1056,17 +1121,29 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1056
1121
|
scope: ['settings', 'rules', 'synonyms'],
|
|
1057
1122
|
},
|
|
1058
1123
|
}, requestOptions);
|
|
1124
|
+
const batchResponses = await this.chunkedBatch({ indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, requestOptions);
|
|
1059
1125
|
await this.waitForTask({
|
|
1126
|
+
indexName: tmpIndexName,
|
|
1127
|
+
taskID: copyOperationResponse.taskID,
|
|
1128
|
+
});
|
|
1129
|
+
copyOperationResponse = await this.operationIndex({
|
|
1060
1130
|
indexName,
|
|
1131
|
+
operationIndexParams: {
|
|
1132
|
+
operation: 'copy',
|
|
1133
|
+
destination: tmpIndexName,
|
|
1134
|
+
scope: ['settings', 'rules', 'synonyms'],
|
|
1135
|
+
},
|
|
1136
|
+
}, requestOptions);
|
|
1137
|
+
await this.waitForTask({
|
|
1138
|
+
indexName: tmpIndexName,
|
|
1061
1139
|
taskID: copyOperationResponse.taskID,
|
|
1062
1140
|
});
|
|
1063
|
-
const batchResponses = await this.chunkedBatch({ indexName: tmpIndexName, objects, waitForTasks: true, batchSize }, requestOptions);
|
|
1064
1141
|
const moveOperationResponse = await this.operationIndex({
|
|
1065
1142
|
indexName: tmpIndexName,
|
|
1066
1143
|
operationIndexParams: { operation: 'move', destination: indexName },
|
|
1067
1144
|
}, requestOptions);
|
|
1068
1145
|
await this.waitForTask({
|
|
1069
|
-
indexName,
|
|
1146
|
+
indexName: tmpIndexName,
|
|
1070
1147
|
taskID: moveOperationResponse.taskID,
|
|
1071
1148
|
});
|
|
1072
1149
|
return { copyOperationResponse, batchResponses, moveOperationResponse };
|
|
@@ -1302,7 +1379,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1302
1379
|
return transporter.request(request, requestOptions);
|
|
1303
1380
|
},
|
|
1304
1381
|
/**
|
|
1305
|
-
* Retrieves records from an index, up to 1,000 per request. While searching retrieves _hits_ (records augmented with attributes for highlighting and ranking details), browsing _just_ returns matching records. This can be useful if you want to export your indices. - The Analytics API doesn\'t collect data when using `browse`. - Records are ranked by attributes and custom ranking. -
|
|
1382
|
+
* Retrieves records from an index, up to 1,000 per request. While searching retrieves _hits_ (records augmented with attributes for highlighting and ranking details), browsing _just_ returns matching records. This can be useful if you want to export your indices. - The Analytics API doesn\'t collect data when using `browse`. - Records are ranked by attributes and custom ranking. - There\'s no ranking for: typo-tolerance, number of matched words, proximity, geo distance. Browse requests automatically apply these settings: - `advancedSyntax`: `false` - `attributesToHighlight`: `[]` - `attributesToSnippet`: `[]` - `distinct`: `false` - `enablePersonalization`: `false` - `enableRules`: `false` - `facets`: `[]` - `getRankingInfo`: `false` - `ignorePlurals`: `false` - `optionalFilters`: `[]` - `typoTolerance`: `true` or `false` (`min` and `strict` is evaluated to `true`) If you send these parameters with your browse requests, they\'ll be ignored.
|
|
1306
1383
|
*
|
|
1307
1384
|
* Required API Key ACLs:
|
|
1308
1385
|
* - browse.
|
|
@@ -1735,6 +1812,31 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1735
1812
|
};
|
|
1736
1813
|
return transporter.request(request, requestOptions);
|
|
1737
1814
|
},
|
|
1815
|
+
/**
|
|
1816
|
+
* Checks the status of a given application task.
|
|
1817
|
+
*
|
|
1818
|
+
* Required API Key ACLs:
|
|
1819
|
+
* - editSettings.
|
|
1820
|
+
*
|
|
1821
|
+
* @param getAppTask - The getAppTask object.
|
|
1822
|
+
* @param getAppTask.taskID - Unique task identifier.
|
|
1823
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1824
|
+
*/
|
|
1825
|
+
getAppTask({ taskID }, requestOptions) {
|
|
1826
|
+
if (!taskID) {
|
|
1827
|
+
throw new Error('Parameter `taskID` is required when calling `getAppTask`.');
|
|
1828
|
+
}
|
|
1829
|
+
const requestPath = '/1/task/{taskID}'.replace('{taskID}', encodeURIComponent(taskID));
|
|
1830
|
+
const headers = {};
|
|
1831
|
+
const queryParameters = {};
|
|
1832
|
+
const request = {
|
|
1833
|
+
method: 'GET',
|
|
1834
|
+
path: requestPath,
|
|
1835
|
+
queryParameters,
|
|
1836
|
+
headers,
|
|
1837
|
+
};
|
|
1838
|
+
return transporter.request(request, requestOptions);
|
|
1839
|
+
},
|
|
1738
1840
|
/**
|
|
1739
1841
|
* Lists supported languages with their supported dictionary types and number of custom entries.
|
|
1740
1842
|
*
|
|
@@ -2209,7 +2311,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
2209
2311
|
return transporter.request(request, requestOptions);
|
|
2210
2312
|
},
|
|
2211
2313
|
/**
|
|
2212
|
-
* Copies or moves (renames) an index within the same Algolia application. - Existing destination indices are overwritten, except for
|
|
2314
|
+
* 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
2315
|
*
|
|
2214
2316
|
* Required API Key ACLs:
|
|
2215
2317
|
* - addObject.
|