@algolia/client-search 5.0.0-alpha.91 → 5.0.0-alpha.98

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.
@@ -66,14 +66,35 @@ function createBrowserLocalStorageCache(options) {
66
66
  function getNamespace() {
67
67
  return JSON.parse(getStorage().getItem(namespaceKey) || '{}');
68
68
  }
69
+ function setNamespace(namespace) {
70
+ getStorage().setItem(namespaceKey, JSON.stringify(namespace));
71
+ }
72
+ function removeOutdatedCacheItems() {
73
+ const timeToLive = options.timeToLive ? options.timeToLive * 1000 : null;
74
+ const namespace = getNamespace();
75
+ const filteredNamespaceWithoutOldFormattedCacheItems = Object.fromEntries(Object.entries(namespace).filter(([, cacheItem]) => {
76
+ return cacheItem.timestamp !== undefined;
77
+ }));
78
+ setNamespace(filteredNamespaceWithoutOldFormattedCacheItems);
79
+ if (!timeToLive) {
80
+ return;
81
+ }
82
+ const filteredNamespaceWithoutExpiredItems = Object.fromEntries(Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(([, cacheItem]) => {
83
+ const currentTimestamp = new Date().getTime();
84
+ const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;
85
+ return !isExpired;
86
+ }));
87
+ setNamespace(filteredNamespaceWithoutExpiredItems);
88
+ }
69
89
  return {
70
90
  get(key, defaultValue, events = {
71
91
  miss: () => Promise.resolve()
72
92
  }) {
73
93
  return Promise.resolve().then(() => {
74
- const keyAsString = JSON.stringify(key);
75
- const value = getNamespace()[keyAsString];
76
- return Promise.all([value || defaultValue(), value !== undefined]);
94
+ removeOutdatedCacheItems();
95
+ return getNamespace()[JSON.stringify(key)];
96
+ }).then(value => {
97
+ return Promise.all([value ? value.value : defaultValue(), value !== undefined]);
77
98
  }).then(([value, exists]) => {
78
99
  return Promise.all([value, exists || events.miss(value)]);
79
100
  }).then(([value]) => value);
@@ -81,7 +102,10 @@ function createBrowserLocalStorageCache(options) {
81
102
  set(key, value) {
82
103
  return Promise.resolve().then(() => {
83
104
  const namespace = getNamespace();
84
- namespace[JSON.stringify(key)] = value;
105
+ namespace[JSON.stringify(key)] = {
106
+ timestamp: new Date().getTime(),
107
+ value
108
+ };
85
109
  getStorage().setItem(namespaceKey, JSON.stringify(namespace));
86
110
  return value;
87
111
  });
@@ -211,6 +235,20 @@ function createStatefulHost(host, status = 'up') {
211
235
  };
212
236
  }
213
237
 
238
+ function _toPrimitive(t, r) {
239
+ if ("object" != typeof t || !t) return t;
240
+ var e = t[Symbol.toPrimitive];
241
+ if (void 0 !== e) {
242
+ var i = e.call(t, r || "default");
243
+ if ("object" != typeof i) return i;
244
+ throw new TypeError("@@toPrimitive must return a primitive value.");
245
+ }
246
+ return ("string" === r ? String : Number)(t);
247
+ }
248
+ function _toPropertyKey(t) {
249
+ var i = _toPrimitive(t, "string");
250
+ return "symbol" == typeof i ? i : String(i);
251
+ }
214
252
  function _defineProperty(obj, key, value) {
215
253
  key = _toPropertyKey(key);
216
254
  if (key in obj) {
@@ -225,20 +263,6 @@ function _defineProperty(obj, key, value) {
225
263
  }
226
264
  return obj;
227
265
  }
228
- function _toPrimitive(input, hint) {
229
- if (typeof input !== "object" || input === null) return input;
230
- var prim = input[Symbol.toPrimitive];
231
- if (prim !== undefined) {
232
- var res = prim.call(input, hint || "default");
233
- if (typeof res !== "object") return res;
234
- throw new TypeError("@@toPrimitive must return a primitive value.");
235
- }
236
- return (hint === "string" ? String : Number)(input);
237
- }
238
- function _toPropertyKey(arg) {
239
- var key = _toPrimitive(arg, "string");
240
- return typeof key === "symbol" ? key : String(key);
241
- }
242
266
 
243
267
  class AlgoliaError extends Error {
244
268
  constructor(message, name) {
@@ -259,7 +283,7 @@ class ErrorWithStackTrace extends AlgoliaError {
259
283
  }
260
284
  class RetryError extends ErrorWithStackTrace {
261
285
  constructor(stackTrace) {
262
- super('Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.', stackTrace, 'RetryError');
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');
263
287
  }
264
288
  }
265
289
  class ApiError extends ErrorWithStackTrace {
@@ -713,7 +737,7 @@ function createXhrRequester() {
713
737
  }
714
738
 
715
739
  // 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.
716
- const apiClientVersion = '5.0.0-alpha.91';
740
+ const apiClientVersion = '5.0.0-alpha.98';
717
741
  function getDefaultHosts(appId) {
718
742
  return [
719
743
  {
@@ -938,21 +962,25 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
938
962
  * @param browseObjects.indexName - The index in which to perform the request.
939
963
  * @param browseObjects.validate - The validator function. It receive the resolved return of the API call. By default, stops when there is less hits returned than the number of maximum hits (1000).
940
964
  * @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`.
965
+ * @param browseObjects.searchSynonymsParams - The `searchSynonyms` method parameters.
941
966
  * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `searchSynonyms` method and merged with the transporter requestOptions.
942
967
  */
943
- browseSynonyms({ indexName, validate, aggregator, ...browseSynonymsOptions }, requestOptions) {
968
+ browseSynonyms({ indexName, searchSynonymsParams, ...browseSynonymsOptions }, requestOptions) {
944
969
  const params = {
970
+ page: 0,
971
+ ...searchSynonymsParams,
945
972
  hitsPerPage: 1000,
946
- ...browseSynonymsOptions,
947
973
  };
948
974
  return createIterablePromise({
949
975
  func: (previousResponse) => {
950
976
  return this.searchSynonyms({
951
- ...params,
952
977
  indexName,
953
- page: previousResponse
954
- ? previousResponse.page + 1
955
- : browseSynonymsOptions.page || 0,
978
+ searchSynonymsParams: {
979
+ ...params,
980
+ page: previousResponse
981
+ ? previousResponse.page + 1
982
+ : params.page,
983
+ },
956
984
  }, requestOptions);
957
985
  },
958
986
  validate: (response) => response.nbHits < params.hitsPerPage,
@@ -1226,24 +1254,20 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1226
1254
  return transporter.request(request, requestOptions);
1227
1255
  },
1228
1256
  /**
1229
- * Delete all synonyms in the index.
1257
+ * Delete the records but leave settings and index-specific API keys untouched.
1230
1258
  *
1231
- * @summary Delete all synonyms.
1232
- * @param clearAllSynonyms - The clearAllSynonyms object.
1233
- * @param clearAllSynonyms.indexName - Index on which to perform the request.
1234
- * @param clearAllSynonyms.forwardToReplicas - Indicates whether changed index settings are forwarded to the replica indices.
1259
+ * @summary Delete all records from an index.
1260
+ * @param clearObjects - The clearObjects object.
1261
+ * @param clearObjects.indexName - Index on which to perform the request.
1235
1262
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1236
1263
  */
1237
- clearAllSynonyms({ indexName, forwardToReplicas }, requestOptions) {
1264
+ clearObjects({ indexName }, requestOptions) {
1238
1265
  if (!indexName) {
1239
- throw new Error('Parameter `indexName` is required when calling `clearAllSynonyms`.');
1266
+ throw new Error('Parameter `indexName` is required when calling `clearObjects`.');
1240
1267
  }
1241
- const requestPath = '/1/indexes/{indexName}/synonyms/clear'.replace('{indexName}', encodeURIComponent(indexName));
1268
+ const requestPath = '/1/indexes/{indexName}/clear'.replace('{indexName}', encodeURIComponent(indexName));
1242
1269
  const headers = {};
1243
1270
  const queryParameters = {};
1244
- if (forwardToReplicas !== undefined) {
1245
- queryParameters.forwardToReplicas = forwardToReplicas.toString();
1246
- }
1247
1271
  const request = {
1248
1272
  method: 'POST',
1249
1273
  path: requestPath,
@@ -1253,20 +1277,24 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1253
1277
  return transporter.request(request, requestOptions);
1254
1278
  },
1255
1279
  /**
1256
- * Delete the records but leave settings and index-specific API keys untouched.
1280
+ * Delete all rules in the index.
1257
1281
  *
1258
- * @summary Delete all records from an index.
1259
- * @param clearObjects - The clearObjects object.
1260
- * @param clearObjects.indexName - Index on which to perform the request.
1282
+ * @summary Delete all rules.
1283
+ * @param clearRules - The clearRules object.
1284
+ * @param clearRules.indexName - Index on which to perform the request.
1285
+ * @param clearRules.forwardToReplicas - Indicates whether changed index settings are forwarded to the replica indices.
1261
1286
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1262
1287
  */
1263
- clearObjects({ indexName }, requestOptions) {
1288
+ clearRules({ indexName, forwardToReplicas }, requestOptions) {
1264
1289
  if (!indexName) {
1265
- throw new Error('Parameter `indexName` is required when calling `clearObjects`.');
1290
+ throw new Error('Parameter `indexName` is required when calling `clearRules`.');
1266
1291
  }
1267
- const requestPath = '/1/indexes/{indexName}/clear'.replace('{indexName}', encodeURIComponent(indexName));
1292
+ const requestPath = '/1/indexes/{indexName}/rules/clear'.replace('{indexName}', encodeURIComponent(indexName));
1268
1293
  const headers = {};
1269
1294
  const queryParameters = {};
1295
+ if (forwardToReplicas !== undefined) {
1296
+ queryParameters.forwardToReplicas = forwardToReplicas.toString();
1297
+ }
1270
1298
  const request = {
1271
1299
  method: 'POST',
1272
1300
  path: requestPath,
@@ -1276,19 +1304,19 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1276
1304
  return transporter.request(request, requestOptions);
1277
1305
  },
1278
1306
  /**
1279
- * Delete all rules in the index.
1307
+ * Delete all synonyms in the index.
1280
1308
  *
1281
- * @summary Delete all rules.
1282
- * @param clearRules - The clearRules object.
1283
- * @param clearRules.indexName - Index on which to perform the request.
1284
- * @param clearRules.forwardToReplicas - Indicates whether changed index settings are forwarded to the replica indices.
1309
+ * @summary Delete all synonyms.
1310
+ * @param clearSynonyms - The clearSynonyms object.
1311
+ * @param clearSynonyms.indexName - Index on which to perform the request.
1312
+ * @param clearSynonyms.forwardToReplicas - Indicates whether changed index settings are forwarded to the replica indices.
1285
1313
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1286
1314
  */
1287
- clearRules({ indexName, forwardToReplicas }, requestOptions) {
1315
+ clearSynonyms({ indexName, forwardToReplicas }, requestOptions) {
1288
1316
  if (!indexName) {
1289
- throw new Error('Parameter `indexName` is required when calling `clearRules`.');
1317
+ throw new Error('Parameter `indexName` is required when calling `clearSynonyms`.');
1290
1318
  }
1291
- const requestPath = '/1/indexes/{indexName}/rules/clear'.replace('{indexName}', encodeURIComponent(indexName));
1319
+ const requestPath = '/1/indexes/{indexName}/synonyms/clear'.replace('{indexName}', encodeURIComponent(indexName));
1292
1320
  const headers = {};
1293
1321
  const queryParameters = {};
1294
1322
  if (forwardToReplicas !== undefined) {
@@ -1306,14 +1334,14 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1306
1334
  * This method allow you to send requests to the Algolia REST API.
1307
1335
  *
1308
1336
  * @summary Send requests to the Algolia REST API.
1309
- * @param del - The del object.
1310
- * @param del.path - Path of the endpoint, anything after \"/1\" must be specified.
1311
- * @param del.parameters - Query parameters to apply to the current query.
1337
+ * @param customDelete - The customDelete object.
1338
+ * @param customDelete.path - Path of the endpoint, anything after \"/1\" must be specified.
1339
+ * @param customDelete.parameters - Query parameters to apply to the current query.
1312
1340
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1313
1341
  */
1314
- del({ path, parameters }, requestOptions) {
1342
+ customDelete({ path, parameters }, requestOptions) {
1315
1343
  if (!path) {
1316
- throw new Error('Parameter `path` is required when calling `del`.');
1344
+ throw new Error('Parameter `path` is required when calling `customDelete`.');
1317
1345
  }
1318
1346
  const requestPath = '/1{path}'.replace('{path}', path);
1319
1347
  const headers = {};
@@ -1326,6 +1354,82 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1326
1354
  };
1327
1355
  return transporter.request(request, requestOptions);
1328
1356
  },
1357
+ /**
1358
+ * This method allow you to send requests to the Algolia REST API.
1359
+ *
1360
+ * @summary Send requests to the Algolia REST API.
1361
+ * @param customGet - The customGet object.
1362
+ * @param customGet.path - Path of the endpoint, anything after \"/1\" must be specified.
1363
+ * @param customGet.parameters - Query parameters to apply to the current query.
1364
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1365
+ */
1366
+ customGet({ path, parameters }, requestOptions) {
1367
+ if (!path) {
1368
+ throw new Error('Parameter `path` is required when calling `customGet`.');
1369
+ }
1370
+ const requestPath = '/1{path}'.replace('{path}', path);
1371
+ const headers = {};
1372
+ const queryParameters = parameters ? parameters : {};
1373
+ const request = {
1374
+ method: 'GET',
1375
+ path: requestPath,
1376
+ queryParameters,
1377
+ headers,
1378
+ };
1379
+ return transporter.request(request, requestOptions);
1380
+ },
1381
+ /**
1382
+ * This method allow you to send requests to the Algolia REST API.
1383
+ *
1384
+ * @summary Send requests to the Algolia REST API.
1385
+ * @param customPost - The customPost object.
1386
+ * @param customPost.path - Path of the endpoint, anything after \"/1\" must be specified.
1387
+ * @param customPost.parameters - Query parameters to apply to the current query.
1388
+ * @param customPost.body - Parameters to send with the custom request.
1389
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1390
+ */
1391
+ customPost({ path, parameters, body }, requestOptions) {
1392
+ if (!path) {
1393
+ throw new Error('Parameter `path` is required when calling `customPost`.');
1394
+ }
1395
+ const requestPath = '/1{path}'.replace('{path}', path);
1396
+ const headers = {};
1397
+ const queryParameters = parameters ? parameters : {};
1398
+ const request = {
1399
+ method: 'POST',
1400
+ path: requestPath,
1401
+ queryParameters,
1402
+ headers,
1403
+ data: body ? body : {},
1404
+ };
1405
+ return transporter.request(request, requestOptions);
1406
+ },
1407
+ /**
1408
+ * This method allow you to send requests to the Algolia REST API.
1409
+ *
1410
+ * @summary Send requests to the Algolia REST API.
1411
+ * @param customPut - The customPut object.
1412
+ * @param customPut.path - Path of the endpoint, anything after \"/1\" must be specified.
1413
+ * @param customPut.parameters - Query parameters to apply to the current query.
1414
+ * @param customPut.body - Parameters to send with the custom request.
1415
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1416
+ */
1417
+ customPut({ path, parameters, body }, requestOptions) {
1418
+ if (!path) {
1419
+ throw new Error('Parameter `path` is required when calling `customPut`.');
1420
+ }
1421
+ const requestPath = '/1{path}'.replace('{path}', path);
1422
+ const headers = {};
1423
+ const queryParameters = parameters ? parameters : {};
1424
+ const request = {
1425
+ method: 'PUT',
1426
+ path: requestPath,
1427
+ queryParameters,
1428
+ headers,
1429
+ data: body ? body : {},
1430
+ };
1431
+ return transporter.request(request, requestOptions);
1432
+ },
1329
1433
  /**
1330
1434
  * Delete an existing API key. The request must be authenticated with the admin API key.
1331
1435
  *
@@ -1518,30 +1622,6 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
1518
1622
  };
1519
1623
  return transporter.request(request, requestOptions);
1520
1624
  },
1521
- /**
1522
- * This method allow you to send requests to the Algolia REST API.
1523
- *
1524
- * @summary Send requests to the Algolia REST API.
1525
- * @param get - The get object.
1526
- * @param get.path - Path of the endpoint, anything after \"/1\" must be specified.
1527
- * @param get.parameters - Query parameters to apply to the current query.
1528
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1529
- */
1530
- get({ path, parameters }, requestOptions) {
1531
- if (!path) {
1532
- throw new Error('Parameter `path` is required when calling `get`.');
1533
- }
1534
- const requestPath = '/1{path}'.replace('{path}', path);
1535
- const headers = {};
1536
- const queryParameters = parameters ? parameters : {};
1537
- const request = {
1538
- method: 'GET',
1539
- path: requestPath,
1540
- queryParameters,
1541
- headers,
1542
- };
1543
- return transporter.request(request, requestOptions);
1544
- },
1545
1625
  /**
1546
1626
  * Get the permissions and restrictions of a specific API key. When authenticating with the admin API key, you can request information for any of your application\'s keys. When authenticating with other API keys, you can only retrieve information for that key.
1547
1627
  *
@@ -2077,58 +2157,6 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2077
2157
  };
2078
2158
  return transporter.request(request, requestOptions);
2079
2159
  },
2080
- /**
2081
- * This method allow you to send requests to the Algolia REST API.
2082
- *
2083
- * @summary Send requests to the Algolia REST API.
2084
- * @param post - The post object.
2085
- * @param post.path - Path of the endpoint, anything after \"/1\" must be specified.
2086
- * @param post.parameters - Query parameters to apply to the current query.
2087
- * @param post.body - Parameters to send with the custom request.
2088
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
2089
- */
2090
- post({ path, parameters, body }, requestOptions) {
2091
- if (!path) {
2092
- throw new Error('Parameter `path` is required when calling `post`.');
2093
- }
2094
- const requestPath = '/1{path}'.replace('{path}', path);
2095
- const headers = {};
2096
- const queryParameters = parameters ? parameters : {};
2097
- const request = {
2098
- method: 'POST',
2099
- path: requestPath,
2100
- queryParameters,
2101
- headers,
2102
- data: body ? body : {},
2103
- };
2104
- return transporter.request(request, requestOptions);
2105
- },
2106
- /**
2107
- * This method allow you to send requests to the Algolia REST API.
2108
- *
2109
- * @summary Send requests to the Algolia REST API.
2110
- * @param put - The put object.
2111
- * @param put.path - Path of the endpoint, anything after \"/1\" must be specified.
2112
- * @param put.parameters - Query parameters to apply to the current query.
2113
- * @param put.body - Parameters to send with the custom request.
2114
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
2115
- */
2116
- put({ path, parameters, body }, requestOptions) {
2117
- if (!path) {
2118
- throw new Error('Parameter `path` is required when calling `put`.');
2119
- }
2120
- const requestPath = '/1{path}'.replace('{path}', path);
2121
- const headers = {};
2122
- const queryParameters = parameters ? parameters : {};
2123
- const request = {
2124
- method: 'PUT',
2125
- path: requestPath,
2126
- queryParameters,
2127
- headers,
2128
- data: body ? body : {},
2129
- };
2130
- return transporter.request(request, requestOptions);
2131
- },
2132
2160
  /**
2133
2161
  * Remove a userID and its associated data from the multi-clusters.
2134
2162
  *
@@ -2561,28 +2589,16 @@ function createSearchClient({ appId: appIdOption, apiKey: apiKeyOption, authMode
2561
2589
  * @summary Search for synonyms.
2562
2590
  * @param searchSynonyms - The searchSynonyms object.
2563
2591
  * @param searchSynonyms.indexName - Index on which to perform the request.
2564
- * @param searchSynonyms.type - Search for specific [types of synonyms](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/adding-synonyms/#the-different-types-of-synonyms).
2565
- * @param searchSynonyms.page - Returns the requested page number (the first page is 0). Page size is set by `hitsPerPage`. When null, there\'s no pagination.
2566
- * @param searchSynonyms.hitsPerPage - Maximum number of hits per page.
2567
2592
  * @param searchSynonyms.searchSynonymsParams - Body of the `searchSynonyms` operation.
2568
2593
  * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
2569
2594
  */
2570
- searchSynonyms({ indexName, type, page, hitsPerPage, searchSynonymsParams, }, requestOptions) {
2595
+ searchSynonyms({ indexName, searchSynonymsParams }, requestOptions) {
2571
2596
  if (!indexName) {
2572
2597
  throw new Error('Parameter `indexName` is required when calling `searchSynonyms`.');
2573
2598
  }
2574
2599
  const requestPath = '/1/indexes/{indexName}/synonyms/search'.replace('{indexName}', encodeURIComponent(indexName));
2575
2600
  const headers = {};
2576
2601
  const queryParameters = {};
2577
- if (type !== undefined) {
2578
- queryParameters.type = type.toString();
2579
- }
2580
- if (page !== undefined) {
2581
- queryParameters.page = page.toString();
2582
- }
2583
- if (hitsPerPage !== undefined) {
2584
- queryParameters.hitsPerPage = hitsPerPage.toString();
2585
- }
2586
2602
  const request = {
2587
2603
  method: 'POST',
2588
2604
  path: requestPath,