@algolia/client-search 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.
- package/dist/client-search.cjs.js +143 -21
- package/dist/client-search.esm.browser.js +171 -49
- package/dist/client-search.esm.node.js +144 -22
- package/dist/client-search.umd.js +2 -2
- package/dist/model/acl.d.ts +3 -0
- package/dist/model/acl.d.ts.map +1 -1
- package/dist/model/addApiKeyResponse.d.ts +1 -1
- package/dist/model/attributeToUpdate.d.ts +3 -0
- package/dist/model/attributeToUpdate.d.ts.map +1 -0
- package/dist/model/baseGetApiKeyResponse.d.ts +11 -0
- package/dist/model/baseGetApiKeyResponse.d.ts.map +1 -0
- package/dist/model/batchParams.d.ts +1 -1
- package/dist/model/batchParams.d.ts.map +1 -1
- package/dist/model/clientMethodProps.d.ts +20 -7
- package/dist/model/clientMethodProps.d.ts.map +1 -1
- package/dist/model/getApiKeyResponse.d.ts +4 -0
- package/dist/model/getApiKeyResponse.d.ts.map +1 -0
- package/dist/model/getObjectsParams.d.ts +1 -1
- package/dist/model/getObjectsParams.d.ts.map +1 -1
- package/dist/model/index.d.ts +3 -3
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/listApiKeysResponse.d.ts +2 -2
- package/dist/model/listApiKeysResponse.d.ts.map +1 -1
- package/dist/model/multipleBatchRequest.d.ts +3 -3
- package/dist/model/multipleBatchRequest.d.ts.map +1 -1
- package/dist/model/multipleBatchResponse.d.ts +2 -2
- package/dist/model/multipleBatchResponse.d.ts.map +1 -1
- package/dist/model/updateApiKeyResponse.d.ts +1 -1
- package/dist/src/searchClient.d.ts +62 -15
- package/dist/src/searchClient.d.ts.map +1 -1
- package/model/acl.ts +3 -0
- package/model/addApiKeyResponse.ts +1 -1
- package/model/{attributeOrBuiltInOperation.ts → attributeToUpdate.ts} +1 -1
- package/model/baseGetApiKeyResponse.ts +13 -0
- package/model/batchParams.ts +1 -1
- package/model/clientMethodProps.ts +27 -11
- package/model/{key.ts → getApiKeyResponse.ts} +2 -2
- package/model/getObjectsParams.ts +1 -1
- package/model/index.ts +3 -3
- package/model/listApiKeysResponse.ts +2 -2
- package/model/multipleBatchRequest.ts +3 -3
- package/model/multipleBatchResponse.ts +2 -2
- package/model/updateApiKeyResponse.ts +1 -1
- package/package.json +5 -5
- package/dist/model/attributeOrBuiltInOperation.d.ts +0 -3
- package/dist/model/attributeOrBuiltInOperation.d.ts.map +0 -1
- package/dist/model/createdAtObject.d.ts +0 -7
- package/dist/model/createdAtObject.d.ts.map +0 -1
- package/dist/model/key.d.ts +0 -4
- package/dist/model/key.d.ts.map +0 -1
- package/model/createdAtObject.ts +0 -8
|
@@ -6,7 +6,7 @@ var clientCommon = require('@algolia/client-common');
|
|
|
6
6
|
var requesterNodeHttp = require('@algolia/requester-node-http');
|
|
7
7
|
|
|
8
8
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
9
|
-
const apiClientVersion = '5.0.0-alpha.
|
|
9
|
+
const apiClientVersion = '5.0.0-alpha.4';
|
|
10
10
|
function getDefaultHosts(appId) {
|
|
11
11
|
return [
|
|
12
12
|
{
|
|
@@ -60,6 +60,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
60
60
|
});
|
|
61
61
|
return {
|
|
62
62
|
transporter,
|
|
63
|
+
/**
|
|
64
|
+
* The `appId` currently in use.
|
|
65
|
+
*/
|
|
66
|
+
appId: appIdOption,
|
|
67
|
+
/**
|
|
68
|
+
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
|
|
69
|
+
*/
|
|
70
|
+
clearCache() {
|
|
71
|
+
return Promise.all([
|
|
72
|
+
transporter.requestsCache.clear(),
|
|
73
|
+
transporter.responsesCache.clear(),
|
|
74
|
+
]).then(() => undefined);
|
|
75
|
+
},
|
|
63
76
|
/**
|
|
64
77
|
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
|
|
65
78
|
*/
|
|
@@ -76,38 +89,57 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
76
89
|
transporter.algoliaAgent.add({ segment, version });
|
|
77
90
|
},
|
|
78
91
|
/**
|
|
79
|
-
* Helper: Wait for a task to
|
|
92
|
+
* Helper: Wait for a task to be published (completed) for a given `indexName` and `taskID`.
|
|
80
93
|
*
|
|
81
|
-
* @summary
|
|
94
|
+
* @summary Helper method that waits for a task to be published (completed).
|
|
82
95
|
* @param waitForTaskOptions - The waitForTaskOptions object.
|
|
83
96
|
* @param waitForTaskOptions.indexName - The `indexName` where the operation was performed.
|
|
84
97
|
* @param waitForTaskOptions.taskID - The `taskID` returned in the method response.
|
|
98
|
+
* @param waitForTaskOptions.maxRetries - The maximum number of retries. 50 by default.
|
|
99
|
+
* @param waitForTaskOptions.timeout - The function to decide how long to wait between retries.
|
|
85
100
|
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
|
|
86
101
|
*/
|
|
87
|
-
waitForTask({ indexName, taskID,
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
waitForTask({ indexName, taskID, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
|
|
103
|
+
let retryCount = 0;
|
|
104
|
+
return clientCommon.createIterablePromise({
|
|
90
105
|
func: () => this.getTask({ indexName, taskID }, requestOptions),
|
|
91
106
|
validate: (response) => response.status === 'published',
|
|
107
|
+
aggregator: () => (retryCount += 1),
|
|
108
|
+
error: {
|
|
109
|
+
validate: () => retryCount >= maxRetries,
|
|
110
|
+
message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
|
|
111
|
+
},
|
|
112
|
+
timeout: () => timeout(retryCount),
|
|
92
113
|
});
|
|
93
114
|
},
|
|
94
115
|
/**
|
|
95
116
|
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
|
|
96
117
|
*
|
|
97
|
-
* @summary
|
|
118
|
+
* @summary Helper method that waits for an API key task to be processed.
|
|
98
119
|
* @param waitForApiKeyOptions - The waitForApiKeyOptions object.
|
|
99
120
|
* @param waitForApiKeyOptions.operation - The `operation` that was done on a `key`.
|
|
100
121
|
* @param waitForApiKeyOptions.key - The `key` that has been added, deleted or updated.
|
|
101
122
|
* @param waitForApiKeyOptions.apiKey - Necessary to know if an `update` operation has been processed, compare fields of the response with it.
|
|
123
|
+
* @param waitForApiKeyOptions.maxRetries - The maximum number of retries. 50 by default.
|
|
124
|
+
* @param waitForApiKeyOptions.timeout - The function to decide how long to wait between retries.
|
|
102
125
|
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getApikey` method and merged with the transporter requestOptions.
|
|
103
126
|
*/
|
|
104
|
-
waitForApiKey({ operation, key, apiKey,
|
|
127
|
+
waitForApiKey({ operation, key, apiKey, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
|
|
128
|
+
let retryCount = 0;
|
|
129
|
+
const baseIteratorOptions = {
|
|
130
|
+
aggregator: () => (retryCount += 1),
|
|
131
|
+
error: {
|
|
132
|
+
validate: () => retryCount >= maxRetries,
|
|
133
|
+
message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
|
|
134
|
+
},
|
|
135
|
+
timeout: () => timeout(retryCount),
|
|
136
|
+
};
|
|
105
137
|
if (operation === 'update') {
|
|
106
138
|
if (!apiKey) {
|
|
107
139
|
throw new Error('`apiKey` is required when waiting for an `update` operation.');
|
|
108
140
|
}
|
|
109
|
-
return clientCommon.
|
|
110
|
-
...
|
|
141
|
+
return clientCommon.createIterablePromise({
|
|
142
|
+
...baseIteratorOptions,
|
|
111
143
|
func: () => this.getApiKey({ key }, requestOptions),
|
|
112
144
|
validate: (response) => {
|
|
113
145
|
for (const field of Object.keys(apiKey)) {
|
|
@@ -125,12 +157,99 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
125
157
|
},
|
|
126
158
|
});
|
|
127
159
|
}
|
|
128
|
-
return clientCommon.
|
|
129
|
-
...
|
|
160
|
+
return clientCommon.createIterablePromise({
|
|
161
|
+
...baseIteratorOptions,
|
|
130
162
|
func: () => this.getApiKey({ key }, requestOptions).catch((error) => error),
|
|
131
163
|
validate: (error) => operation === 'add' ? error.status !== 404 : error.status === 404,
|
|
132
164
|
});
|
|
133
165
|
},
|
|
166
|
+
/**
|
|
167
|
+
* Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
|
|
168
|
+
*
|
|
169
|
+
* @summary Helper method that iterates on the `browse` method.
|
|
170
|
+
* @param browseObjects - The browseObjects object.
|
|
171
|
+
* @param browseObjects.indexName - The index in which to perform the request.
|
|
172
|
+
* @param browseObjects.browseRequest - The `browse` method parameters.
|
|
173
|
+
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
|
|
174
|
+
* @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`.
|
|
175
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
|
|
176
|
+
*/
|
|
177
|
+
browseObjects({ indexName, browseRequest, ...browseObjectsOptions }, requestOptions) {
|
|
178
|
+
return clientCommon.createIterablePromise({
|
|
179
|
+
func: (previousResponse) => {
|
|
180
|
+
return this.browse({
|
|
181
|
+
indexName,
|
|
182
|
+
browseRequest: {
|
|
183
|
+
cursor: previousResponse ? previousResponse.cursor : undefined,
|
|
184
|
+
...browseRequest,
|
|
185
|
+
},
|
|
186
|
+
}, requestOptions);
|
|
187
|
+
},
|
|
188
|
+
validate: (response) => response.cursor === undefined,
|
|
189
|
+
...browseObjectsOptions,
|
|
190
|
+
});
|
|
191
|
+
},
|
|
192
|
+
/**
|
|
193
|
+
* Helper: Iterate on the `searchRules` method of the client to allow aggregating rules of an index.
|
|
194
|
+
*
|
|
195
|
+
* @summary Helper method that iterates on the `searchRules` method.
|
|
196
|
+
* @param browseObjects - The browseObjects object.
|
|
197
|
+
* @param browseObjects.indexName - The index in which to perform the request.
|
|
198
|
+
* @param browseObjects.searchRulesParams - The `searchRules` method parameters.
|
|
199
|
+
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
|
|
200
|
+
* @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`.
|
|
201
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchRules` method and merged with the transporter requestOptions.
|
|
202
|
+
*/
|
|
203
|
+
browseRules({ indexName, searchRulesParams, ...browseRulesOptions }, requestOptions) {
|
|
204
|
+
const params = {
|
|
205
|
+
hitsPerPage: 1000,
|
|
206
|
+
...searchRulesParams,
|
|
207
|
+
};
|
|
208
|
+
return clientCommon.createIterablePromise({
|
|
209
|
+
func: (previousResponse) => {
|
|
210
|
+
return this.searchRules({
|
|
211
|
+
indexName,
|
|
212
|
+
searchRulesParams: {
|
|
213
|
+
...params,
|
|
214
|
+
page: previousResponse
|
|
215
|
+
? previousResponse.page + 1
|
|
216
|
+
: params.page || 0,
|
|
217
|
+
},
|
|
218
|
+
}, requestOptions);
|
|
219
|
+
},
|
|
220
|
+
validate: (response) => response.nbHits < params.hitsPerPage,
|
|
221
|
+
...browseRulesOptions,
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
/**
|
|
225
|
+
* Helper: Iterate on the `searchSynonyms` method of the client to allow aggregating rules of an index.
|
|
226
|
+
*
|
|
227
|
+
* @summary Helper method that iterates on the `searchSynonyms` method.
|
|
228
|
+
* @param browseObjects - The browseObjects object.
|
|
229
|
+
* @param browseObjects.indexName - The index in which to perform the request.
|
|
230
|
+
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
|
|
231
|
+
* @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`.
|
|
232
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method and merged with the transporter requestOptions.
|
|
233
|
+
*/
|
|
234
|
+
browseSynonyms({ indexName, validate, aggregator, ...browseSynonymsOptions }, requestOptions) {
|
|
235
|
+
const params = {
|
|
236
|
+
hitsPerPage: 1000,
|
|
237
|
+
...browseSynonymsOptions,
|
|
238
|
+
};
|
|
239
|
+
return clientCommon.createIterablePromise({
|
|
240
|
+
func: (previousResponse) => {
|
|
241
|
+
return this.searchSynonyms({
|
|
242
|
+
...params,
|
|
243
|
+
indexName,
|
|
244
|
+
page: previousResponse
|
|
245
|
+
? previousResponse.page + 1
|
|
246
|
+
: browseSynonymsOptions.page || 0,
|
|
247
|
+
}, requestOptions);
|
|
248
|
+
},
|
|
249
|
+
validate: (response) => response.nbHits < params.hitsPerPage,
|
|
250
|
+
...browseSynonymsOptions,
|
|
251
|
+
});
|
|
252
|
+
},
|
|
134
253
|
/**
|
|
135
254
|
* Add a new API Key with specific permissions/restrictions.
|
|
136
255
|
*
|
|
@@ -824,6 +943,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
824
943
|
if (!getObjectsParams) {
|
|
825
944
|
throw new Error('Parameter `getObjectsParams` is required when calling `getObjects`.');
|
|
826
945
|
}
|
|
946
|
+
if (!getObjectsParams.requests) {
|
|
947
|
+
throw new Error('Parameter `getObjectsParams.requests` is required when calling `getObjects`.');
|
|
948
|
+
}
|
|
827
949
|
const requestPath = '/1/indexes/*/objects';
|
|
828
950
|
const headers = {};
|
|
829
951
|
const queryParameters = {};
|
|
@@ -1127,6 +1249,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1127
1249
|
if (!batchParams) {
|
|
1128
1250
|
throw new Error('Parameter `batchParams` is required when calling `multipleBatch`.');
|
|
1129
1251
|
}
|
|
1252
|
+
if (!batchParams.requests) {
|
|
1253
|
+
throw new Error('Parameter `batchParams.requests` is required when calling `multipleBatch`.');
|
|
1254
|
+
}
|
|
1130
1255
|
const requestPath = '/1/indexes/*/batch';
|
|
1131
1256
|
const headers = {};
|
|
1132
1257
|
const queryParameters = {};
|
|
@@ -1180,19 +1305,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1180
1305
|
* @param partialUpdateObject - The partialUpdateObject object.
|
|
1181
1306
|
* @param partialUpdateObject.indexName - The index in which to perform the request.
|
|
1182
1307
|
* @param partialUpdateObject.objectID - Unique identifier of an object.
|
|
1183
|
-
* @param partialUpdateObject.
|
|
1308
|
+
* @param partialUpdateObject.attributeToUpdate - List of attributes to update.
|
|
1184
1309
|
* @param partialUpdateObject.createIfNotExists - Creates the record if it does not exist yet.
|
|
1185
1310
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1186
1311
|
*/
|
|
1187
|
-
partialUpdateObject({ indexName, objectID,
|
|
1312
|
+
partialUpdateObject({ indexName, objectID, attributeToUpdate, createIfNotExists, }, requestOptions) {
|
|
1188
1313
|
if (!indexName) {
|
|
1189
1314
|
throw new Error('Parameter `indexName` is required when calling `partialUpdateObject`.');
|
|
1190
1315
|
}
|
|
1191
1316
|
if (!objectID) {
|
|
1192
1317
|
throw new Error('Parameter `objectID` is required when calling `partialUpdateObject`.');
|
|
1193
1318
|
}
|
|
1194
|
-
if (!
|
|
1195
|
-
throw new Error('Parameter `
|
|
1319
|
+
if (!attributeToUpdate) {
|
|
1320
|
+
throw new Error('Parameter `attributeToUpdate` is required when calling `partialUpdateObject`.');
|
|
1196
1321
|
}
|
|
1197
1322
|
const requestPath = '/1/indexes/{indexName}/{objectID}/partial'
|
|
1198
1323
|
.replace('{indexName}', encodeURIComponent(indexName))
|
|
@@ -1207,7 +1332,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1207
1332
|
path: requestPath,
|
|
1208
1333
|
queryParameters,
|
|
1209
1334
|
headers,
|
|
1210
|
-
data:
|
|
1335
|
+
data: attributeToUpdate,
|
|
1211
1336
|
};
|
|
1212
1337
|
return transporter.request(request, requestOptions);
|
|
1213
1338
|
},
|
|
@@ -1645,9 +1770,6 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1645
1770
|
if (!indexName) {
|
|
1646
1771
|
throw new Error('Parameter `indexName` is required when calling `searchRules`.');
|
|
1647
1772
|
}
|
|
1648
|
-
if (!searchRulesParams) {
|
|
1649
|
-
throw new Error('Parameter `searchRulesParams` is required when calling `searchRules`.');
|
|
1650
|
-
}
|
|
1651
1773
|
const requestPath = '/1/indexes/{indexName}/rules/search'.replace('{indexName}', encodeURIComponent(indexName));
|
|
1652
1774
|
const headers = {};
|
|
1653
1775
|
const queryParameters = {};
|
|
@@ -1656,7 +1778,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1656
1778
|
path: requestPath,
|
|
1657
1779
|
queryParameters,
|
|
1658
1780
|
headers,
|
|
1659
|
-
data: searchRulesParams,
|
|
1781
|
+
data: searchRulesParams ? searchRulesParams : {},
|
|
1660
1782
|
useReadTransporter: true,
|
|
1661
1783
|
cacheable: true,
|
|
1662
1784
|
};
|
|
@@ -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
|
-
*
|
|
19
|
+
* Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.
|
|
22
20
|
*
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
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
|
-
|
|
34
|
-
|
|
31
|
+
aggregator,
|
|
32
|
+
error,
|
|
33
|
+
timeout = () => 0
|
|
35
34
|
}) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const retry = () => {
|
|
35
|
+
const retry = previousResponse => {
|
|
39
36
|
return new Promise((resolve, reject) => {
|
|
40
|
-
func().then(response => {
|
|
41
|
-
|
|
37
|
+
func(previousResponse).then(response => {
|
|
38
|
+
if (aggregator) {
|
|
39
|
+
aggregator(response);
|
|
40
|
+
}
|
|
42
41
|
|
|
43
|
-
if (
|
|
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
|
-
|
|
54
|
-
|
|
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
|
};
|
|
@@ -767,7 +767,7 @@ function createXhrRequester() {
|
|
|
767
767
|
}
|
|
768
768
|
|
|
769
769
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
770
|
-
const apiClientVersion = '5.0.0-alpha.
|
|
770
|
+
const apiClientVersion = '5.0.0-alpha.4';
|
|
771
771
|
function getDefaultHosts(appId) {
|
|
772
772
|
return [
|
|
773
773
|
{
|
|
@@ -821,6 +821,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
821
821
|
});
|
|
822
822
|
return {
|
|
823
823
|
transporter,
|
|
824
|
+
/**
|
|
825
|
+
* The `appId` currently in use.
|
|
826
|
+
*/
|
|
827
|
+
appId: appIdOption,
|
|
828
|
+
/**
|
|
829
|
+
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
|
|
830
|
+
*/
|
|
831
|
+
clearCache() {
|
|
832
|
+
return Promise.all([
|
|
833
|
+
transporter.requestsCache.clear(),
|
|
834
|
+
transporter.responsesCache.clear(),
|
|
835
|
+
]).then(() => undefined);
|
|
836
|
+
},
|
|
824
837
|
/**
|
|
825
838
|
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
|
|
826
839
|
*/
|
|
@@ -837,38 +850,57 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
837
850
|
transporter.algoliaAgent.add({ segment, version });
|
|
838
851
|
},
|
|
839
852
|
/**
|
|
840
|
-
* Helper: Wait for a task to
|
|
853
|
+
* Helper: Wait for a task to be published (completed) for a given `indexName` and `taskID`.
|
|
841
854
|
*
|
|
842
|
-
* @summary
|
|
855
|
+
* @summary Helper method that waits for a task to be published (completed).
|
|
843
856
|
* @param waitForTaskOptions - The waitForTaskOptions object.
|
|
844
857
|
* @param waitForTaskOptions.indexName - The `indexName` where the operation was performed.
|
|
845
858
|
* @param waitForTaskOptions.taskID - The `taskID` returned in the method response.
|
|
859
|
+
* @param waitForTaskOptions.maxRetries - The maximum number of retries. 50 by default.
|
|
860
|
+
* @param waitForTaskOptions.timeout - The function to decide how long to wait between retries.
|
|
846
861
|
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
|
|
847
862
|
*/
|
|
848
|
-
waitForTask({ indexName, taskID,
|
|
849
|
-
|
|
850
|
-
|
|
863
|
+
waitForTask({ indexName, taskID, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
|
|
864
|
+
let retryCount = 0;
|
|
865
|
+
return createIterablePromise({
|
|
851
866
|
func: () => this.getTask({ indexName, taskID }, requestOptions),
|
|
852
867
|
validate: (response) => response.status === 'published',
|
|
868
|
+
aggregator: () => (retryCount += 1),
|
|
869
|
+
error: {
|
|
870
|
+
validate: () => retryCount >= maxRetries,
|
|
871
|
+
message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
|
|
872
|
+
},
|
|
873
|
+
timeout: () => timeout(retryCount),
|
|
853
874
|
});
|
|
854
875
|
},
|
|
855
876
|
/**
|
|
856
877
|
* Helper: Wait for an API key to be added, updated or deleted based on a given `operation`.
|
|
857
878
|
*
|
|
858
|
-
* @summary
|
|
879
|
+
* @summary Helper method that waits for an API key task to be processed.
|
|
859
880
|
* @param waitForApiKeyOptions - The waitForApiKeyOptions object.
|
|
860
881
|
* @param waitForApiKeyOptions.operation - The `operation` that was done on a `key`.
|
|
861
882
|
* @param waitForApiKeyOptions.key - The `key` that has been added, deleted or updated.
|
|
862
883
|
* @param waitForApiKeyOptions.apiKey - Necessary to know if an `update` operation has been processed, compare fields of the response with it.
|
|
884
|
+
* @param waitForApiKeyOptions.maxRetries - The maximum number of retries. 50 by default.
|
|
885
|
+
* @param waitForApiKeyOptions.timeout - The function to decide how long to wait between retries.
|
|
863
886
|
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getApikey` method and merged with the transporter requestOptions.
|
|
864
887
|
*/
|
|
865
|
-
waitForApiKey({ operation, key, apiKey,
|
|
888
|
+
waitForApiKey({ operation, key, apiKey, maxRetries = 50, timeout = (retryCount) => Math.min(retryCount * 200, 5000), }, requestOptions) {
|
|
889
|
+
let retryCount = 0;
|
|
890
|
+
const baseIteratorOptions = {
|
|
891
|
+
aggregator: () => (retryCount += 1),
|
|
892
|
+
error: {
|
|
893
|
+
validate: () => retryCount >= maxRetries,
|
|
894
|
+
message: () => `The maximum number of retries exceeded. (${retryCount}/${maxRetries})`,
|
|
895
|
+
},
|
|
896
|
+
timeout: () => timeout(retryCount),
|
|
897
|
+
};
|
|
866
898
|
if (operation === 'update') {
|
|
867
899
|
if (!apiKey) {
|
|
868
900
|
throw new Error('`apiKey` is required when waiting for an `update` operation.');
|
|
869
901
|
}
|
|
870
|
-
return
|
|
871
|
-
...
|
|
902
|
+
return createIterablePromise({
|
|
903
|
+
...baseIteratorOptions,
|
|
872
904
|
func: () => this.getApiKey({ key }, requestOptions),
|
|
873
905
|
validate: (response) => {
|
|
874
906
|
for (const field of Object.keys(apiKey)) {
|
|
@@ -886,12 +918,99 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
886
918
|
},
|
|
887
919
|
});
|
|
888
920
|
}
|
|
889
|
-
return
|
|
890
|
-
...
|
|
921
|
+
return createIterablePromise({
|
|
922
|
+
...baseIteratorOptions,
|
|
891
923
|
func: () => this.getApiKey({ key }, requestOptions).catch((error) => error),
|
|
892
924
|
validate: (error) => operation === 'add' ? error.status !== 404 : error.status === 404,
|
|
893
925
|
});
|
|
894
926
|
},
|
|
927
|
+
/**
|
|
928
|
+
* Helper: Iterate on the `browse` method of the client to allow aggregating objects of an index.
|
|
929
|
+
*
|
|
930
|
+
* @summary Helper method that iterates on the `browse` method.
|
|
931
|
+
* @param browseObjects - The browseObjects object.
|
|
932
|
+
* @param browseObjects.indexName - The index in which to perform the request.
|
|
933
|
+
* @param browseObjects.browseRequest - The `browse` method parameters.
|
|
934
|
+
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
|
|
935
|
+
* @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`.
|
|
936
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `browse` method and merged with the transporter requestOptions.
|
|
937
|
+
*/
|
|
938
|
+
browseObjects({ indexName, browseRequest, ...browseObjectsOptions }, requestOptions) {
|
|
939
|
+
return createIterablePromise({
|
|
940
|
+
func: (previousResponse) => {
|
|
941
|
+
return this.browse({
|
|
942
|
+
indexName,
|
|
943
|
+
browseRequest: {
|
|
944
|
+
cursor: previousResponse ? previousResponse.cursor : undefined,
|
|
945
|
+
...browseRequest,
|
|
946
|
+
},
|
|
947
|
+
}, requestOptions);
|
|
948
|
+
},
|
|
949
|
+
validate: (response) => response.cursor === undefined,
|
|
950
|
+
...browseObjectsOptions,
|
|
951
|
+
});
|
|
952
|
+
},
|
|
953
|
+
/**
|
|
954
|
+
* Helper: Iterate on the `searchRules` method of the client to allow aggregating rules of an index.
|
|
955
|
+
*
|
|
956
|
+
* @summary Helper method that iterates on the `searchRules` method.
|
|
957
|
+
* @param browseObjects - The browseObjects object.
|
|
958
|
+
* @param browseObjects.indexName - The index in which to perform the request.
|
|
959
|
+
* @param browseObjects.searchRulesParams - The `searchRules` method parameters.
|
|
960
|
+
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
|
|
961
|
+
* @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`.
|
|
962
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchRules` method and merged with the transporter requestOptions.
|
|
963
|
+
*/
|
|
964
|
+
browseRules({ indexName, searchRulesParams, ...browseRulesOptions }, requestOptions) {
|
|
965
|
+
const params = {
|
|
966
|
+
hitsPerPage: 1000,
|
|
967
|
+
...searchRulesParams,
|
|
968
|
+
};
|
|
969
|
+
return createIterablePromise({
|
|
970
|
+
func: (previousResponse) => {
|
|
971
|
+
return this.searchRules({
|
|
972
|
+
indexName,
|
|
973
|
+
searchRulesParams: {
|
|
974
|
+
...params,
|
|
975
|
+
page: previousResponse
|
|
976
|
+
? previousResponse.page + 1
|
|
977
|
+
: params.page || 0,
|
|
978
|
+
},
|
|
979
|
+
}, requestOptions);
|
|
980
|
+
},
|
|
981
|
+
validate: (response) => response.nbHits < params.hitsPerPage,
|
|
982
|
+
...browseRulesOptions,
|
|
983
|
+
});
|
|
984
|
+
},
|
|
985
|
+
/**
|
|
986
|
+
* Helper: Iterate on the `searchSynonyms` method of the client to allow aggregating rules of an index.
|
|
987
|
+
*
|
|
988
|
+
* @summary Helper method that iterates on the `searchSynonyms` method.
|
|
989
|
+
* @param browseObjects - The browseObjects object.
|
|
990
|
+
* @param browseObjects.indexName - The index in which to perform the request.
|
|
991
|
+
* @param browseObjects.validate - The validator function. It receive the resolved return of the API call.
|
|
992
|
+
* @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`.
|
|
993
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method and merged with the transporter requestOptions.
|
|
994
|
+
*/
|
|
995
|
+
browseSynonyms({ indexName, validate, aggregator, ...browseSynonymsOptions }, requestOptions) {
|
|
996
|
+
const params = {
|
|
997
|
+
hitsPerPage: 1000,
|
|
998
|
+
...browseSynonymsOptions,
|
|
999
|
+
};
|
|
1000
|
+
return createIterablePromise({
|
|
1001
|
+
func: (previousResponse) => {
|
|
1002
|
+
return this.searchSynonyms({
|
|
1003
|
+
...params,
|
|
1004
|
+
indexName,
|
|
1005
|
+
page: previousResponse
|
|
1006
|
+
? previousResponse.page + 1
|
|
1007
|
+
: browseSynonymsOptions.page || 0,
|
|
1008
|
+
}, requestOptions);
|
|
1009
|
+
},
|
|
1010
|
+
validate: (response) => response.nbHits < params.hitsPerPage,
|
|
1011
|
+
...browseSynonymsOptions,
|
|
1012
|
+
});
|
|
1013
|
+
},
|
|
895
1014
|
/**
|
|
896
1015
|
* Add a new API Key with specific permissions/restrictions.
|
|
897
1016
|
*
|
|
@@ -1585,6 +1704,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1585
1704
|
if (!getObjectsParams) {
|
|
1586
1705
|
throw new Error('Parameter `getObjectsParams` is required when calling `getObjects`.');
|
|
1587
1706
|
}
|
|
1707
|
+
if (!getObjectsParams.requests) {
|
|
1708
|
+
throw new Error('Parameter `getObjectsParams.requests` is required when calling `getObjects`.');
|
|
1709
|
+
}
|
|
1588
1710
|
const requestPath = '/1/indexes/*/objects';
|
|
1589
1711
|
const headers = {};
|
|
1590
1712
|
const queryParameters = {};
|
|
@@ -1888,6 +2010,9 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1888
2010
|
if (!batchParams) {
|
|
1889
2011
|
throw new Error('Parameter `batchParams` is required when calling `multipleBatch`.');
|
|
1890
2012
|
}
|
|
2013
|
+
if (!batchParams.requests) {
|
|
2014
|
+
throw new Error('Parameter `batchParams.requests` is required when calling `multipleBatch`.');
|
|
2015
|
+
}
|
|
1891
2016
|
const requestPath = '/1/indexes/*/batch';
|
|
1892
2017
|
const headers = {};
|
|
1893
2018
|
const queryParameters = {};
|
|
@@ -1941,19 +2066,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1941
2066
|
* @param partialUpdateObject - The partialUpdateObject object.
|
|
1942
2067
|
* @param partialUpdateObject.indexName - The index in which to perform the request.
|
|
1943
2068
|
* @param partialUpdateObject.objectID - Unique identifier of an object.
|
|
1944
|
-
* @param partialUpdateObject.
|
|
2069
|
+
* @param partialUpdateObject.attributeToUpdate - List of attributes to update.
|
|
1945
2070
|
* @param partialUpdateObject.createIfNotExists - Creates the record if it does not exist yet.
|
|
1946
2071
|
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1947
2072
|
*/
|
|
1948
|
-
partialUpdateObject({ indexName, objectID,
|
|
2073
|
+
partialUpdateObject({ indexName, objectID, attributeToUpdate, createIfNotExists, }, requestOptions) {
|
|
1949
2074
|
if (!indexName) {
|
|
1950
2075
|
throw new Error('Parameter `indexName` is required when calling `partialUpdateObject`.');
|
|
1951
2076
|
}
|
|
1952
2077
|
if (!objectID) {
|
|
1953
2078
|
throw new Error('Parameter `objectID` is required when calling `partialUpdateObject`.');
|
|
1954
2079
|
}
|
|
1955
|
-
if (!
|
|
1956
|
-
throw new Error('Parameter `
|
|
2080
|
+
if (!attributeToUpdate) {
|
|
2081
|
+
throw new Error('Parameter `attributeToUpdate` is required when calling `partialUpdateObject`.');
|
|
1957
2082
|
}
|
|
1958
2083
|
const requestPath = '/1/indexes/{indexName}/{objectID}/partial'
|
|
1959
2084
|
.replace('{indexName}', encodeURIComponent(indexName))
|
|
@@ -1968,7 +2093,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
1968
2093
|
path: requestPath,
|
|
1969
2094
|
queryParameters,
|
|
1970
2095
|
headers,
|
|
1971
|
-
data:
|
|
2096
|
+
data: attributeToUpdate,
|
|
1972
2097
|
};
|
|
1973
2098
|
return transporter.request(request, requestOptions);
|
|
1974
2099
|
},
|
|
@@ -2406,9 +2531,6 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
2406
2531
|
if (!indexName) {
|
|
2407
2532
|
throw new Error('Parameter `indexName` is required when calling `searchRules`.');
|
|
2408
2533
|
}
|
|
2409
|
-
if (!searchRulesParams) {
|
|
2410
|
-
throw new Error('Parameter `searchRulesParams` is required when calling `searchRules`.');
|
|
2411
|
-
}
|
|
2412
2534
|
const requestPath = '/1/indexes/{indexName}/rules/search'.replace('{indexName}', encodeURIComponent(indexName));
|
|
2413
2535
|
const headers = {};
|
|
2414
2536
|
const queryParameters = {};
|
|
@@ -2417,7 +2539,7 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
|
|
|
2417
2539
|
path: requestPath,
|
|
2418
2540
|
queryParameters,
|
|
2419
2541
|
headers,
|
|
2420
|
-
data: searchRulesParams,
|
|
2542
|
+
data: searchRulesParams ? searchRulesParams : {},
|
|
2421
2543
|
useReadTransporter: true,
|
|
2422
2544
|
cacheable: true,
|
|
2423
2545
|
};
|