@algolia/client-query-suggestions 5.0.0-alpha.10 → 5.0.0-alpha.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/builds/browser.d.ts +5 -5
  2. package/dist/builds/browser.d.ts.map +1 -1
  3. package/dist/builds/node.d.ts +5 -5
  4. package/dist/builds/node.d.ts.map +1 -1
  5. package/dist/{client-query-suggestions.cjs.js → client-query-suggestions.cjs} +361 -353
  6. package/dist/client-query-suggestions.esm.browser.js +573 -589
  7. package/dist/client-query-suggestions.esm.node.js +361 -351
  8. package/dist/client-query-suggestions.umd.js +2 -2
  9. package/dist/model/baseQuerySuggestionsConfigurationResponse.d.ts +15 -0
  10. package/dist/model/baseQuerySuggestionsConfigurationResponse.d.ts.map +1 -0
  11. package/dist/model/baseQuerySuggestionsConfigurationWithIndex.d.ts +7 -0
  12. package/dist/model/baseQuerySuggestionsConfigurationWithIndex.d.ts.map +1 -0
  13. package/dist/model/baseResponse.d.ts +11 -0
  14. package/dist/model/baseResponse.d.ts.map +1 -0
  15. package/dist/model/clientMethodProps.d.ts +107 -107
  16. package/dist/model/clientMethodProps.d.ts.map +1 -1
  17. package/dist/model/errorBase.d.ts +6 -6
  18. package/dist/model/errorBase.d.ts.map +1 -1
  19. package/dist/model/facet.d.ts +14 -0
  20. package/dist/model/facet.d.ts.map +1 -0
  21. package/dist/model/getConfigStatus200Response.d.ts +23 -0
  22. package/dist/model/getConfigStatus200Response.d.ts.map +1 -0
  23. package/dist/model/getLogFile200Response.d.ts +17 -0
  24. package/dist/model/getLogFile200Response.d.ts.map +1 -0
  25. package/dist/model/index.d.ts +14 -13
  26. package/dist/model/index.d.ts.map +1 -1
  27. package/dist/model/languages.d.ts +5 -0
  28. package/dist/model/languages.d.ts.map +1 -0
  29. package/dist/model/logLevel.d.ts +4 -4
  30. package/dist/model/logLevel.d.ts.map +1 -1
  31. package/dist/model/querySuggestionsConfiguration.d.ts +25 -0
  32. package/dist/model/querySuggestionsConfiguration.d.ts.map +1 -0
  33. package/dist/model/querySuggestionsConfigurationResponse.d.ts +4 -0
  34. package/dist/model/querySuggestionsConfigurationResponse.d.ts.map +1 -0
  35. package/dist/model/querySuggestionsConfigurationWithIndex.d.ts +7 -0
  36. package/dist/model/querySuggestionsConfigurationWithIndex.d.ts.map +1 -0
  37. package/dist/model/sourceIndex.d.ts +35 -31
  38. package/dist/model/sourceIndex.d.ts.map +1 -1
  39. package/dist/src/querySuggestionsClient.d.ts +151 -141
  40. package/dist/src/querySuggestionsClient.d.ts.map +1 -1
  41. package/index.js +1 -1
  42. package/model/baseQuerySuggestionsConfigurationResponse.ts +18 -0
  43. package/model/baseQuerySuggestionsConfigurationWithIndex.ts +8 -0
  44. package/model/baseResponse.ts +13 -0
  45. package/model/clientMethodProps.ts +50 -50
  46. package/model/errorBase.ts +1 -1
  47. package/model/facet.ts +16 -0
  48. package/model/getConfigStatus200Response.ts +28 -0
  49. package/model/getLogFile200Response.ts +22 -0
  50. package/model/index.ts +11 -10
  51. package/model/languages.ts +6 -0
  52. package/model/logLevel.ts +2 -2
  53. package/model/querySuggestionsConfiguration.ts +31 -0
  54. package/model/querySuggestionsConfigurationResponse.ts +8 -0
  55. package/model/querySuggestionsConfigurationWithIndex.ts +10 -0
  56. package/model/sourceIndex.ts +19 -14
  57. package/package.json +30 -13
  58. package/dist/model/indexName.d.ts +0 -7
  59. package/dist/model/indexName.d.ts.map +0 -1
  60. package/dist/model/logFile.d.ts +0 -17
  61. package/dist/model/logFile.d.ts.map +0 -1
  62. package/dist/model/querySuggestionsIndex.d.ts +0 -20
  63. package/dist/model/querySuggestionsIndex.d.ts.map +0 -1
  64. package/dist/model/querySuggestionsIndexParam.d.ts +0 -16
  65. package/dist/model/querySuggestionsIndexParam.d.ts.map +0 -1
  66. package/dist/model/querySuggestionsIndexWithIndexParam.d.ts +0 -4
  67. package/dist/model/querySuggestionsIndexWithIndexParam.d.ts.map +0 -1
  68. package/dist/model/sourceIndexExternal.d.ts +0 -11
  69. package/dist/model/sourceIndexExternal.d.ts.map +0 -1
  70. package/dist/model/sourceIndexWithReplicas.d.ts +0 -39
  71. package/dist/model/sourceIndexWithReplicas.d.ts.map +0 -1
  72. package/dist/model/status.d.ts +0 -15
  73. package/dist/model/status.d.ts.map +0 -1
  74. package/dist/model/successResponse.d.ts +0 -11
  75. package/dist/model/successResponse.d.ts.map +0 -1
  76. package/model/indexName.ts +0 -8
  77. package/model/logFile.ts +0 -22
  78. package/model/querySuggestionsIndex.ts +0 -25
  79. package/model/querySuggestionsIndexParam.ts +0 -20
  80. package/model/querySuggestionsIndexWithIndexParam.ts +0 -7
  81. package/model/sourceIndexExternal.ts +0 -13
  82. package/model/sourceIndexWithReplicas.ts +0 -48
  83. package/model/status.ts +0 -18
  84. package/model/successResponse.ts +0 -13
@@ -7,53 +7,69 @@ function createAuth(appId, apiKey, authMode = 'WithinHeaders') {
7
7
  headers() {
8
8
  return authMode === 'WithinHeaders' ? credentials : {};
9
9
  },
10
-
11
10
  queryParameters() {
12
11
  return authMode === 'WithinQueryParameters' ? credentials : {};
13
12
  }
14
-
15
13
  };
16
14
  }
17
15
 
18
16
  function createBrowserLocalStorageCache(options) {
19
- let storage; // We've changed the namespace to avoid conflicts with v4, as this version is a huge breaking change
20
-
17
+ let storage;
18
+ // We've changed the namespace to avoid conflicts with v4, as this version is a huge breaking change
21
19
  const namespaceKey = `algolia-client-js-${options.key}`;
22
-
23
20
  function getStorage() {
24
21
  if (storage === undefined) {
25
22
  storage = options.localStorage || window.localStorage;
26
23
  }
27
-
28
24
  return storage;
29
25
  }
30
-
31
26
  function getNamespace() {
32
27
  return JSON.parse(getStorage().getItem(namespaceKey) || '{}');
33
28
  }
34
-
29
+ function setNamespace(namespace) {
30
+ getStorage().setItem(namespaceKey, JSON.stringify(namespace));
31
+ }
32
+ function removeOutdatedCacheItems() {
33
+ const timeToLive = options.timeToLive ? options.timeToLive * 1000 : null;
34
+ const namespace = getNamespace();
35
+ const filteredNamespaceWithoutOldFormattedCacheItems = Object.fromEntries(Object.entries(namespace).filter(([, cacheItem]) => {
36
+ return cacheItem.timestamp !== undefined;
37
+ }));
38
+ setNamespace(filteredNamespaceWithoutOldFormattedCacheItems);
39
+ if (!timeToLive) {
40
+ return;
41
+ }
42
+ const filteredNamespaceWithoutExpiredItems = Object.fromEntries(Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(([, cacheItem]) => {
43
+ const currentTimestamp = new Date().getTime();
44
+ const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;
45
+ return !isExpired;
46
+ }));
47
+ setNamespace(filteredNamespaceWithoutExpiredItems);
48
+ }
35
49
  return {
36
50
  get(key, defaultValue, events = {
37
51
  miss: () => Promise.resolve()
38
52
  }) {
39
53
  return Promise.resolve().then(() => {
40
- const keyAsString = JSON.stringify(key);
41
- const value = getNamespace()[keyAsString];
42
- return Promise.all([value || defaultValue(), value !== undefined]);
54
+ removeOutdatedCacheItems();
55
+ return getNamespace()[JSON.stringify(key)];
56
+ }).then(value => {
57
+ return Promise.all([value ? value.value : defaultValue(), value !== undefined]);
43
58
  }).then(([value, exists]) => {
44
59
  return Promise.all([value, exists || events.miss(value)]);
45
60
  }).then(([value]) => value);
46
61
  },
47
-
48
62
  set(key, value) {
49
63
  return Promise.resolve().then(() => {
50
64
  const namespace = getNamespace();
51
- namespace[JSON.stringify(key)] = value;
65
+ namespace[JSON.stringify(key)] = {
66
+ timestamp: new Date().getTime(),
67
+ value
68
+ };
52
69
  getStorage().setItem(namespaceKey, JSON.stringify(namespace));
53
70
  return value;
54
71
  });
55
72
  },
56
-
57
73
  delete(key) {
58
74
  return Promise.resolve().then(() => {
59
75
  const namespace = getNamespace();
@@ -61,13 +77,11 @@ function createBrowserLocalStorageCache(options) {
61
77
  getStorage().setItem(namespaceKey, JSON.stringify(namespace));
62
78
  });
63
79
  },
64
-
65
80
  clear() {
66
81
  return Promise.resolve().then(() => {
67
82
  getStorage().removeItem(namespaceKey);
68
83
  });
69
84
  }
70
-
71
85
  };
72
86
  }
73
87
 
@@ -79,30 +93,24 @@ function createNullCache() {
79
93
  const value = defaultValue();
80
94
  return value.then(result => Promise.all([result, events.miss(result)])).then(([result]) => result);
81
95
  },
82
-
83
96
  set(_key, value) {
84
97
  return Promise.resolve(value);
85
98
  },
86
-
87
99
  delete(_key) {
88
100
  return Promise.resolve();
89
101
  },
90
-
91
102
  clear() {
92
103
  return Promise.resolve();
93
104
  }
94
-
95
105
  };
96
106
  }
97
107
 
98
108
  function createFallbackableCache(options) {
99
109
  const caches = [...options.caches];
100
110
  const current = caches.shift();
101
-
102
111
  if (current === undefined) {
103
112
  return createNullCache();
104
113
  }
105
-
106
114
  return {
107
115
  get(key, defaultValue, events = {
108
116
  miss: () => Promise.resolve()
@@ -113,7 +121,6 @@ function createFallbackableCache(options) {
113
121
  }).get(key, defaultValue, events);
114
122
  });
115
123
  },
116
-
117
124
  set(key, value) {
118
125
  return current.set(key, value).catch(() => {
119
126
  return createFallbackableCache({
@@ -121,7 +128,6 @@ function createFallbackableCache(options) {
121
128
  }).set(key, value);
122
129
  });
123
130
  },
124
-
125
131
  delete(key) {
126
132
  return current.delete(key).catch(() => {
127
133
  return createFallbackableCache({
@@ -129,7 +135,6 @@ function createFallbackableCache(options) {
129
135
  }).delete(key);
130
136
  });
131
137
  },
132
-
133
138
  clear() {
134
139
  return current.clear().catch(() => {
135
140
  return createFallbackableCache({
@@ -137,7 +142,6 @@ function createFallbackableCache(options) {
137
142
  }).clear();
138
143
  });
139
144
  }
140
-
141
145
  };
142
146
  }
143
147
 
@@ -150,30 +154,24 @@ function createMemoryCache(options = {
150
154
  miss: () => Promise.resolve()
151
155
  }) {
152
156
  const keyAsString = JSON.stringify(key);
153
-
154
157
  if (keyAsString in cache) {
155
158
  return Promise.resolve(options.serializable ? JSON.parse(cache[keyAsString]) : cache[keyAsString]);
156
159
  }
157
-
158
160
  const promise = defaultValue();
159
161
  return promise.then(value => events.miss(value)).then(() => promise);
160
162
  },
161
-
162
163
  set(key, value) {
163
164
  cache[JSON.stringify(key)] = options.serializable ? JSON.stringify(value) : value;
164
165
  return Promise.resolve(value);
165
166
  },
166
-
167
167
  delete(key) {
168
168
  delete cache[JSON.stringify(key)];
169
169
  return Promise.resolve();
170
170
  },
171
-
172
171
  clear() {
173
172
  cache = {};
174
173
  return Promise.resolve();
175
174
  }
176
-
177
175
  };
178
176
  }
179
177
 
@@ -182,16 +180,14 @@ function createMemoryCache(options = {
182
180
  const EXPIRATION_DELAY = 2 * 60 * 1000;
183
181
  function createStatefulHost(host, status = 'up') {
184
182
  const lastUpdate = Date.now();
185
-
186
183
  function isUp() {
187
184
  return status === 'up' || Date.now() - lastUpdate > EXPIRATION_DELAY;
188
185
  }
189
-
190
186
  function isTimedOut() {
191
187
  return status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY;
192
188
  }
193
-
194
- return { ...host,
189
+ return {
190
+ ...host,
195
191
  status,
196
192
  lastUpdate,
197
193
  isUp,
@@ -199,7 +195,22 @@ function createStatefulHost(host, status = 'up') {
199
195
  };
200
196
  }
201
197
 
198
+ function _toPrimitive(t, r) {
199
+ if ("object" != typeof t || !t) return t;
200
+ var e = t[Symbol.toPrimitive];
201
+ if (void 0 !== e) {
202
+ var i = e.call(t, r || "default");
203
+ if ("object" != typeof i) return i;
204
+ throw new TypeError("@@toPrimitive must return a primitive value.");
205
+ }
206
+ return ("string" === r ? String : Number)(t);
207
+ }
208
+ function _toPropertyKey(t) {
209
+ var i = _toPrimitive(t, "string");
210
+ return "symbol" == typeof i ? i : String(i);
211
+ }
202
212
  function _defineProperty(obj, key, value) {
213
+ key = _toPropertyKey(key);
203
214
  if (key in obj) {
204
215
  Object.defineProperty(obj, key, {
205
216
  value: value,
@@ -210,79 +221,71 @@ function _defineProperty(obj, key, value) {
210
221
  } else {
211
222
  obj[key] = value;
212
223
  }
213
-
214
224
  return obj;
215
225
  }
216
226
 
217
227
  class AlgoliaError extends Error {
218
228
  constructor(message, name) {
219
229
  super(message);
220
-
221
230
  _defineProperty(this, "name", 'AlgoliaError');
222
-
223
231
  if (name) {
224
232
  this.name = name;
225
233
  }
226
234
  }
227
-
228
235
  }
229
236
  class ErrorWithStackTrace extends AlgoliaError {
230
237
  constructor(message, stackTrace, name) {
231
- super(message, name); // the array and object should be frozen to reflect the stackTrace at the time of the error
232
-
238
+ super(message, name);
239
+ // the array and object should be frozen to reflect the stackTrace at the time of the error
233
240
  _defineProperty(this, "stackTrace", void 0);
234
-
235
241
  this.stackTrace = stackTrace;
236
242
  }
237
-
238
243
  }
239
244
  class RetryError extends ErrorWithStackTrace {
240
245
  constructor(stackTrace) {
241
- super('Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.', stackTrace, 'RetryError');
246
+ 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');
242
247
  }
243
-
244
248
  }
245
249
  class ApiError extends ErrorWithStackTrace {
246
- constructor(message, status, stackTrace) {
247
- super(message, stackTrace, 'ApiError');
248
-
250
+ constructor(message, status, stackTrace, name = 'ApiError') {
251
+ super(message, stackTrace, name);
249
252
  _defineProperty(this, "status", void 0);
250
-
251
253
  this.status = status;
252
254
  }
253
-
254
255
  }
255
256
  class DeserializationError extends AlgoliaError {
256
257
  constructor(message, response) {
257
258
  super(message, 'DeserializationError');
258
-
259
259
  _defineProperty(this, "response", void 0);
260
-
261
260
  this.response = response;
262
261
  }
263
-
262
+ }
263
+ // DetailedApiError is only used by the ingestion client to return more informative error, other clients will use ApiClient.
264
+ class DetailedApiError extends ApiError {
265
+ constructor(message, status, error, stackTrace) {
266
+ super(message, status, stackTrace, 'DetailedApiError');
267
+ _defineProperty(this, "error", void 0);
268
+ this.error = error;
269
+ }
264
270
  }
265
271
  function serializeUrl(host, path, queryParameters) {
266
272
  const queryParametersAsString = serializeQueryParameters(queryParameters);
267
- let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`;
268
-
273
+ let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${path.charAt(0) === '/' ? path.substr(1) : path}`;
269
274
  if (queryParametersAsString.length) {
270
275
  url += `?${queryParametersAsString}`;
271
276
  }
272
-
273
277
  return url;
274
278
  }
275
279
  function serializeQueryParameters(parameters) {
276
280
  const isObjectOrArray = value => Object.prototype.toString.call(value) === '[object Object]' || Object.prototype.toString.call(value) === '[object Array]';
277
-
278
- return Object.keys(parameters).map(key => `${key}=${isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]}`).join('&');
281
+ return Object.keys(parameters).map(key => `${key}=${encodeURIComponent(isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]).replaceAll('+', '%20')}`).join('&');
279
282
  }
280
283
  function serializeData(request, requestOptions) {
281
284
  if (request.method === 'GET' || request.data === undefined && requestOptions.data === undefined) {
282
285
  return undefined;
283
286
  }
284
-
285
- const data = Array.isArray(request.data) ? request.data : { ...request.data,
287
+ const data = Array.isArray(request.data) ? request.data : {
288
+ ...request.data,
286
289
  ...requestOptions.data
287
290
  };
288
291
  return JSON.stringify(data);
@@ -312,14 +315,16 @@ function deserializeFailure({
312
315
  content,
313
316
  status
314
317
  }, stackFrame) {
315
- let message = content;
316
-
317
318
  try {
318
- message = JSON.parse(content).message;
319
- } catch (e) {// ..
319
+ const parsed = JSON.parse(content);
320
+ if ('error' in parsed) {
321
+ return new DetailedApiError(parsed.message, status, parsed.error, stackFrame);
322
+ }
323
+ return new ApiError(parsed.message, status, stackFrame);
324
+ } catch (e) {
325
+ // ..
320
326
  }
321
-
322
- return new ApiError(message, status, stackFrame);
327
+ return new ApiError(content, status, stackFrame);
323
328
  }
324
329
 
325
330
  function isNetworkError({
@@ -350,9 +355,12 @@ function stackFrameWithoutCredentials(stackFrame) {
350
355
  const modifiedHeaders = stackFrame.request.headers['x-algolia-api-key'] ? {
351
356
  'x-algolia-api-key': '*****'
352
357
  } : {};
353
- return { ...stackFrame,
354
- request: { ...stackFrame.request,
355
- headers: { ...stackFrame.request.headers,
358
+ return {
359
+ ...stackFrame,
360
+ request: {
361
+ ...stackFrame.request,
362
+ headers: {
363
+ ...stackFrame.request.headers,
356
364
  ...modifiedHeaders
357
365
  }
358
366
  }
@@ -377,53 +385,49 @@ function createTransporter({
377
385
  });
378
386
  }));
379
387
  const hostsUp = statefulHosts.filter(host => host.isUp());
380
- const hostsTimedOut = statefulHosts.filter(host => host.isTimedOut()); // Note, we put the hosts that previously timed out on the end of the list.
381
-
388
+ const hostsTimedOut = statefulHosts.filter(host => host.isTimedOut());
389
+ // Note, we put the hosts that previously timed out on the end of the list.
382
390
  const hostsAvailable = [...hostsUp, ...hostsTimedOut];
383
391
  const compatibleHostsAvailable = hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;
384
392
  return {
385
393
  hosts: compatibleHostsAvailable,
386
-
387
394
  getTimeout(timeoutsCount, baseTimeout) {
388
- /**
389
- * Imagine that you have 4 hosts, if timeouts will increase
390
- * on the following way: 1 (timed out) > 4 (timed out) > 5 (200).
391
- *
392
- * Note that, the very next request, we start from the previous timeout.
393
- *
394
- * 5 (timed out) > 6 (timed out) > 7 ...
395
- *
396
- * This strategy may need to be reviewed, but is the strategy on the our
397
- * current v3 version.
395
+ /**
396
+ * Imagine that you have 4 hosts, if timeouts will increase
397
+ * on the following way: 1 (timed out) > 4 (timed out) > 5 (200).
398
+ *
399
+ * Note that, the very next request, we start from the previous timeout.
400
+ *
401
+ * 5 (timed out) > 6 (timed out) > 7 ...
402
+ *
403
+ * This strategy may need to be reviewed, but is the strategy on the our
404
+ * current v3 version.
398
405
  */
399
406
  const timeoutMultiplier = hostsTimedOut.length === 0 && timeoutsCount === 0 ? 1 : hostsTimedOut.length + 3 + timeoutsCount;
400
407
  return timeoutMultiplier * baseTimeout;
401
408
  }
402
-
403
409
  };
404
410
  }
405
-
406
411
  async function retryableRequest(request, requestOptions, isRead = true) {
407
412
  const stackTrace = [];
408
- /**
409
- * First we prepare the payload that do not depend from hosts.
413
+ /**
414
+ * First we prepare the payload that do not depend from hosts.
410
415
  */
411
-
412
416
  const data = serializeData(request, requestOptions);
413
- const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers); // On `GET`, the data is proxied to query parameters.
414
-
415
- const dataQueryParameters = request.method === 'GET' ? { ...request.data,
417
+ const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);
418
+ // On `GET`, the data is proxied to query parameters.
419
+ const dataQueryParameters = request.method === 'GET' ? {
420
+ ...request.data,
416
421
  ...requestOptions.data
417
422
  } : {};
418
- const queryParameters = { ...baseQueryParameters,
423
+ const queryParameters = {
424
+ ...baseQueryParameters,
419
425
  ...request.queryParameters,
420
426
  ...dataQueryParameters
421
427
  };
422
-
423
428
  if (algoliaAgent.value) {
424
429
  queryParameters['x-algolia-agent'] = algoliaAgent.value;
425
430
  }
426
-
427
431
  if (requestOptions && requestOptions.queryParameters) {
428
432
  for (const key of Object.keys(requestOptions.queryParameters)) {
429
433
  // We want to keep `undefined` and `null` values,
@@ -436,25 +440,19 @@ function createTransporter({
436
440
  }
437
441
  }
438
442
  }
439
-
440
443
  let timeoutsCount = 0;
441
-
442
444
  const retry = async (retryableHosts, getTimeout) => {
443
- /**
444
- * We iterate on each host, until there is no host left.
445
+ /**
446
+ * We iterate on each host, until there is no host left.
445
447
  */
446
448
  const host = retryableHosts.pop();
447
-
448
449
  if (host === undefined) {
449
450
  throw new RetryError(stackTraceWithoutCredentials(stackTrace));
450
451
  }
451
-
452
452
  let responseTimeout = requestOptions.timeout;
453
-
454
453
  if (responseTimeout === undefined) {
455
454
  responseTimeout = isRead ? timeouts.read : timeouts.write;
456
455
  }
457
-
458
456
  const payload = {
459
457
  data,
460
458
  headers,
@@ -463,12 +461,11 @@ function createTransporter({
463
461
  connectTimeout: getTimeout(timeoutsCount, timeouts.connect),
464
462
  responseTimeout: getTimeout(timeoutsCount, responseTimeout)
465
463
  };
466
- /**
467
- * The stackFrame is pushed to the stackTrace so we
468
- * can have information about onRetry and onFailure
469
- * decisions.
464
+ /**
465
+ * The stackFrame is pushed to the stackTrace so we
466
+ * can have information about onRetry and onFailure
467
+ * decisions.
470
468
  */
471
-
472
469
  const pushToStackTrace = response => {
473
470
  const stackFrame = {
474
471
  request: payload,
@@ -479,102 +476,85 @@ function createTransporter({
479
476
  stackTrace.push(stackFrame);
480
477
  return stackFrame;
481
478
  };
482
-
483
479
  const response = await requester.send(payload);
484
-
485
480
  if (isRetryable(response)) {
486
- const stackFrame = pushToStackTrace(response); // If response is a timeout, we increase the number of timeouts so we can increase the timeout later.
487
-
481
+ const stackFrame = pushToStackTrace(response);
482
+ // If response is a timeout, we increase the number of timeouts so we can increase the timeout later.
488
483
  if (response.isTimedOut) {
489
484
  timeoutsCount++;
490
485
  }
491
- /**
492
- * Failures are individually sent to the logger, allowing
493
- * the end user to debug / store stack frames even
494
- * when a retry error does not happen.
486
+ /**
487
+ * Failures are individually sent to the logger, allowing
488
+ * the end user to debug / store stack frames even
489
+ * when a retry error does not happen.
495
490
  */
496
491
  // eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
497
-
498
-
499
492
  console.log('Retryable failure', stackFrameWithoutCredentials(stackFrame));
500
- /**
501
- * We also store the state of the host in failure cases. If the host, is
502
- * down it will remain down for the next 2 minutes. In a timeout situation,
503
- * this host will be added end of the list of hosts on the next request.
493
+ /**
494
+ * We also store the state of the host in failure cases. If the host, is
495
+ * down it will remain down for the next 2 minutes. In a timeout situation,
496
+ * this host will be added end of the list of hosts on the next request.
504
497
  */
505
-
506
498
  await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));
507
499
  return retry(retryableHosts, getTimeout);
508
500
  }
509
-
510
501
  if (isSuccess(response)) {
511
502
  return deserializeSuccess(response);
512
503
  }
513
-
514
504
  pushToStackTrace(response);
515
505
  throw deserializeFailure(response, stackTrace);
516
506
  };
517
- /**
518
- * Finally, for each retryable host perform request until we got a non
519
- * retryable response. Some notes here:
520
- *
521
- * 1. The reverse here is applied so we can apply a `pop` later on => more performant.
522
- * 2. We also get from the retryable options a timeout multiplier that is tailored
523
- * for the current context.
507
+ /**
508
+ * Finally, for each retryable host perform request until we got a non
509
+ * retryable response. Some notes here:
510
+ *
511
+ * 1. The reverse here is applied so we can apply a `pop` later on => more performant.
512
+ * 2. We also get from the retryable options a timeout multiplier that is tailored
513
+ * for the current context.
524
514
  */
525
-
526
-
527
515
  const compatibleHosts = hosts.filter(host => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'));
528
516
  const options = await createRetryableOptions(compatibleHosts);
529
517
  return retry([...options.hosts].reverse(), options.getTimeout);
530
518
  }
531
-
532
519
  function createRequest(request, requestOptions = {}) {
533
- /**
534
- * A read request is either a `GET` request, or a request that we make
535
- * via the `read` transporter (e.g. `search`).
520
+ /**
521
+ * A read request is either a `GET` request, or a request that we make
522
+ * via the `read` transporter (e.g. `search`).
536
523
  */
537
524
  const isRead = request.useReadTransporter || request.method === 'GET';
538
-
539
525
  if (!isRead) {
540
- /**
541
- * On write requests, no cache mechanisms are applied, and we
542
- * proxy the request immediately to the requester.
526
+ /**
527
+ * On write requests, no cache mechanisms are applied, and we
528
+ * proxy the request immediately to the requester.
543
529
  */
544
530
  return retryableRequest(request, requestOptions, isRead);
545
531
  }
546
-
547
532
  const createRetryableRequest = () => {
548
- /**
549
- * Then, we prepare a function factory that contains the construction of
550
- * the retryable request. At this point, we may *not* perform the actual
551
- * request. But we want to have the function factory ready.
533
+ /**
534
+ * Then, we prepare a function factory that contains the construction of
535
+ * the retryable request. At this point, we may *not* perform the actual
536
+ * request. But we want to have the function factory ready.
552
537
  */
553
538
  return retryableRequest(request, requestOptions);
554
539
  };
555
- /**
556
- * Once we have the function factory ready, we need to determine of the
557
- * request is "cacheable" - should be cached. Note that, once again,
558
- * the user can force this option.
540
+ /**
541
+ * Once we have the function factory ready, we need to determine of the
542
+ * request is "cacheable" - should be cached. Note that, once again,
543
+ * the user can force this option.
559
544
  */
560
-
561
-
562
545
  const cacheable = requestOptions.cacheable || request.cacheable;
563
- /**
564
- * If is not "cacheable", we immediately trigger the retryable request, no
565
- * need to check cache implementations.
546
+ /**
547
+ * If is not "cacheable", we immediately trigger the retryable request, no
548
+ * need to check cache implementations.
566
549
  */
567
-
568
550
  if (cacheable !== true) {
569
551
  return createRetryableRequest();
570
552
  }
571
- /**
572
- * If the request is "cacheable", we need to first compute the key to ask
573
- * the cache implementations if this request is on progress or if the
574
- * response already exists on the cache.
553
+ /**
554
+ * If the request is "cacheable", we need to first compute the key to ask
555
+ * the cache implementations if this request is on progress or if the
556
+ * response already exists on the cache.
575
557
  */
576
-
577
-
578
558
  const key = {
579
559
  request,
580
560
  requestOptions,
@@ -583,33 +563,31 @@ function createTransporter({
583
563
  headers: baseHeaders
584
564
  }
585
565
  };
586
- /**
587
- * With the computed key, we first ask the responses cache
588
- * implementation if this request was been resolved before.
566
+ /**
567
+ * With the computed key, we first ask the responses cache
568
+ * implementation if this request was been resolved before.
589
569
  */
590
-
591
570
  return responsesCache.get(key, () => {
592
- /**
593
- * If the request has never resolved before, we actually ask if there
594
- * is a current request with the same key on progress.
571
+ /**
572
+ * If the request has never resolved before, we actually ask if there
573
+ * is a current request with the same key on progress.
595
574
  */
596
575
  return requestsCache.get(key, () =>
597
- /**
598
- * Finally, if there is no request in progress with the same key,
599
- * this `createRetryableRequest()` will actually trigger the
600
- * retryable request.
576
+ /**
577
+ * Finally, if there is no request in progress with the same key,
578
+ * this `createRetryableRequest()` will actually trigger the
579
+ * retryable request.
601
580
  */
602
581
  requestsCache.set(key, createRetryableRequest()).then(response => Promise.all([requestsCache.delete(key), response]), err => Promise.all([requestsCache.delete(key), Promise.reject(err)])).then(([_, response]) => response));
603
582
  }, {
604
- /**
605
- * Of course, once we get this response back from the server, we
606
- * tell response cache to actually store the received response
607
- * to be used later.
583
+ /**
584
+ * Of course, once we get this response back from the server, we
585
+ * tell response cache to actually store the received response
586
+ * to be used later.
608
587
  */
609
588
  miss: response => responsesCache.set(key, response)
610
589
  });
611
590
  }
612
-
613
591
  return {
614
592
  hostsCache,
615
593
  requester,
@@ -627,17 +605,13 @@ function createTransporter({
627
605
  function createAlgoliaAgent(version) {
628
606
  const algoliaAgent = {
629
607
  value: `Algolia for JavaScript (${version})`,
630
-
631
608
  add(options) {
632
609
  const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;
633
-
634
610
  if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
635
611
  algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
636
612
  }
637
-
638
613
  return algoliaAgent;
639
614
  }
640
-
641
615
  };
642
616
  return algoliaAgent;
643
617
  }
@@ -659,417 +633,427 @@ const DEFAULT_CONNECT_TIMEOUT_BROWSER = 1000;
659
633
  const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
660
634
  const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
661
635
 
662
- function createXhrRequester() {
663
- function send(request) {
664
- return new Promise((resolve) => {
665
- const baseRequester = new XMLHttpRequest();
666
- baseRequester.open(request.method, request.url, true);
667
- Object.keys(request.headers).forEach((key) => baseRequester.setRequestHeader(key, request.headers[key]));
668
- const createTimeout = (timeout, content) => {
669
- return setTimeout(() => {
670
- baseRequester.abort();
671
- resolve({
672
- status: 0,
673
- content,
674
- isTimedOut: true,
675
- });
676
- }, timeout);
677
- };
678
- const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
679
- let responseTimeout;
680
- baseRequester.onreadystatechange = () => {
681
- if (baseRequester.readyState > baseRequester.OPENED &&
682
- responseTimeout === undefined) {
683
- clearTimeout(connectTimeout);
684
- responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
685
- }
686
- };
687
- baseRequester.onerror = () => {
688
- // istanbul ignore next
689
- if (baseRequester.status === 0) {
690
- clearTimeout(connectTimeout);
691
- clearTimeout(responseTimeout);
692
- resolve({
693
- content: baseRequester.responseText || 'Network request failed',
694
- status: baseRequester.status,
695
- isTimedOut: false,
696
- });
697
- }
698
- };
699
- baseRequester.onload = () => {
700
- clearTimeout(connectTimeout);
701
- clearTimeout(responseTimeout);
702
- resolve({
703
- content: baseRequester.responseText,
704
- status: baseRequester.status,
705
- isTimedOut: false,
706
- });
707
- };
708
- baseRequester.send(request.data);
709
- });
710
- }
711
- return { send };
636
+ function createXhrRequester() {
637
+ function send(request) {
638
+ return new Promise((resolve) => {
639
+ const baseRequester = new XMLHttpRequest();
640
+ baseRequester.open(request.method, request.url, true);
641
+ Object.keys(request.headers).forEach((key) => baseRequester.setRequestHeader(key, request.headers[key]));
642
+ const createTimeout = (timeout, content) => {
643
+ return setTimeout(() => {
644
+ baseRequester.abort();
645
+ resolve({
646
+ status: 0,
647
+ content,
648
+ isTimedOut: true,
649
+ });
650
+ }, timeout);
651
+ };
652
+ const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
653
+ let responseTimeout;
654
+ baseRequester.onreadystatechange = () => {
655
+ if (baseRequester.readyState > baseRequester.OPENED &&
656
+ responseTimeout === undefined) {
657
+ clearTimeout(connectTimeout);
658
+ responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
659
+ }
660
+ };
661
+ baseRequester.onerror = () => {
662
+ // istanbul ignore next
663
+ if (baseRequester.status === 0) {
664
+ clearTimeout(connectTimeout);
665
+ clearTimeout(responseTimeout);
666
+ resolve({
667
+ content: baseRequester.responseText || 'Network request failed',
668
+ status: baseRequester.status,
669
+ isTimedOut: false,
670
+ });
671
+ }
672
+ };
673
+ baseRequester.onload = () => {
674
+ clearTimeout(connectTimeout);
675
+ clearTimeout(responseTimeout);
676
+ resolve({
677
+ content: baseRequester.responseText,
678
+ status: baseRequester.status,
679
+ isTimedOut: false,
680
+ });
681
+ };
682
+ baseRequester.send(request.data);
683
+ });
684
+ }
685
+ return { send };
712
686
  }
713
687
 
714
- // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
715
- const apiClientVersion = '5.0.0-alpha.10';
716
- const REGIONS = ['eu', 'us'];
717
- function getDefaultHosts(region) {
718
- const url = 'query-suggestions.{region}.algolia.com'.replace('{region}', region);
719
- return [{ url, accept: 'readWrite', protocol: 'https' }];
720
- }
721
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
722
- function createQuerySuggestionsClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }) {
723
- const auth = createAuth(appIdOption, apiKeyOption, authMode);
724
- const transporter = createTransporter({
725
- hosts: getDefaultHosts(regionOption),
726
- ...options,
727
- algoliaAgent: getAlgoliaAgent({
728
- algoliaAgents,
729
- client: 'QuerySuggestions',
730
- version: apiClientVersion,
731
- }),
732
- baseHeaders: {
733
- 'content-type': 'text/plain',
734
- ...auth.headers(),
735
- ...options.baseHeaders,
736
- },
737
- baseQueryParameters: {
738
- ...auth.queryParameters(),
739
- ...options.baseQueryParameters,
740
- },
741
- });
742
- return {
743
- transporter,
744
- /**
745
- * The `appId` currently in use.
746
- */
747
- appId: appIdOption,
748
- /**
749
- * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
750
- */
751
- clearCache() {
752
- return Promise.all([
753
- transporter.requestsCache.clear(),
754
- transporter.responsesCache.clear(),
755
- ]).then(() => undefined);
756
- },
757
- /**
758
- * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
759
- */
760
- get _ua() {
761
- return transporter.algoliaAgent.value;
762
- },
763
- /**
764
- * Adds a `segment` to the `x-algolia-agent` sent with every requests.
765
- *
766
- * @param segment - The algolia agent (user-agent) segment to add.
767
- * @param version - The version of the agent.
768
- */
769
- addAlgoliaAgent(segment, version) {
770
- transporter.algoliaAgent.add({ segment, version });
771
- },
772
- /**
773
- * Create a configuration of a Query Suggestions index. There\'s a limit of 100 configurations per application.
774
- *
775
- * @summary Create a configuration.
776
- * @param querySuggestionsIndexWithIndexParam - The querySuggestionsIndexWithIndexParam object.
777
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
778
- */
779
- createConfig(querySuggestionsIndexWithIndexParam, requestOptions) {
780
- if (!querySuggestionsIndexWithIndexParam) {
781
- throw new Error('Parameter `querySuggestionsIndexWithIndexParam` is required when calling `createConfig`.');
782
- }
783
- const requestPath = '/1/configs';
784
- const headers = {};
785
- const queryParameters = {};
786
- const request = {
787
- method: 'POST',
788
- path: requestPath,
789
- queryParameters,
790
- headers,
791
- data: querySuggestionsIndexWithIndexParam,
792
- };
793
- return transporter.request(request, requestOptions);
794
- },
795
- /**
796
- * This method allow you to send requests to the Algolia REST API.
797
- *
798
- * @summary Send requests to the Algolia REST API.
799
- * @param del - The del object.
800
- * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
801
- * @param del.parameters - Query parameters to be applied to the current query.
802
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
803
- */
804
- del({ path, parameters }, requestOptions) {
805
- if (!path) {
806
- throw new Error('Parameter `path` is required when calling `del`.');
807
- }
808
- const requestPath = '/1{path}'.replace('{path}', path);
809
- const headers = {};
810
- const queryParameters = parameters ? parameters : {};
811
- const request = {
812
- method: 'DELETE',
813
- path: requestPath,
814
- queryParameters,
815
- headers,
816
- };
817
- return transporter.request(request, requestOptions);
818
- },
819
- /**
820
- * Delete a configuration of a Query Suggestion\'s index. By deleting a configuration, you stop all updates to the underlying query suggestion index. Note that when doing this, the underlying index does not change - existing suggestions remain untouched.
821
- *
822
- * @summary Delete a configuration.
823
- * @param deleteConfig - The deleteConfig object.
824
- * @param deleteConfig.indexName - The index in which to perform the request.
825
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
826
- */
827
- deleteConfig({ indexName }, requestOptions) {
828
- if (!indexName) {
829
- throw new Error('Parameter `indexName` is required when calling `deleteConfig`.');
830
- }
831
- const requestPath = '/1/configs/{indexName}'.replace('{indexName}', encodeURIComponent(indexName));
832
- const headers = {};
833
- const queryParameters = {};
834
- const request = {
835
- method: 'DELETE',
836
- path: requestPath,
837
- queryParameters,
838
- headers,
839
- };
840
- return transporter.request(request, requestOptions);
841
- },
842
- /**
843
- * This method allow you to send requests to the Algolia REST API.
844
- *
845
- * @summary Send requests to the Algolia REST API.
846
- * @param get - The get object.
847
- * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
848
- * @param get.parameters - Query parameters to be applied to the current query.
849
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
850
- */
851
- get({ path, parameters }, requestOptions) {
852
- if (!path) {
853
- throw new Error('Parameter `path` is required when calling `get`.');
854
- }
855
- const requestPath = '/1{path}'.replace('{path}', path);
856
- const headers = {};
857
- const queryParameters = parameters ? parameters : {};
858
- const request = {
859
- method: 'GET',
860
- path: requestPath,
861
- queryParameters,
862
- headers,
863
- };
864
- return transporter.request(request, requestOptions);
865
- },
866
- /**
867
- * Get all the configurations of Query Suggestions. For each index, you get a block of JSON with a list of its configuration settings.
868
- *
869
- * @summary List configurations.
870
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
871
- */
872
- getAllConfigs(requestOptions) {
873
- const requestPath = '/1/configs';
874
- const headers = {};
875
- const queryParameters = {};
876
- const request = {
877
- method: 'GET',
878
- path: requestPath,
879
- queryParameters,
880
- headers,
881
- };
882
- return transporter.request(request, requestOptions);
883
- },
884
- /**
885
- * Get the configuration of a single Query Suggestions index.
886
- *
887
- * @summary Get a single configuration.
888
- * @param getConfig - The getConfig object.
889
- * @param getConfig.indexName - The index in which to perform the request.
890
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
891
- */
892
- getConfig({ indexName }, requestOptions) {
893
- if (!indexName) {
894
- throw new Error('Parameter `indexName` is required when calling `getConfig`.');
895
- }
896
- const requestPath = '/1/configs/{indexName}'.replace('{indexName}', encodeURIComponent(indexName));
897
- const headers = {};
898
- const queryParameters = {};
899
- const request = {
900
- method: 'GET',
901
- path: requestPath,
902
- queryParameters,
903
- headers,
904
- };
905
- return transporter.request(request, requestOptions);
906
- },
907
- /**
908
- * Get the status of a Query Suggestion\'s index. The status includes whether the Query Suggestions index is currently in the process of being built, and the last build time.
909
- *
910
- * @summary Get configuration status.
911
- * @param getConfigStatus - The getConfigStatus object.
912
- * @param getConfigStatus.indexName - The index in which to perform the request.
913
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
914
- */
915
- getConfigStatus({ indexName }, requestOptions) {
916
- if (!indexName) {
917
- throw new Error('Parameter `indexName` is required when calling `getConfigStatus`.');
918
- }
919
- const requestPath = '/1/configs/{indexName}/status'.replace('{indexName}', encodeURIComponent(indexName));
920
- const headers = {};
921
- const queryParameters = {};
922
- const request = {
923
- method: 'GET',
924
- path: requestPath,
925
- queryParameters,
926
- headers,
927
- };
928
- return transporter.request(request, requestOptions);
929
- },
930
- /**
931
- * Get the log file of the last build of a single Query Suggestion index.
932
- *
933
- * @summary Get a log file.
934
- * @param getLogFile - The getLogFile object.
935
- * @param getLogFile.indexName - The index in which to perform the request.
936
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
937
- */
938
- getLogFile({ indexName }, requestOptions) {
939
- if (!indexName) {
940
- throw new Error('Parameter `indexName` is required when calling `getLogFile`.');
941
- }
942
- const requestPath = '/1/logs/{indexName}'.replace('{indexName}', encodeURIComponent(indexName));
943
- const headers = {};
944
- const queryParameters = {};
945
- const request = {
946
- method: 'GET',
947
- path: requestPath,
948
- queryParameters,
949
- headers,
950
- };
951
- return transporter.request(request, requestOptions);
952
- },
953
- /**
954
- * This method allow you to send requests to the Algolia REST API.
955
- *
956
- * @summary Send requests to the Algolia REST API.
957
- * @param post - The post object.
958
- * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
959
- * @param post.parameters - Query parameters to be applied to the current query.
960
- * @param post.body - The parameters to send with the custom request.
961
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
962
- */
963
- post({ path, parameters, body }, requestOptions) {
964
- if (!path) {
965
- throw new Error('Parameter `path` is required when calling `post`.');
966
- }
967
- const requestPath = '/1{path}'.replace('{path}', path);
968
- const headers = {};
969
- const queryParameters = parameters ? parameters : {};
970
- const request = {
971
- method: 'POST',
972
- path: requestPath,
973
- queryParameters,
974
- headers,
975
- data: body ? body : {},
976
- };
977
- return transporter.request(request, requestOptions);
978
- },
979
- /**
980
- * This method allow you to send requests to the Algolia REST API.
981
- *
982
- * @summary Send requests to the Algolia REST API.
983
- * @param put - The put object.
984
- * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
985
- * @param put.parameters - Query parameters to be applied to the current query.
986
- * @param put.body - The parameters to send with the custom request.
987
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
988
- */
989
- put({ path, parameters, body }, requestOptions) {
990
- if (!path) {
991
- throw new Error('Parameter `path` is required when calling `put`.');
992
- }
993
- const requestPath = '/1{path}'.replace('{path}', path);
994
- const headers = {};
995
- const queryParameters = parameters ? parameters : {};
996
- const request = {
997
- method: 'PUT',
998
- path: requestPath,
999
- queryParameters,
1000
- headers,
1001
- data: body ? body : {},
1002
- };
1003
- return transporter.request(request, requestOptions);
1004
- },
1005
- /**
1006
- * Update the configuration of a Query Suggestions index.
1007
- *
1008
- * @summary Update a configuration.
1009
- * @param updateConfig - The updateConfig object.
1010
- * @param updateConfig.indexName - The index in which to perform the request.
1011
- * @param updateConfig.querySuggestionsIndexParam - The querySuggestionsIndexParam object.
1012
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1013
- */
1014
- updateConfig({ indexName, querySuggestionsIndexParam }, requestOptions) {
1015
- if (!indexName) {
1016
- throw new Error('Parameter `indexName` is required when calling `updateConfig`.');
1017
- }
1018
- if (!querySuggestionsIndexParam) {
1019
- throw new Error('Parameter `querySuggestionsIndexParam` is required when calling `updateConfig`.');
1020
- }
1021
- if (!querySuggestionsIndexParam.sourceIndices) {
1022
- throw new Error('Parameter `querySuggestionsIndexParam.sourceIndices` is required when calling `updateConfig`.');
1023
- }
1024
- const requestPath = '/1/configs/{indexName}'.replace('{indexName}', encodeURIComponent(indexName));
1025
- const headers = {};
1026
- const queryParameters = {};
1027
- const request = {
1028
- method: 'PUT',
1029
- path: requestPath,
1030
- queryParameters,
1031
- headers,
1032
- data: querySuggestionsIndexParam,
1033
- };
1034
- return transporter.request(request, requestOptions);
1035
- },
1036
- };
688
+ // 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.
689
+ const apiClientVersion = '5.0.0-alpha.101';
690
+ const REGIONS = ['eu', 'us'];
691
+ function getDefaultHosts(region) {
692
+ const url = 'query-suggestions.{region}.algolia.com'.replace('{region}', region);
693
+ return [{ url, accept: 'readWrite', protocol: 'https' }];
694
+ }
695
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
696
+ function createQuerySuggestionsClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }) {
697
+ const auth = createAuth(appIdOption, apiKeyOption, authMode);
698
+ const transporter = createTransporter({
699
+ hosts: getDefaultHosts(regionOption),
700
+ ...options,
701
+ algoliaAgent: getAlgoliaAgent({
702
+ algoliaAgents,
703
+ client: 'QuerySuggestions',
704
+ version: apiClientVersion,
705
+ }),
706
+ baseHeaders: {
707
+ 'content-type': 'text/plain',
708
+ ...auth.headers(),
709
+ ...options.baseHeaders,
710
+ },
711
+ baseQueryParameters: {
712
+ ...auth.queryParameters(),
713
+ ...options.baseQueryParameters,
714
+ },
715
+ });
716
+ return {
717
+ transporter,
718
+ /**
719
+ * The `appId` currently in use.
720
+ */
721
+ appId: appIdOption,
722
+ /**
723
+ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
724
+ */
725
+ clearCache() {
726
+ return Promise.all([
727
+ transporter.requestsCache.clear(),
728
+ transporter.responsesCache.clear(),
729
+ ]).then(() => undefined);
730
+ },
731
+ /**
732
+ * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
733
+ */
734
+ get _ua() {
735
+ return transporter.algoliaAgent.value;
736
+ },
737
+ /**
738
+ * Adds a `segment` to the `x-algolia-agent` sent with every requests.
739
+ *
740
+ * @param segment - The algolia agent (user-agent) segment to add.
741
+ * @param version - The version of the agent.
742
+ */
743
+ addAlgoliaAgent(segment, version) {
744
+ transporter.algoliaAgent.add({ segment, version });
745
+ },
746
+ /**
747
+ * Create a new Query Suggestions configuration. You can have up to 100 configurations per Algolia application.
748
+ *
749
+ * Required API Key ACLs:
750
+ * - editSettings.
751
+ *
752
+ * @param querySuggestionsConfigurationWithIndex - The querySuggestionsConfigurationWithIndex object.
753
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
754
+ */
755
+ createConfig(querySuggestionsConfigurationWithIndex, requestOptions) {
756
+ if (!querySuggestionsConfigurationWithIndex) {
757
+ throw new Error('Parameter `querySuggestionsConfigurationWithIndex` is required when calling `createConfig`.');
758
+ }
759
+ const requestPath = '/1/configs';
760
+ const headers = {};
761
+ const queryParameters = {};
762
+ const request = {
763
+ method: 'POST',
764
+ path: requestPath,
765
+ queryParameters,
766
+ headers,
767
+ data: querySuggestionsConfigurationWithIndex,
768
+ };
769
+ return transporter.request(request, requestOptions);
770
+ },
771
+ /**
772
+ * This method allow you to send requests to the Algolia REST API.
773
+ *
774
+ * @param customDelete - The customDelete object.
775
+ * @param customDelete.path - Path of the endpoint, anything after \"/1\" must be specified.
776
+ * @param customDelete.parameters - Query parameters to apply to the current query.
777
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
778
+ */
779
+ customDelete({ path, parameters }, requestOptions) {
780
+ if (!path) {
781
+ throw new Error('Parameter `path` is required when calling `customDelete`.');
782
+ }
783
+ const requestPath = '/1{path}'.replace('{path}', path);
784
+ const headers = {};
785
+ const queryParameters = parameters ? parameters : {};
786
+ const request = {
787
+ method: 'DELETE',
788
+ path: requestPath,
789
+ queryParameters,
790
+ headers,
791
+ };
792
+ return transporter.request(request, requestOptions);
793
+ },
794
+ /**
795
+ * This method allow you to send requests to the Algolia REST API.
796
+ *
797
+ * @param customGet - The customGet object.
798
+ * @param customGet.path - Path of the endpoint, anything after \"/1\" must be specified.
799
+ * @param customGet.parameters - Query parameters to apply to the current query.
800
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
801
+ */
802
+ customGet({ path, parameters }, requestOptions) {
803
+ if (!path) {
804
+ throw new Error('Parameter `path` is required when calling `customGet`.');
805
+ }
806
+ const requestPath = '/1{path}'.replace('{path}', path);
807
+ const headers = {};
808
+ const queryParameters = parameters ? parameters : {};
809
+ const request = {
810
+ method: 'GET',
811
+ path: requestPath,
812
+ queryParameters,
813
+ headers,
814
+ };
815
+ return transporter.request(request, requestOptions);
816
+ },
817
+ /**
818
+ * This method allow you to send requests to the Algolia REST API.
819
+ *
820
+ * @param customPost - The customPost object.
821
+ * @param customPost.path - Path of the endpoint, anything after \"/1\" must be specified.
822
+ * @param customPost.parameters - Query parameters to apply to the current query.
823
+ * @param customPost.body - Parameters to send with the custom request.
824
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
825
+ */
826
+ customPost({ path, parameters, body }, requestOptions) {
827
+ if (!path) {
828
+ throw new Error('Parameter `path` is required when calling `customPost`.');
829
+ }
830
+ const requestPath = '/1{path}'.replace('{path}', path);
831
+ const headers = {};
832
+ const queryParameters = parameters ? parameters : {};
833
+ const request = {
834
+ method: 'POST',
835
+ path: requestPath,
836
+ queryParameters,
837
+ headers,
838
+ data: body ? body : {},
839
+ };
840
+ return transporter.request(request, requestOptions);
841
+ },
842
+ /**
843
+ * This method allow you to send requests to the Algolia REST API.
844
+ *
845
+ * @param customPut - The customPut object.
846
+ * @param customPut.path - Path of the endpoint, anything after \"/1\" must be specified.
847
+ * @param customPut.parameters - Query parameters to apply to the current query.
848
+ * @param customPut.body - Parameters to send with the custom request.
849
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
850
+ */
851
+ customPut({ path, parameters, body }, requestOptions) {
852
+ if (!path) {
853
+ throw new Error('Parameter `path` is required when calling `customPut`.');
854
+ }
855
+ const requestPath = '/1{path}'.replace('{path}', path);
856
+ const headers = {};
857
+ const queryParameters = parameters ? parameters : {};
858
+ const request = {
859
+ method: 'PUT',
860
+ path: requestPath,
861
+ queryParameters,
862
+ headers,
863
+ data: body ? body : {},
864
+ };
865
+ return transporter.request(request, requestOptions);
866
+ },
867
+ /**
868
+ * Delete a Query Suggestions configuration. Deleting only removes the configuration and stops updates to the Query Suggestions index. The Query Suggestions index itself is not deleted.
869
+ *
870
+ * Required API Key ACLs:
871
+ * - editSettings.
872
+ *
873
+ * @param deleteConfig - The deleteConfig object.
874
+ * @param deleteConfig.indexName - Query Suggestions index name.
875
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
876
+ */
877
+ deleteConfig({ indexName }, requestOptions) {
878
+ if (!indexName) {
879
+ throw new Error('Parameter `indexName` is required when calling `deleteConfig`.');
880
+ }
881
+ const requestPath = '/1/configs/{indexName}'.replace('{indexName}', encodeURIComponent(indexName));
882
+ const headers = {};
883
+ const queryParameters = {};
884
+ const request = {
885
+ method: 'DELETE',
886
+ path: requestPath,
887
+ queryParameters,
888
+ headers,
889
+ };
890
+ return transporter.request(request, requestOptions);
891
+ },
892
+ /**
893
+ * List all Query Suggestions configurations of your Algolia application.
894
+ *
895
+ * Required API Key ACLs:
896
+ * - settings.
897
+ *
898
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
899
+ */
900
+ getAllConfigs(requestOptions) {
901
+ const requestPath = '/1/configs';
902
+ const headers = {};
903
+ const queryParameters = {};
904
+ const request = {
905
+ method: 'GET',
906
+ path: requestPath,
907
+ queryParameters,
908
+ headers,
909
+ };
910
+ return transporter.request(request, requestOptions);
911
+ },
912
+ /**
913
+ * Get a single Query Suggestions configuration.
914
+ *
915
+ * Required API Key ACLs:
916
+ * - settings.
917
+ *
918
+ * @param getConfig - The getConfig object.
919
+ * @param getConfig.indexName - Query Suggestions index name.
920
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
921
+ */
922
+ getConfig({ indexName }, requestOptions) {
923
+ if (!indexName) {
924
+ throw new Error('Parameter `indexName` is required when calling `getConfig`.');
925
+ }
926
+ const requestPath = '/1/configs/{indexName}'.replace('{indexName}', encodeURIComponent(indexName));
927
+ const headers = {};
928
+ const queryParameters = {};
929
+ const request = {
930
+ method: 'GET',
931
+ path: requestPath,
932
+ queryParameters,
933
+ headers,
934
+ };
935
+ return transporter.request(request, requestOptions);
936
+ },
937
+ /**
938
+ * Report the status of a Query Suggestions index.
939
+ *
940
+ * Required API Key ACLs:
941
+ * - settings.
942
+ *
943
+ * @param getConfigStatus - The getConfigStatus object.
944
+ * @param getConfigStatus.indexName - Query Suggestions index name.
945
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
946
+ */
947
+ getConfigStatus({ indexName }, requestOptions) {
948
+ if (!indexName) {
949
+ throw new Error('Parameter `indexName` is required when calling `getConfigStatus`.');
950
+ }
951
+ const requestPath = '/1/configs/{indexName}/status'.replace('{indexName}', encodeURIComponent(indexName));
952
+ const headers = {};
953
+ const queryParameters = {};
954
+ const request = {
955
+ method: 'GET',
956
+ path: requestPath,
957
+ queryParameters,
958
+ headers,
959
+ };
960
+ return transporter.request(request, requestOptions);
961
+ },
962
+ /**
963
+ * Get the logs for a single Query Suggestions index.
964
+ *
965
+ * Required API Key ACLs:
966
+ * - settings.
967
+ *
968
+ * @param getLogFile - The getLogFile object.
969
+ * @param getLogFile.indexName - Query Suggestions index name.
970
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
971
+ */
972
+ getLogFile({ indexName }, requestOptions) {
973
+ if (!indexName) {
974
+ throw new Error('Parameter `indexName` is required when calling `getLogFile`.');
975
+ }
976
+ const requestPath = '/1/logs/{indexName}'.replace('{indexName}', encodeURIComponent(indexName));
977
+ const headers = {};
978
+ const queryParameters = {};
979
+ const request = {
980
+ method: 'GET',
981
+ path: requestPath,
982
+ queryParameters,
983
+ headers,
984
+ };
985
+ return transporter.request(request, requestOptions);
986
+ },
987
+ /**
988
+ * Update a QuerySuggestions configuration.
989
+ *
990
+ * Required API Key ACLs:
991
+ * - editSettings.
992
+ *
993
+ * @param updateConfig - The updateConfig object.
994
+ * @param updateConfig.indexName - Query Suggestions index name.
995
+ * @param updateConfig.querySuggestionsConfiguration - The querySuggestionsConfiguration object.
996
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
997
+ */
998
+ updateConfig({ indexName, querySuggestionsConfiguration }, requestOptions) {
999
+ if (!indexName) {
1000
+ throw new Error('Parameter `indexName` is required when calling `updateConfig`.');
1001
+ }
1002
+ if (!querySuggestionsConfiguration) {
1003
+ throw new Error('Parameter `querySuggestionsConfiguration` is required when calling `updateConfig`.');
1004
+ }
1005
+ if (!querySuggestionsConfiguration.sourceIndices) {
1006
+ throw new Error('Parameter `querySuggestionsConfiguration.sourceIndices` is required when calling `updateConfig`.');
1007
+ }
1008
+ const requestPath = '/1/configs/{indexName}'.replace('{indexName}', encodeURIComponent(indexName));
1009
+ const headers = {};
1010
+ const queryParameters = {};
1011
+ const request = {
1012
+ method: 'PUT',
1013
+ path: requestPath,
1014
+ queryParameters,
1015
+ headers,
1016
+ data: querySuggestionsConfiguration,
1017
+ };
1018
+ return transporter.request(request, requestOptions);
1019
+ },
1020
+ };
1037
1021
  }
1038
1022
 
1039
- // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
1040
- function querySuggestionsClient(appId, apiKey, region, options) {
1041
- if (!appId || typeof appId !== 'string') {
1042
- throw new Error('`appId` is missing.');
1043
- }
1044
- if (!apiKey || typeof apiKey !== 'string') {
1045
- throw new Error('`apiKey` is missing.');
1046
- }
1047
- if (!region ||
1048
- (region && (typeof region !== 'string' || !REGIONS.includes(region)))) {
1049
- throw new Error(`\`region\` is required and must be one of the following: ${REGIONS.join(', ')}`);
1050
- }
1051
- return createQuerySuggestionsClient({
1052
- appId,
1053
- apiKey,
1054
- region,
1055
- timeouts: {
1056
- connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
1057
- read: DEFAULT_READ_TIMEOUT_BROWSER,
1058
- write: DEFAULT_WRITE_TIMEOUT_BROWSER,
1059
- },
1060
- requester: createXhrRequester(),
1061
- algoliaAgents: [{ segment: 'Browser' }],
1062
- authMode: 'WithinQueryParameters',
1063
- responsesCache: createMemoryCache(),
1064
- requestsCache: createMemoryCache({ serializable: false }),
1065
- hostsCache: createFallbackableCache({
1066
- caches: [
1067
- createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }),
1068
- createMemoryCache(),
1069
- ],
1070
- }),
1071
- ...options,
1072
- });
1023
+ // 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.
1024
+ function querySuggestionsClient(appId, apiKey, region, options) {
1025
+ if (!appId || typeof appId !== 'string') {
1026
+ throw new Error('`appId` is missing.');
1027
+ }
1028
+ if (!apiKey || typeof apiKey !== 'string') {
1029
+ throw new Error('`apiKey` is missing.');
1030
+ }
1031
+ if (!region ||
1032
+ (region && (typeof region !== 'string' || !REGIONS.includes(region)))) {
1033
+ throw new Error(`\`region\` is required and must be one of the following: ${REGIONS.join(', ')}`);
1034
+ }
1035
+ return createQuerySuggestionsClient({
1036
+ appId,
1037
+ apiKey,
1038
+ region,
1039
+ timeouts: {
1040
+ connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
1041
+ read: DEFAULT_READ_TIMEOUT_BROWSER,
1042
+ write: DEFAULT_WRITE_TIMEOUT_BROWSER,
1043
+ },
1044
+ requester: createXhrRequester(),
1045
+ algoliaAgents: [{ segment: 'Browser' }],
1046
+ authMode: 'WithinQueryParameters',
1047
+ responsesCache: createMemoryCache(),
1048
+ requestsCache: createMemoryCache({ serializable: false }),
1049
+ hostsCache: createFallbackableCache({
1050
+ caches: [
1051
+ createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }),
1052
+ createMemoryCache(),
1053
+ ],
1054
+ }),
1055
+ ...options,
1056
+ });
1073
1057
  }
1074
1058
 
1075
1059
  export { apiClientVersion, querySuggestionsClient };