@algolia/client-analytics 4.14.1 → 5.0.0-alpha.1

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 (150) hide show
  1. package/dist/builds/browser.d.ts +6 -0
  2. package/dist/builds/browser.d.ts.map +1 -0
  3. package/dist/builds/node.d.ts +6 -0
  4. package/dist/builds/node.d.ts.map +1 -0
  5. package/dist/client-analytics.cjs.js +907 -65
  6. package/dist/client-analytics.esm.browser.js +1631 -0
  7. package/dist/client-analytics.esm.node.js +917 -0
  8. package/dist/client-analytics.umd.js +2 -0
  9. package/dist/model/averageClickEvent.d.ts +15 -0
  10. package/dist/model/averageClickEvent.d.ts.map +1 -0
  11. package/dist/model/clickPosition.d.ts +11 -0
  12. package/dist/model/clickPosition.d.ts.map +1 -0
  13. package/dist/model/clickThroughRateEvent.d.ts +19 -0
  14. package/dist/model/clickThroughRateEvent.d.ts.map +1 -0
  15. package/dist/model/clientMethodProps.d.ts +508 -0
  16. package/dist/model/clientMethodProps.d.ts.map +1 -0
  17. package/dist/model/conversionRateEvent.d.ts +19 -0
  18. package/dist/model/conversionRateEvent.d.ts.map +1 -0
  19. package/dist/model/direction.d.ts +2 -0
  20. package/dist/model/direction.d.ts.map +1 -0
  21. package/dist/model/errorBase.d.ts +7 -0
  22. package/dist/model/errorBase.d.ts.map +1 -0
  23. package/dist/model/getAverageClickPositionResponse.d.ts +16 -0
  24. package/dist/model/getAverageClickPositionResponse.d.ts.map +1 -0
  25. package/dist/model/getClickPositionsResponse.d.ts +8 -0
  26. package/dist/model/getClickPositionsResponse.d.ts.map +1 -0
  27. package/dist/model/getClickThroughRateResponse.d.ts +20 -0
  28. package/dist/model/getClickThroughRateResponse.d.ts.map +1 -0
  29. package/dist/model/getConversationRateResponse.d.ts +20 -0
  30. package/dist/model/getConversationRateResponse.d.ts.map +1 -0
  31. package/dist/model/getNoClickRateResponse.d.ts +20 -0
  32. package/dist/model/getNoClickRateResponse.d.ts.map +1 -0
  33. package/dist/model/getNoResultsRateResponse.d.ts +20 -0
  34. package/dist/model/getNoResultsRateResponse.d.ts.map +1 -0
  35. package/dist/model/getSearchesCountResponse.d.ts +12 -0
  36. package/dist/model/getSearchesCountResponse.d.ts.map +1 -0
  37. package/dist/model/getSearchesNoClicksResponse.d.ts +8 -0
  38. package/dist/model/getSearchesNoClicksResponse.d.ts.map +1 -0
  39. package/dist/model/getSearchesNoResultsResponse.d.ts +8 -0
  40. package/dist/model/getSearchesNoResultsResponse.d.ts.map +1 -0
  41. package/dist/model/getStatusResponse.d.ts +7 -0
  42. package/dist/model/getStatusResponse.d.ts.map +1 -0
  43. package/dist/model/getTopCountriesResponse.d.ts +8 -0
  44. package/dist/model/getTopCountriesResponse.d.ts.map +1 -0
  45. package/dist/model/getTopFilterAttribute.d.ts +11 -0
  46. package/dist/model/getTopFilterAttribute.d.ts.map +1 -0
  47. package/dist/model/getTopFilterAttributesResponse.d.ts +8 -0
  48. package/dist/model/getTopFilterAttributesResponse.d.ts.map +1 -0
  49. package/dist/model/getTopFilterForAttribute.d.ts +19 -0
  50. package/dist/model/getTopFilterForAttribute.d.ts.map +1 -0
  51. package/dist/model/getTopFilterForAttributeResponse.d.ts +8 -0
  52. package/dist/model/getTopFilterForAttributeResponse.d.ts.map +1 -0
  53. package/dist/model/getTopFiltersNoResultsResponse.d.ts +8 -0
  54. package/dist/model/getTopFiltersNoResultsResponse.d.ts.map +1 -0
  55. package/dist/model/getTopFiltersNoResultsValue.d.ts +15 -0
  56. package/dist/model/getTopFiltersNoResultsValue.d.ts.map +1 -0
  57. package/dist/model/getTopFiltersNoResultsValues.d.ts +12 -0
  58. package/dist/model/getTopFiltersNoResultsValues.d.ts.map +1 -0
  59. package/dist/model/getTopHitsResponse.d.ts +4 -0
  60. package/dist/model/getTopHitsResponse.d.ts.map +1 -0
  61. package/dist/model/getTopSearchesResponse.d.ts +4 -0
  62. package/dist/model/getTopSearchesResponse.d.ts.map +1 -0
  63. package/dist/model/getUsersCountResponse.d.ts +12 -0
  64. package/dist/model/getUsersCountResponse.d.ts.map +1 -0
  65. package/dist/model/index.d.ts +45 -0
  66. package/dist/model/index.d.ts.map +1 -0
  67. package/dist/model/noClickRateEvent.d.ts +19 -0
  68. package/dist/model/noClickRateEvent.d.ts.map +1 -0
  69. package/dist/model/noResultsRateEvent.d.ts +19 -0
  70. package/dist/model/noResultsRateEvent.d.ts.map +1 -0
  71. package/dist/model/orderBy.d.ts +2 -0
  72. package/dist/model/orderBy.d.ts.map +1 -0
  73. package/dist/model/searchEvent.d.ts +11 -0
  74. package/dist/model/searchEvent.d.ts.map +1 -0
  75. package/dist/model/searchNoClickEvent.d.ts +15 -0
  76. package/dist/model/searchNoClickEvent.d.ts.map +1 -0
  77. package/dist/model/searchNoResultEvent.d.ts +15 -0
  78. package/dist/model/searchNoResultEvent.d.ts.map +1 -0
  79. package/dist/model/topCountry.d.ts +11 -0
  80. package/dist/model/topCountry.d.ts.map +1 -0
  81. package/dist/model/topHit.d.ts +11 -0
  82. package/dist/model/topHit.d.ts.map +1 -0
  83. package/dist/model/topHitWithAnalytics.d.ts +31 -0
  84. package/dist/model/topHitWithAnalytics.d.ts.map +1 -0
  85. package/dist/model/topHitsResponse.d.ts +8 -0
  86. package/dist/model/topHitsResponse.d.ts.map +1 -0
  87. package/dist/model/topHitsResponseWithAnalytics.d.ts +8 -0
  88. package/dist/model/topHitsResponseWithAnalytics.d.ts.map +1 -0
  89. package/dist/model/topSearch.d.ts +15 -0
  90. package/dist/model/topSearch.d.ts.map +1 -0
  91. package/dist/model/topSearchWithAnalytics.d.ts +39 -0
  92. package/dist/model/topSearchWithAnalytics.d.ts.map +1 -0
  93. package/dist/model/topSearchesResponse.d.ts +8 -0
  94. package/dist/model/topSearchesResponse.d.ts.map +1 -0
  95. package/dist/model/topSearchesResponseWithAnalytics.d.ts +8 -0
  96. package/dist/model/topSearchesResponseWithAnalytics.d.ts.map +1 -0
  97. package/dist/model/userWithDate.d.ts +11 -0
  98. package/dist/model/userWithDate.d.ts.map +1 -0
  99. package/dist/src/analyticsClient.d.ts +308 -0
  100. package/dist/src/analyticsClient.d.ts.map +1 -0
  101. package/index.d.ts +2 -0
  102. package/index.js +1 -1
  103. package/model/averageClickEvent.ts +16 -0
  104. package/model/clickPosition.ts +12 -0
  105. package/model/clickThroughRateEvent.ts +20 -0
  106. package/model/clientMethodProps.ts +530 -0
  107. package/model/conversionRateEvent.ts +20 -0
  108. package/model/direction.ts +3 -0
  109. package/model/errorBase.ts +8 -0
  110. package/model/getAverageClickPositionResponse.ts +18 -0
  111. package/model/getClickPositionsResponse.ts +10 -0
  112. package/model/getClickThroughRateResponse.ts +22 -0
  113. package/model/getConversationRateResponse.ts +22 -0
  114. package/model/getNoClickRateResponse.ts +22 -0
  115. package/model/getNoResultsRateResponse.ts +22 -0
  116. package/model/getSearchesCountResponse.ts +14 -0
  117. package/model/getSearchesNoClicksResponse.ts +10 -0
  118. package/model/getSearchesNoResultsResponse.ts +10 -0
  119. package/model/getStatusResponse.ts +8 -0
  120. package/model/getTopCountriesResponse.ts +10 -0
  121. package/model/getTopFilterAttribute.ts +12 -0
  122. package/model/getTopFilterAttributesResponse.ts +10 -0
  123. package/model/getTopFilterForAttribute.ts +20 -0
  124. package/model/getTopFilterForAttributeResponse.ts +10 -0
  125. package/model/getTopFiltersNoResultsResponse.ts +10 -0
  126. package/model/getTopFiltersNoResultsValue.ts +16 -0
  127. package/model/getTopFiltersNoResultsValues.ts +14 -0
  128. package/model/getTopHitsResponse.ts +6 -0
  129. package/model/getTopSearchesResponse.ts +8 -0
  130. package/model/getUsersCountResponse.ts +14 -0
  131. package/model/index.ts +46 -0
  132. package/model/noClickRateEvent.ts +20 -0
  133. package/model/noResultsRateEvent.ts +20 -0
  134. package/model/orderBy.ts +7 -0
  135. package/model/searchEvent.ts +12 -0
  136. package/model/searchNoClickEvent.ts +16 -0
  137. package/model/searchNoResultEvent.ts +16 -0
  138. package/model/topCountry.ts +12 -0
  139. package/model/topHit.ts +12 -0
  140. package/model/topHitWithAnalytics.ts +32 -0
  141. package/model/topHitsResponse.ts +10 -0
  142. package/model/topHitsResponseWithAnalytics.ts +10 -0
  143. package/model/topSearch.ts +16 -0
  144. package/model/topSearchWithAnalytics.ts +40 -0
  145. package/model/topSearchesResponse.ts +10 -0
  146. package/model/topSearchesResponseWithAnalytics.ts +10 -0
  147. package/model/userWithDate.ts +12 -0
  148. package/package.json +25 -14
  149. package/dist/client-analytics.d.ts +0 -233
  150. package/dist/client-analytics.esm.js +0 -71
@@ -0,0 +1,1631 @@
1
+ function createAuth(appId, apiKey, authMode = 'WithinHeaders') {
2
+ const credentials = {
3
+ 'x-algolia-api-key': apiKey,
4
+ 'x-algolia-application-id': appId
5
+ };
6
+ return {
7
+ headers() {
8
+ return authMode === 'WithinHeaders' ? credentials : {};
9
+ },
10
+
11
+ queryParameters() {
12
+ return authMode === 'WithinQueryParameters' ? credentials : {};
13
+ }
14
+
15
+ };
16
+ }
17
+
18
+ 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
+
21
+ const namespaceKey = `algolia-client-js-${options.key}`;
22
+
23
+ function getStorage() {
24
+ if (storage === undefined) {
25
+ storage = options.localStorage || window.localStorage;
26
+ }
27
+
28
+ return storage;
29
+ }
30
+
31
+ function getNamespace() {
32
+ return JSON.parse(getStorage().getItem(namespaceKey) || '{}');
33
+ }
34
+
35
+ return {
36
+ get(key, defaultValue, events = {
37
+ miss: () => Promise.resolve()
38
+ }) {
39
+ return Promise.resolve().then(() => {
40
+ const keyAsString = JSON.stringify(key);
41
+ const value = getNamespace()[keyAsString];
42
+ return Promise.all([value || defaultValue(), value !== undefined]);
43
+ }).then(([value, exists]) => {
44
+ return Promise.all([value, exists || events.miss(value)]);
45
+ }).then(([value]) => value);
46
+ },
47
+
48
+ set(key, value) {
49
+ return Promise.resolve().then(() => {
50
+ const namespace = getNamespace();
51
+ namespace[JSON.stringify(key)] = value;
52
+ getStorage().setItem(namespaceKey, JSON.stringify(namespace));
53
+ return value;
54
+ });
55
+ },
56
+
57
+ delete(key) {
58
+ return Promise.resolve().then(() => {
59
+ const namespace = getNamespace();
60
+ delete namespace[JSON.stringify(key)];
61
+ getStorage().setItem(namespaceKey, JSON.stringify(namespace));
62
+ });
63
+ },
64
+
65
+ clear() {
66
+ return Promise.resolve().then(() => {
67
+ getStorage().removeItem(namespaceKey);
68
+ });
69
+ }
70
+
71
+ };
72
+ }
73
+
74
+ function createNullCache() {
75
+ return {
76
+ get(_key, defaultValue, events = {
77
+ miss: () => Promise.resolve()
78
+ }) {
79
+ const value = defaultValue();
80
+ return value.then(result => Promise.all([result, events.miss(result)])).then(([result]) => result);
81
+ },
82
+
83
+ set(_key, value) {
84
+ return Promise.resolve(value);
85
+ },
86
+
87
+ delete(_key) {
88
+ return Promise.resolve();
89
+ },
90
+
91
+ clear() {
92
+ return Promise.resolve();
93
+ }
94
+
95
+ };
96
+ }
97
+
98
+ function createFallbackableCache(options) {
99
+ const caches = [...options.caches];
100
+ const current = caches.shift();
101
+
102
+ if (current === undefined) {
103
+ return createNullCache();
104
+ }
105
+
106
+ return {
107
+ get(key, defaultValue, events = {
108
+ miss: () => Promise.resolve()
109
+ }) {
110
+ return current.get(key, defaultValue, events).catch(() => {
111
+ return createFallbackableCache({
112
+ caches
113
+ }).get(key, defaultValue, events);
114
+ });
115
+ },
116
+
117
+ set(key, value) {
118
+ return current.set(key, value).catch(() => {
119
+ return createFallbackableCache({
120
+ caches
121
+ }).set(key, value);
122
+ });
123
+ },
124
+
125
+ delete(key) {
126
+ return current.delete(key).catch(() => {
127
+ return createFallbackableCache({
128
+ caches
129
+ }).delete(key);
130
+ });
131
+ },
132
+
133
+ clear() {
134
+ return current.clear().catch(() => {
135
+ return createFallbackableCache({
136
+ caches
137
+ }).clear();
138
+ });
139
+ }
140
+
141
+ };
142
+ }
143
+
144
+ function createMemoryCache(options = {
145
+ serializable: true
146
+ }) {
147
+ let cache = {};
148
+ return {
149
+ get(key, defaultValue, events = {
150
+ miss: () => Promise.resolve()
151
+ }) {
152
+ const keyAsString = JSON.stringify(key);
153
+
154
+ if (keyAsString in cache) {
155
+ return Promise.resolve(options.serializable ? JSON.parse(cache[keyAsString]) : cache[keyAsString]);
156
+ }
157
+
158
+ const promise = defaultValue();
159
+ return promise.then(value => events.miss(value)).then(() => promise);
160
+ },
161
+
162
+ set(key, value) {
163
+ cache[JSON.stringify(key)] = options.serializable ? JSON.stringify(value) : value;
164
+ return Promise.resolve(value);
165
+ },
166
+
167
+ delete(key) {
168
+ delete cache[JSON.stringify(key)];
169
+ return Promise.resolve();
170
+ },
171
+
172
+ clear() {
173
+ cache = {};
174
+ return Promise.resolve();
175
+ }
176
+
177
+ };
178
+ }
179
+
180
+ // By default, API Clients at Algolia have expiration delay of 5 mins.
181
+ // In the JavaScript client, we have 2 mins.
182
+ const EXPIRATION_DELAY = 2 * 60 * 1000;
183
+ function createStatefulHost(host, status = 'up') {
184
+ const lastUpdate = Date.now();
185
+
186
+ function isUp() {
187
+ return status === 'up' || Date.now() - lastUpdate > EXPIRATION_DELAY;
188
+ }
189
+
190
+ function isTimedOut() {
191
+ return status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY;
192
+ }
193
+
194
+ return { ...host,
195
+ status,
196
+ lastUpdate,
197
+ isUp,
198
+ isTimedOut
199
+ };
200
+ }
201
+
202
+ function _defineProperty(obj, key, value) {
203
+ if (key in obj) {
204
+ Object.defineProperty(obj, key, {
205
+ value: value,
206
+ enumerable: true,
207
+ configurable: true,
208
+ writable: true
209
+ });
210
+ } else {
211
+ obj[key] = value;
212
+ }
213
+
214
+ return obj;
215
+ }
216
+
217
+ class AlgoliaError extends Error {
218
+ constructor(message, name) {
219
+ super(message);
220
+
221
+ _defineProperty(this, "name", 'AlgoliaError');
222
+
223
+ if (name) {
224
+ this.name = name;
225
+ }
226
+ }
227
+
228
+ }
229
+ class ErrorWithStackTrace extends AlgoliaError {
230
+ 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
+
233
+ _defineProperty(this, "stackTrace", void 0);
234
+
235
+ this.stackTrace = stackTrace;
236
+ }
237
+
238
+ }
239
+ class RetryError extends ErrorWithStackTrace {
240
+ constructor(stackTrace) {
241
+ super('Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.', stackTrace, 'RetryError');
242
+ }
243
+
244
+ }
245
+ class ApiError extends ErrorWithStackTrace {
246
+ constructor(message, status, stackTrace) {
247
+ super(message, stackTrace, 'ApiError');
248
+
249
+ _defineProperty(this, "status", void 0);
250
+
251
+ this.status = status;
252
+ }
253
+
254
+ }
255
+ class DeserializationError extends AlgoliaError {
256
+ constructor(message, response) {
257
+ super(message, 'DeserializationError');
258
+
259
+ _defineProperty(this, "response", void 0);
260
+
261
+ this.response = response;
262
+ }
263
+
264
+ }
265
+ function serializeUrl(host, path, queryParameters) {
266
+ const queryParametersAsString = serializeQueryParameters(queryParameters);
267
+ let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`;
268
+
269
+ if (queryParametersAsString.length) {
270
+ url += `?${queryParametersAsString}`;
271
+ }
272
+
273
+ return url;
274
+ }
275
+ function serializeQueryParameters(parameters) {
276
+ 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('&');
279
+ }
280
+ function serializeData(request, requestOptions) {
281
+ if (request.method === 'GET' || request.data === undefined && requestOptions.data === undefined) {
282
+ return undefined;
283
+ }
284
+
285
+ const data = Array.isArray(request.data) ? request.data : { ...request.data,
286
+ ...requestOptions.data
287
+ };
288
+ return JSON.stringify(data);
289
+ }
290
+ function serializeHeaders(baseHeaders, requestHeaders, requestOptionsHeaders) {
291
+ const headers = {
292
+ Accept: 'application/json',
293
+ ...baseHeaders,
294
+ ...requestHeaders,
295
+ ...requestOptionsHeaders
296
+ };
297
+ const serializedHeaders = {};
298
+ Object.keys(headers).forEach(header => {
299
+ const value = headers[header];
300
+ serializedHeaders[header.toLowerCase()] = value;
301
+ });
302
+ return serializedHeaders;
303
+ }
304
+ function deserializeSuccess(response) {
305
+ try {
306
+ return JSON.parse(response.content);
307
+ } catch (e) {
308
+ throw new DeserializationError(e.message, response);
309
+ }
310
+ }
311
+ function deserializeFailure({
312
+ content,
313
+ status
314
+ }, stackFrame) {
315
+ let message = content;
316
+
317
+ try {
318
+ message = JSON.parse(content).message;
319
+ } catch (e) {// ..
320
+ }
321
+
322
+ return new ApiError(message, status, stackFrame);
323
+ }
324
+
325
+ function isNetworkError({
326
+ isTimedOut,
327
+ status
328
+ }) {
329
+ return !isTimedOut && ~~status === 0;
330
+ }
331
+ function isRetryable({
332
+ isTimedOut,
333
+ status
334
+ }) {
335
+ return isTimedOut || isNetworkError({
336
+ isTimedOut,
337
+ status
338
+ }) || ~~(status / 100) !== 2 && ~~(status / 100) !== 4;
339
+ }
340
+ function isSuccess({
341
+ status
342
+ }) {
343
+ return ~~(status / 100) === 2;
344
+ }
345
+
346
+ function stackTraceWithoutCredentials(stackTrace) {
347
+ return stackTrace.map(stackFrame => stackFrameWithoutCredentials(stackFrame));
348
+ }
349
+ function stackFrameWithoutCredentials(stackFrame) {
350
+ const modifiedHeaders = stackFrame.request.headers['x-algolia-api-key'] ? {
351
+ 'x-algolia-api-key': '*****'
352
+ } : {};
353
+ return { ...stackFrame,
354
+ request: { ...stackFrame.request,
355
+ headers: { ...stackFrame.request.headers,
356
+ ...modifiedHeaders
357
+ }
358
+ }
359
+ };
360
+ }
361
+
362
+ function createTransporter({
363
+ hosts,
364
+ hostsCache,
365
+ baseHeaders,
366
+ baseQueryParameters,
367
+ algoliaAgent,
368
+ timeouts,
369
+ requester,
370
+ requestsCache,
371
+ responsesCache
372
+ }) {
373
+ async function createRetryableOptions(compatibleHosts) {
374
+ const statefulHosts = await Promise.all(compatibleHosts.map(compatibleHost => {
375
+ return hostsCache.get(compatibleHost, () => {
376
+ return Promise.resolve(createStatefulHost(compatibleHost));
377
+ });
378
+ }));
379
+ 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
+
382
+ const hostsAvailable = [...hostsUp, ...hostsTimedOut];
383
+ const compatibleHostsAvailable = hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;
384
+ return {
385
+ hosts: compatibleHostsAvailable,
386
+
387
+ 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.
398
+ */
399
+ const timeoutMultiplier = hostsTimedOut.length === 0 && timeoutsCount === 0 ? 1 : hostsTimedOut.length + 3 + timeoutsCount;
400
+ return timeoutMultiplier * baseTimeout;
401
+ }
402
+
403
+ };
404
+ }
405
+
406
+ async function retryableRequest(request, requestOptions, isRead = true) {
407
+ const stackTrace = [];
408
+ /**
409
+ * First we prepare the payload that do not depend from hosts.
410
+ */
411
+
412
+ 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,
416
+ ...requestOptions.data
417
+ } : {};
418
+ const queryParameters = {
419
+ 'x-algolia-agent': algoliaAgent.value,
420
+ ...baseQueryParameters,
421
+ ...request.queryParameters,
422
+ ...dataQueryParameters
423
+ };
424
+
425
+ if (requestOptions && requestOptions.queryParameters) {
426
+ for (const key of Object.keys(requestOptions.queryParameters)) {
427
+ // We want to keep `undefined` and `null` values,
428
+ // but also avoid stringifying `object`s, as they are
429
+ // handled in the `serializeUrl` step right after.
430
+ if (!requestOptions.queryParameters[key] || Object.prototype.toString.call(requestOptions.queryParameters[key]) === '[object Object]') {
431
+ queryParameters[key] = requestOptions.queryParameters[key];
432
+ } else {
433
+ queryParameters[key] = requestOptions.queryParameters[key].toString();
434
+ }
435
+ }
436
+ }
437
+
438
+ let timeoutsCount = 0;
439
+
440
+ const retry = async (retryableHosts, getTimeout) => {
441
+ /**
442
+ * We iterate on each host, until there is no host left.
443
+ */
444
+ const host = retryableHosts.pop();
445
+
446
+ if (host === undefined) {
447
+ throw new RetryError(stackTraceWithoutCredentials(stackTrace));
448
+ }
449
+
450
+ let responseTimeout = requestOptions.timeout;
451
+
452
+ if (responseTimeout === undefined) {
453
+ responseTimeout = isRead ? timeouts.read : timeouts.write;
454
+ }
455
+
456
+ const payload = {
457
+ data,
458
+ headers,
459
+ method: request.method,
460
+ url: serializeUrl(host, request.path, queryParameters),
461
+ connectTimeout: getTimeout(timeoutsCount, timeouts.connect),
462
+ responseTimeout: getTimeout(timeoutsCount, responseTimeout)
463
+ };
464
+ /**
465
+ * The stackFrame is pushed to the stackTrace so we
466
+ * can have information about onRetry and onFailure
467
+ * decisions.
468
+ */
469
+
470
+ const pushToStackTrace = response => {
471
+ const stackFrame = {
472
+ request: payload,
473
+ response,
474
+ host,
475
+ triesLeft: retryableHosts.length
476
+ };
477
+ stackTrace.push(stackFrame);
478
+ return stackFrame;
479
+ };
480
+
481
+ const response = await requester.send(payload);
482
+
483
+ if (isRetryable(response)) {
484
+ const stackFrame = pushToStackTrace(response); // If response is a timeout, we increase the number of timeouts so we can increase the timeout later.
485
+
486
+ if (response.isTimedOut) {
487
+ timeoutsCount++;
488
+ }
489
+ /**
490
+ * Failures are individually sent to the logger, allowing
491
+ * the end user to debug / store stack frames even
492
+ * when a retry error does not happen.
493
+ */
494
+ // eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
495
+
496
+
497
+ console.log('Retryable failure', stackFrameWithoutCredentials(stackFrame));
498
+ /**
499
+ * We also store the state of the host in failure cases. If the host, is
500
+ * down it will remain down for the next 2 minutes. In a timeout situation,
501
+ * this host will be added end of the list of hosts on the next request.
502
+ */
503
+
504
+ await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));
505
+ return retry(retryableHosts, getTimeout);
506
+ }
507
+
508
+ if (isSuccess(response)) {
509
+ return deserializeSuccess(response);
510
+ }
511
+
512
+ pushToStackTrace(response);
513
+ throw deserializeFailure(response, stackTrace);
514
+ };
515
+ /**
516
+ * Finally, for each retryable host perform request until we got a non
517
+ * retryable response. Some notes here:
518
+ *
519
+ * 1. The reverse here is applied so we can apply a `pop` later on => more performant.
520
+ * 2. We also get from the retryable options a timeout multiplier that is tailored
521
+ * for the current context.
522
+ */
523
+
524
+
525
+ const compatibleHosts = hosts.filter(host => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'));
526
+ const options = await createRetryableOptions(compatibleHosts);
527
+ return retry([...options.hosts].reverse(), options.getTimeout);
528
+ }
529
+
530
+ function createRequest(request, requestOptions = {}) {
531
+ /**
532
+ * A read request is either a `GET` request, or a request that we make
533
+ * via the `read` transporter (e.g. `search`).
534
+ */
535
+ const isRead = request.useReadTransporter || request.method === 'GET';
536
+
537
+ if (!isRead) {
538
+ /**
539
+ * On write requests, no cache mechanisms are applied, and we
540
+ * proxy the request immediately to the requester.
541
+ */
542
+ return retryableRequest(request, requestOptions, isRead);
543
+ }
544
+
545
+ const createRetryableRequest = () => {
546
+ /**
547
+ * Then, we prepare a function factory that contains the construction of
548
+ * the retryable request. At this point, we may *not* perform the actual
549
+ * request. But we want to have the function factory ready.
550
+ */
551
+ return retryableRequest(request, requestOptions);
552
+ };
553
+ /**
554
+ * Once we have the function factory ready, we need to determine of the
555
+ * request is "cacheable" - should be cached. Note that, once again,
556
+ * the user can force this option.
557
+ */
558
+
559
+
560
+ const cacheable = requestOptions.cacheable || request.cacheable;
561
+ /**
562
+ * If is not "cacheable", we immediately trigger the retryable request, no
563
+ * need to check cache implementations.
564
+ */
565
+
566
+ if (cacheable !== true) {
567
+ return createRetryableRequest();
568
+ }
569
+ /**
570
+ * If the request is "cacheable", we need to first compute the key to ask
571
+ * the cache implementations if this request is on progress or if the
572
+ * response already exists on the cache.
573
+ */
574
+
575
+
576
+ const key = {
577
+ request,
578
+ requestOptions,
579
+ transporter: {
580
+ queryParameters: baseQueryParameters,
581
+ headers: baseHeaders
582
+ }
583
+ };
584
+ /**
585
+ * With the computed key, we first ask the responses cache
586
+ * implementation if this request was been resolved before.
587
+ */
588
+
589
+ return responsesCache.get(key, () => {
590
+ /**
591
+ * If the request has never resolved before, we actually ask if there
592
+ * is a current request with the same key on progress.
593
+ */
594
+ return requestsCache.get(key, () =>
595
+ /**
596
+ * Finally, if there is no request in progress with the same key,
597
+ * this `createRetryableRequest()` will actually trigger the
598
+ * retryable request.
599
+ */
600
+ requestsCache.set(key, createRetryableRequest()).then(response => Promise.all([requestsCache.delete(key), response]), err => Promise.all([requestsCache.delete(key), Promise.reject(err)])).then(([_, response]) => response));
601
+ }, {
602
+ /**
603
+ * Of course, once we get this response back from the server, we
604
+ * tell response cache to actually store the received response
605
+ * to be used later.
606
+ */
607
+ miss: response => responsesCache.set(key, response)
608
+ });
609
+ }
610
+
611
+ return {
612
+ hostsCache,
613
+ requester,
614
+ timeouts,
615
+ algoliaAgent,
616
+ baseHeaders,
617
+ baseQueryParameters,
618
+ hosts,
619
+ request: createRequest,
620
+ requestsCache,
621
+ responsesCache
622
+ };
623
+ }
624
+
625
+ function createAlgoliaAgent(version) {
626
+ const algoliaAgent = {
627
+ value: `Algolia for JavaScript (${version})`,
628
+
629
+ add(options) {
630
+ const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;
631
+
632
+ if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
633
+ algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
634
+ }
635
+
636
+ return algoliaAgent;
637
+ }
638
+
639
+ };
640
+ return algoliaAgent;
641
+ }
642
+
643
+ function getAlgoliaAgent({
644
+ algoliaAgents,
645
+ client,
646
+ version
647
+ }) {
648
+ const defaultAlgoliaAgent = createAlgoliaAgent(version).add({
649
+ segment: client,
650
+ version
651
+ });
652
+ algoliaAgents.forEach(algoliaAgent => defaultAlgoliaAgent.add(algoliaAgent));
653
+ return defaultAlgoliaAgent;
654
+ }
655
+
656
+ const DEFAULT_CONNECT_TIMEOUT_BROWSER = 1000;
657
+ const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
658
+ const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
659
+
660
+ function createXhrRequester() {
661
+ function send(request) {
662
+ return new Promise((resolve) => {
663
+ const baseRequester = new XMLHttpRequest();
664
+ baseRequester.open(request.method, request.url, true);
665
+ Object.keys(request.headers).forEach((key) => baseRequester.setRequestHeader(key, request.headers[key]));
666
+ const createTimeout = (timeout, content) => {
667
+ return setTimeout(() => {
668
+ baseRequester.abort();
669
+ resolve({
670
+ status: 0,
671
+ content,
672
+ isTimedOut: true,
673
+ });
674
+ }, timeout);
675
+ };
676
+ const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
677
+ let responseTimeout;
678
+ baseRequester.onreadystatechange = () => {
679
+ if (baseRequester.readyState > baseRequester.OPENED &&
680
+ responseTimeout === undefined) {
681
+ clearTimeout(connectTimeout);
682
+ responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
683
+ }
684
+ };
685
+ baseRequester.onerror = () => {
686
+ // istanbul ignore next
687
+ if (baseRequester.status === 0) {
688
+ clearTimeout(connectTimeout);
689
+ clearTimeout(responseTimeout);
690
+ resolve({
691
+ content: baseRequester.responseText || 'Network request failed',
692
+ status: baseRequester.status,
693
+ isTimedOut: false,
694
+ });
695
+ }
696
+ };
697
+ baseRequester.onload = () => {
698
+ clearTimeout(connectTimeout);
699
+ clearTimeout(responseTimeout);
700
+ resolve({
701
+ content: baseRequester.responseText,
702
+ status: baseRequester.status,
703
+ isTimedOut: false,
704
+ });
705
+ };
706
+ baseRequester.send(request.data);
707
+ });
708
+ }
709
+ return { send };
710
+ }
711
+
712
+ // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
713
+ const apiClientVersion = '5.0.0-alpha.1';
714
+ const REGIONS = ['de', 'us'];
715
+ function getDefaultHosts(region) {
716
+ const url = !region
717
+ ? 'analytics.algolia.com'
718
+ : 'analytics.{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 createAnalyticsClient({ 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: 'Analytics',
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
+ * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
746
+ */
747
+ get _ua() {
748
+ return transporter.algoliaAgent.value;
749
+ },
750
+ /**
751
+ * Adds a `segment` to the `x-algolia-agent` sent with every requests.
752
+ *
753
+ * @param segment - The algolia agent (user-agent) segment to add.
754
+ * @param version - The version of the agent.
755
+ */
756
+ addAlgoliaAgent(segment, version) {
757
+ transporter.algoliaAgent.add({ segment, version });
758
+ },
759
+ /**
760
+ * This method allow you to send requests to the Algolia REST API.
761
+ *
762
+ * @summary Send requests to the Algolia REST API.
763
+ * @param del - The del object.
764
+ * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
765
+ * @param del.parameters - Query parameters to be applied to the current query.
766
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
767
+ */
768
+ del({ path, parameters }, requestOptions) {
769
+ if (!path) {
770
+ throw new Error('Parameter `path` is required when calling `del`.');
771
+ }
772
+ const requestPath = '/1{path}'.replace('{path}', path);
773
+ const headers = {};
774
+ const queryParameters = parameters ? parameters : {};
775
+ const request = {
776
+ method: 'DELETE',
777
+ path: requestPath,
778
+ queryParameters,
779
+ headers,
780
+ };
781
+ return transporter.request(request, requestOptions);
782
+ },
783
+ /**
784
+ * This method allow you to send requests to the Algolia REST API.
785
+ *
786
+ * @summary Send requests to the Algolia REST API.
787
+ * @param get - The get object.
788
+ * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
789
+ * @param get.parameters - Query parameters to be applied to the current query.
790
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
791
+ */
792
+ get({ path, parameters }, requestOptions) {
793
+ if (!path) {
794
+ throw new Error('Parameter `path` is required when calling `get`.');
795
+ }
796
+ const requestPath = '/1{path}'.replace('{path}', path);
797
+ const headers = {};
798
+ const queryParameters = parameters ? parameters : {};
799
+ const request = {
800
+ method: 'GET',
801
+ path: requestPath,
802
+ queryParameters,
803
+ headers,
804
+ };
805
+ return transporter.request(request, requestOptions);
806
+ },
807
+ /**
808
+ * Returns the average click position. The endpoint returns a value for the complete given time range, as well as a value per day.
809
+ *
810
+ * @summary Get average click position.
811
+ * @param getAverageClickPosition - The getAverageClickPosition object.
812
+ * @param getAverageClickPosition.index - The index name to target.
813
+ * @param getAverageClickPosition.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
814
+ * @param getAverageClickPosition.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
815
+ * @param getAverageClickPosition.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
816
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
817
+ */
818
+ getAverageClickPosition({ index, startDate, endDate, tags }, requestOptions) {
819
+ if (!index) {
820
+ throw new Error('Parameter `index` is required when calling `getAverageClickPosition`.');
821
+ }
822
+ const requestPath = '/2/clicks/averageClickPosition';
823
+ const headers = {};
824
+ const queryParameters = {};
825
+ if (index !== undefined) {
826
+ queryParameters.index = index.toString();
827
+ }
828
+ if (startDate !== undefined) {
829
+ queryParameters.startDate = startDate.toString();
830
+ }
831
+ if (endDate !== undefined) {
832
+ queryParameters.endDate = endDate.toString();
833
+ }
834
+ if (tags !== undefined) {
835
+ queryParameters.tags = tags.toString();
836
+ }
837
+ const request = {
838
+ method: 'GET',
839
+ path: requestPath,
840
+ queryParameters,
841
+ headers,
842
+ };
843
+ return transporter.request(request, requestOptions);
844
+ },
845
+ /**
846
+ * Returns the distribution of clicks per range of positions. If the groups all have a count of 0, it means Algolia didn’t receive any click events for the queries with the clickAnalytics search parameter set to true. The count is 0 until Algolia receives at least one click event.
847
+ *
848
+ * @summary Get clicks per positions.
849
+ * @param getClickPositions - The getClickPositions object.
850
+ * @param getClickPositions.index - The index name to target.
851
+ * @param getClickPositions.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
852
+ * @param getClickPositions.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
853
+ * @param getClickPositions.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
854
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
855
+ */
856
+ getClickPositions({ index, startDate, endDate, tags }, requestOptions) {
857
+ if (!index) {
858
+ throw new Error('Parameter `index` is required when calling `getClickPositions`.');
859
+ }
860
+ const requestPath = '/2/clicks/positions';
861
+ const headers = {};
862
+ const queryParameters = {};
863
+ if (index !== undefined) {
864
+ queryParameters.index = index.toString();
865
+ }
866
+ if (startDate !== undefined) {
867
+ queryParameters.startDate = startDate.toString();
868
+ }
869
+ if (endDate !== undefined) {
870
+ queryParameters.endDate = endDate.toString();
871
+ }
872
+ if (tags !== undefined) {
873
+ queryParameters.tags = tags.toString();
874
+ }
875
+ const request = {
876
+ method: 'GET',
877
+ path: requestPath,
878
+ queryParameters,
879
+ headers,
880
+ };
881
+ return transporter.request(request, requestOptions);
882
+ },
883
+ /**
884
+ * Returns a click-through rate (CTR). The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of clicks and searches used to compute the rates.
885
+ *
886
+ * @summary Get click-through rate (CTR).
887
+ * @param getClickThroughRate - The getClickThroughRate object.
888
+ * @param getClickThroughRate.index - The index name to target.
889
+ * @param getClickThroughRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
890
+ * @param getClickThroughRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
891
+ * @param getClickThroughRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
892
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
893
+ */
894
+ getClickThroughRate({ index, startDate, endDate, tags }, requestOptions) {
895
+ if (!index) {
896
+ throw new Error('Parameter `index` is required when calling `getClickThroughRate`.');
897
+ }
898
+ const requestPath = '/2/clicks/clickThroughRate';
899
+ const headers = {};
900
+ const queryParameters = {};
901
+ if (index !== undefined) {
902
+ queryParameters.index = index.toString();
903
+ }
904
+ if (startDate !== undefined) {
905
+ queryParameters.startDate = startDate.toString();
906
+ }
907
+ if (endDate !== undefined) {
908
+ queryParameters.endDate = endDate.toString();
909
+ }
910
+ if (tags !== undefined) {
911
+ queryParameters.tags = tags.toString();
912
+ }
913
+ const request = {
914
+ method: 'GET',
915
+ path: requestPath,
916
+ queryParameters,
917
+ headers,
918
+ };
919
+ return transporter.request(request, requestOptions);
920
+ },
921
+ /**
922
+ * Returns a conversion rate (CR). The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of conversion and searches used to compute the rates.
923
+ *
924
+ * @summary Get conversion rate (CR).
925
+ * @param getConversationRate - The getConversationRate object.
926
+ * @param getConversationRate.index - The index name to target.
927
+ * @param getConversationRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
928
+ * @param getConversationRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
929
+ * @param getConversationRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
930
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
931
+ */
932
+ getConversationRate({ index, startDate, endDate, tags }, requestOptions) {
933
+ if (!index) {
934
+ throw new Error('Parameter `index` is required when calling `getConversationRate`.');
935
+ }
936
+ const requestPath = '/2/conversions/conversionRate';
937
+ const headers = {};
938
+ const queryParameters = {};
939
+ if (index !== undefined) {
940
+ queryParameters.index = index.toString();
941
+ }
942
+ if (startDate !== undefined) {
943
+ queryParameters.startDate = startDate.toString();
944
+ }
945
+ if (endDate !== undefined) {
946
+ queryParameters.endDate = endDate.toString();
947
+ }
948
+ if (tags !== undefined) {
949
+ queryParameters.tags = tags.toString();
950
+ }
951
+ const request = {
952
+ method: 'GET',
953
+ path: requestPath,
954
+ queryParameters,
955
+ headers,
956
+ };
957
+ return transporter.request(request, requestOptions);
958
+ },
959
+ /**
960
+ * Returns the rate at which searches didn\'t lead to any clicks. The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of searches and searches without clicks.
961
+ *
962
+ * @summary Get no click rate.
963
+ * @param getNoClickRate - The getNoClickRate object.
964
+ * @param getNoClickRate.index - The index name to target.
965
+ * @param getNoClickRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
966
+ * @param getNoClickRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
967
+ * @param getNoClickRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
968
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
969
+ */
970
+ getNoClickRate({ index, startDate, endDate, tags }, requestOptions) {
971
+ if (!index) {
972
+ throw new Error('Parameter `index` is required when calling `getNoClickRate`.');
973
+ }
974
+ const requestPath = '/2/searches/noClickRate';
975
+ const headers = {};
976
+ const queryParameters = {};
977
+ if (index !== undefined) {
978
+ queryParameters.index = index.toString();
979
+ }
980
+ if (startDate !== undefined) {
981
+ queryParameters.startDate = startDate.toString();
982
+ }
983
+ if (endDate !== undefined) {
984
+ queryParameters.endDate = endDate.toString();
985
+ }
986
+ if (tags !== undefined) {
987
+ queryParameters.tags = tags.toString();
988
+ }
989
+ const request = {
990
+ method: 'GET',
991
+ path: requestPath,
992
+ queryParameters,
993
+ headers,
994
+ };
995
+ return transporter.request(request, requestOptions);
996
+ },
997
+ /**
998
+ * Returns the rate at which searches didn\'t return any results. The endpoint returns a value for the complete given time range, as well as a value per day. It also returns the count of searches and searches without results used to compute the rates.
999
+ *
1000
+ * @summary Get no results rate.
1001
+ * @param getNoResultsRate - The getNoResultsRate object.
1002
+ * @param getNoResultsRate.index - The index name to target.
1003
+ * @param getNoResultsRate.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1004
+ * @param getNoResultsRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1005
+ * @param getNoResultsRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1006
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1007
+ */
1008
+ getNoResultsRate({ index, startDate, endDate, tags }, requestOptions) {
1009
+ if (!index) {
1010
+ throw new Error('Parameter `index` is required when calling `getNoResultsRate`.');
1011
+ }
1012
+ const requestPath = '/2/searches/noResultRate';
1013
+ const headers = {};
1014
+ const queryParameters = {};
1015
+ if (index !== undefined) {
1016
+ queryParameters.index = index.toString();
1017
+ }
1018
+ if (startDate !== undefined) {
1019
+ queryParameters.startDate = startDate.toString();
1020
+ }
1021
+ if (endDate !== undefined) {
1022
+ queryParameters.endDate = endDate.toString();
1023
+ }
1024
+ if (tags !== undefined) {
1025
+ queryParameters.tags = tags.toString();
1026
+ }
1027
+ const request = {
1028
+ method: 'GET',
1029
+ path: requestPath,
1030
+ queryParameters,
1031
+ headers,
1032
+ };
1033
+ return transporter.request(request, requestOptions);
1034
+ },
1035
+ /**
1036
+ * Returns the number of searches across the given time range. The endpoint returns a value for the complete given time range, as well as a value per day.
1037
+ *
1038
+ * @summary Get searches count.
1039
+ * @param getSearchesCount - The getSearchesCount object.
1040
+ * @param getSearchesCount.index - The index name to target.
1041
+ * @param getSearchesCount.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1042
+ * @param getSearchesCount.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1043
+ * @param getSearchesCount.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1044
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1045
+ */
1046
+ getSearchesCount({ index, startDate, endDate, tags }, requestOptions) {
1047
+ if (!index) {
1048
+ throw new Error('Parameter `index` is required when calling `getSearchesCount`.');
1049
+ }
1050
+ const requestPath = '/2/searches/count';
1051
+ const headers = {};
1052
+ const queryParameters = {};
1053
+ if (index !== undefined) {
1054
+ queryParameters.index = index.toString();
1055
+ }
1056
+ if (startDate !== undefined) {
1057
+ queryParameters.startDate = startDate.toString();
1058
+ }
1059
+ if (endDate !== undefined) {
1060
+ queryParameters.endDate = endDate.toString();
1061
+ }
1062
+ if (tags !== undefined) {
1063
+ queryParameters.tags = tags.toString();
1064
+ }
1065
+ const request = {
1066
+ method: 'GET',
1067
+ path: requestPath,
1068
+ queryParameters,
1069
+ headers,
1070
+ };
1071
+ return transporter.request(request, requestOptions);
1072
+ },
1073
+ /**
1074
+ * Returns top searches that didn\'t lead to any clicks. Limited to the 1000 most frequent ones. For each search, also returns the average number of found hits.
1075
+ *
1076
+ * @summary Get top searches with no clicks.
1077
+ * @param getSearchesNoClicks - The getSearchesNoClicks object.
1078
+ * @param getSearchesNoClicks.index - The index name to target.
1079
+ * @param getSearchesNoClicks.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1080
+ * @param getSearchesNoClicks.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1081
+ * @param getSearchesNoClicks.limit - Number of records to return. Limit is the size of the page.
1082
+ * @param getSearchesNoClicks.offset - Position of the starting record. Used for paging. 0 is the first record.
1083
+ * @param getSearchesNoClicks.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1084
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1085
+ */
1086
+ getSearchesNoClicks({ index, startDate, endDate, limit, offset, tags, }, requestOptions) {
1087
+ if (!index) {
1088
+ throw new Error('Parameter `index` is required when calling `getSearchesNoClicks`.');
1089
+ }
1090
+ const requestPath = '/2/searches/noClicks';
1091
+ const headers = {};
1092
+ const queryParameters = {};
1093
+ if (index !== undefined) {
1094
+ queryParameters.index = index.toString();
1095
+ }
1096
+ if (startDate !== undefined) {
1097
+ queryParameters.startDate = startDate.toString();
1098
+ }
1099
+ if (endDate !== undefined) {
1100
+ queryParameters.endDate = endDate.toString();
1101
+ }
1102
+ if (limit !== undefined) {
1103
+ queryParameters.limit = limit.toString();
1104
+ }
1105
+ if (offset !== undefined) {
1106
+ queryParameters.offset = offset.toString();
1107
+ }
1108
+ if (tags !== undefined) {
1109
+ queryParameters.tags = tags.toString();
1110
+ }
1111
+ const request = {
1112
+ method: 'GET',
1113
+ path: requestPath,
1114
+ queryParameters,
1115
+ headers,
1116
+ };
1117
+ return transporter.request(request, requestOptions);
1118
+ },
1119
+ /**
1120
+ * Returns top searches that didn\'t return any results. Limited to the 1000 most frequent ones.
1121
+ *
1122
+ * @summary Get top searches with no results.
1123
+ * @param getSearchesNoResults - The getSearchesNoResults object.
1124
+ * @param getSearchesNoResults.index - The index name to target.
1125
+ * @param getSearchesNoResults.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1126
+ * @param getSearchesNoResults.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1127
+ * @param getSearchesNoResults.limit - Number of records to return. Limit is the size of the page.
1128
+ * @param getSearchesNoResults.offset - Position of the starting record. Used for paging. 0 is the first record.
1129
+ * @param getSearchesNoResults.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1130
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1131
+ */
1132
+ getSearchesNoResults({ index, startDate, endDate, limit, offset, tags, }, requestOptions) {
1133
+ if (!index) {
1134
+ throw new Error('Parameter `index` is required when calling `getSearchesNoResults`.');
1135
+ }
1136
+ const requestPath = '/2/searches/noResults';
1137
+ const headers = {};
1138
+ const queryParameters = {};
1139
+ if (index !== undefined) {
1140
+ queryParameters.index = index.toString();
1141
+ }
1142
+ if (startDate !== undefined) {
1143
+ queryParameters.startDate = startDate.toString();
1144
+ }
1145
+ if (endDate !== undefined) {
1146
+ queryParameters.endDate = endDate.toString();
1147
+ }
1148
+ if (limit !== undefined) {
1149
+ queryParameters.limit = limit.toString();
1150
+ }
1151
+ if (offset !== undefined) {
1152
+ queryParameters.offset = offset.toString();
1153
+ }
1154
+ if (tags !== undefined) {
1155
+ queryParameters.tags = tags.toString();
1156
+ }
1157
+ const request = {
1158
+ method: 'GET',
1159
+ path: requestPath,
1160
+ queryParameters,
1161
+ headers,
1162
+ };
1163
+ return transporter.request(request, requestOptions);
1164
+ },
1165
+ /**
1166
+ * Returns the latest update time of the analytics API for a given index. If the index has been recently created and/or no search has been performed yet the updated time will be null.
1167
+ *
1168
+ * @summary Get Analytics API status.
1169
+ * @param getStatus - The getStatus object.
1170
+ * @param getStatus.index - The index name to target.
1171
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1172
+ */
1173
+ getStatus({ index }, requestOptions) {
1174
+ if (!index) {
1175
+ throw new Error('Parameter `index` is required when calling `getStatus`.');
1176
+ }
1177
+ const requestPath = '/2/status';
1178
+ const headers = {};
1179
+ const queryParameters = {};
1180
+ if (index !== undefined) {
1181
+ queryParameters.index = index.toString();
1182
+ }
1183
+ const request = {
1184
+ method: 'GET',
1185
+ path: requestPath,
1186
+ queryParameters,
1187
+ headers,
1188
+ };
1189
+ return transporter.request(request, requestOptions);
1190
+ },
1191
+ /**
1192
+ * Returns top countries. Limited to the 1000 most frequent ones.
1193
+ *
1194
+ * @summary Get top countries.
1195
+ * @param getTopCountries - The getTopCountries object.
1196
+ * @param getTopCountries.index - The index name to target.
1197
+ * @param getTopCountries.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1198
+ * @param getTopCountries.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1199
+ * @param getTopCountries.limit - Number of records to return. Limit is the size of the page.
1200
+ * @param getTopCountries.offset - Position of the starting record. Used for paging. 0 is the first record.
1201
+ * @param getTopCountries.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1202
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1203
+ */
1204
+ getTopCountries({ index, startDate, endDate, limit, offset, tags }, requestOptions) {
1205
+ if (!index) {
1206
+ throw new Error('Parameter `index` is required when calling `getTopCountries`.');
1207
+ }
1208
+ const requestPath = '/2/countries';
1209
+ const headers = {};
1210
+ const queryParameters = {};
1211
+ if (index !== undefined) {
1212
+ queryParameters.index = index.toString();
1213
+ }
1214
+ if (startDate !== undefined) {
1215
+ queryParameters.startDate = startDate.toString();
1216
+ }
1217
+ if (endDate !== undefined) {
1218
+ queryParameters.endDate = endDate.toString();
1219
+ }
1220
+ if (limit !== undefined) {
1221
+ queryParameters.limit = limit.toString();
1222
+ }
1223
+ if (offset !== undefined) {
1224
+ queryParameters.offset = offset.toString();
1225
+ }
1226
+ if (tags !== undefined) {
1227
+ queryParameters.tags = tags.toString();
1228
+ }
1229
+ const request = {
1230
+ method: 'GET',
1231
+ path: requestPath,
1232
+ queryParameters,
1233
+ headers,
1234
+ };
1235
+ return transporter.request(request, requestOptions);
1236
+ },
1237
+ /**
1238
+ * Returns top filter attributes. Limited to the 1000 most used filters.
1239
+ *
1240
+ * @summary Get top filter attributes.
1241
+ * @param getTopFilterAttributes - The getTopFilterAttributes object.
1242
+ * @param getTopFilterAttributes.index - The index name to target.
1243
+ * @param getTopFilterAttributes.search - The query term to search for. Must match the exact user input.
1244
+ * @param getTopFilterAttributes.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1245
+ * @param getTopFilterAttributes.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1246
+ * @param getTopFilterAttributes.limit - Number of records to return. Limit is the size of the page.
1247
+ * @param getTopFilterAttributes.offset - Position of the starting record. Used for paging. 0 is the first record.
1248
+ * @param getTopFilterAttributes.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1249
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1250
+ */
1251
+ getTopFilterAttributes({ index, search, startDate, endDate, limit, offset, tags, }, requestOptions) {
1252
+ if (!index) {
1253
+ throw new Error('Parameter `index` is required when calling `getTopFilterAttributes`.');
1254
+ }
1255
+ const requestPath = '/2/filters';
1256
+ const headers = {};
1257
+ const queryParameters = {};
1258
+ if (index !== undefined) {
1259
+ queryParameters.index = index.toString();
1260
+ }
1261
+ if (search !== undefined) {
1262
+ queryParameters.search = search.toString();
1263
+ }
1264
+ if (startDate !== undefined) {
1265
+ queryParameters.startDate = startDate.toString();
1266
+ }
1267
+ if (endDate !== undefined) {
1268
+ queryParameters.endDate = endDate.toString();
1269
+ }
1270
+ if (limit !== undefined) {
1271
+ queryParameters.limit = limit.toString();
1272
+ }
1273
+ if (offset !== undefined) {
1274
+ queryParameters.offset = offset.toString();
1275
+ }
1276
+ if (tags !== undefined) {
1277
+ queryParameters.tags = tags.toString();
1278
+ }
1279
+ const request = {
1280
+ method: 'GET',
1281
+ path: requestPath,
1282
+ queryParameters,
1283
+ headers,
1284
+ };
1285
+ return transporter.request(request, requestOptions);
1286
+ },
1287
+ /**
1288
+ * Returns top filters for the given attribute. Limited to the 1000 most used filters.
1289
+ *
1290
+ * @summary Get top filters for the an attribute.
1291
+ * @param getTopFilterForAttribute - The getTopFilterForAttribute object.
1292
+ * @param getTopFilterForAttribute.attribute - The exact name of the attribute.
1293
+ * @param getTopFilterForAttribute.index - The index name to target.
1294
+ * @param getTopFilterForAttribute.search - The query term to search for. Must match the exact user input.
1295
+ * @param getTopFilterForAttribute.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1296
+ * @param getTopFilterForAttribute.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1297
+ * @param getTopFilterForAttribute.limit - Number of records to return. Limit is the size of the page.
1298
+ * @param getTopFilterForAttribute.offset - Position of the starting record. Used for paging. 0 is the first record.
1299
+ * @param getTopFilterForAttribute.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1300
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1301
+ */
1302
+ getTopFilterForAttribute({ attribute, index, search, startDate, endDate, limit, offset, tags, }, requestOptions) {
1303
+ if (!attribute) {
1304
+ throw new Error('Parameter `attribute` is required when calling `getTopFilterForAttribute`.');
1305
+ }
1306
+ if (!index) {
1307
+ throw new Error('Parameter `index` is required when calling `getTopFilterForAttribute`.');
1308
+ }
1309
+ const requestPath = '/2/filters/{attribute}'.replace('{attribute}', encodeURIComponent(attribute));
1310
+ const headers = {};
1311
+ const queryParameters = {};
1312
+ if (index !== undefined) {
1313
+ queryParameters.index = index.toString();
1314
+ }
1315
+ if (search !== undefined) {
1316
+ queryParameters.search = search.toString();
1317
+ }
1318
+ if (startDate !== undefined) {
1319
+ queryParameters.startDate = startDate.toString();
1320
+ }
1321
+ if (endDate !== undefined) {
1322
+ queryParameters.endDate = endDate.toString();
1323
+ }
1324
+ if (limit !== undefined) {
1325
+ queryParameters.limit = limit.toString();
1326
+ }
1327
+ if (offset !== undefined) {
1328
+ queryParameters.offset = offset.toString();
1329
+ }
1330
+ if (tags !== undefined) {
1331
+ queryParameters.tags = tags.toString();
1332
+ }
1333
+ const request = {
1334
+ method: 'GET',
1335
+ path: requestPath,
1336
+ queryParameters,
1337
+ headers,
1338
+ };
1339
+ return transporter.request(request, requestOptions);
1340
+ },
1341
+ /**
1342
+ * Returns top filters with no results. Limited to the 1000 most used filters.
1343
+ *
1344
+ * @summary Get top filters for a no result search.
1345
+ * @param getTopFiltersNoResults - The getTopFiltersNoResults object.
1346
+ * @param getTopFiltersNoResults.index - The index name to target.
1347
+ * @param getTopFiltersNoResults.search - The query term to search for. Must match the exact user input.
1348
+ * @param getTopFiltersNoResults.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1349
+ * @param getTopFiltersNoResults.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1350
+ * @param getTopFiltersNoResults.limit - Number of records to return. Limit is the size of the page.
1351
+ * @param getTopFiltersNoResults.offset - Position of the starting record. Used for paging. 0 is the first record.
1352
+ * @param getTopFiltersNoResults.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1353
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1354
+ */
1355
+ getTopFiltersNoResults({ index, search, startDate, endDate, limit, offset, tags, }, requestOptions) {
1356
+ if (!index) {
1357
+ throw new Error('Parameter `index` is required when calling `getTopFiltersNoResults`.');
1358
+ }
1359
+ const requestPath = '/2/filters/noResults';
1360
+ const headers = {};
1361
+ const queryParameters = {};
1362
+ if (index !== undefined) {
1363
+ queryParameters.index = index.toString();
1364
+ }
1365
+ if (search !== undefined) {
1366
+ queryParameters.search = search.toString();
1367
+ }
1368
+ if (startDate !== undefined) {
1369
+ queryParameters.startDate = startDate.toString();
1370
+ }
1371
+ if (endDate !== undefined) {
1372
+ queryParameters.endDate = endDate.toString();
1373
+ }
1374
+ if (limit !== undefined) {
1375
+ queryParameters.limit = limit.toString();
1376
+ }
1377
+ if (offset !== undefined) {
1378
+ queryParameters.offset = offset.toString();
1379
+ }
1380
+ if (tags !== undefined) {
1381
+ queryParameters.tags = tags.toString();
1382
+ }
1383
+ const request = {
1384
+ method: 'GET',
1385
+ path: requestPath,
1386
+ queryParameters,
1387
+ headers,
1388
+ };
1389
+ return transporter.request(request, requestOptions);
1390
+ },
1391
+ /**
1392
+ * Returns top hits. Limited to the 1000 most frequent ones.
1393
+ *
1394
+ * @summary Get top hits.
1395
+ * @param getTopHits - The getTopHits object.
1396
+ * @param getTopHits.index - The index name to target.
1397
+ * @param getTopHits.search - The query term to search for. Must match the exact user input.
1398
+ * @param getTopHits.clickAnalytics - Whether to include the click-through and conversion rates for a search.
1399
+ * @param getTopHits.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1400
+ * @param getTopHits.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1401
+ * @param getTopHits.limit - Number of records to return. Limit is the size of the page.
1402
+ * @param getTopHits.offset - Position of the starting record. Used for paging. 0 is the first record.
1403
+ * @param getTopHits.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1404
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1405
+ */
1406
+ getTopHits({ index, search, clickAnalytics, startDate, endDate, limit, offset, tags, }, requestOptions) {
1407
+ if (!index) {
1408
+ throw new Error('Parameter `index` is required when calling `getTopHits`.');
1409
+ }
1410
+ const requestPath = '/2/hits';
1411
+ const headers = {};
1412
+ const queryParameters = {};
1413
+ if (index !== undefined) {
1414
+ queryParameters.index = index.toString();
1415
+ }
1416
+ if (search !== undefined) {
1417
+ queryParameters.search = search.toString();
1418
+ }
1419
+ if (clickAnalytics !== undefined) {
1420
+ queryParameters.clickAnalytics = clickAnalytics.toString();
1421
+ }
1422
+ if (startDate !== undefined) {
1423
+ queryParameters.startDate = startDate.toString();
1424
+ }
1425
+ if (endDate !== undefined) {
1426
+ queryParameters.endDate = endDate.toString();
1427
+ }
1428
+ if (limit !== undefined) {
1429
+ queryParameters.limit = limit.toString();
1430
+ }
1431
+ if (offset !== undefined) {
1432
+ queryParameters.offset = offset.toString();
1433
+ }
1434
+ if (tags !== undefined) {
1435
+ queryParameters.tags = tags.toString();
1436
+ }
1437
+ const request = {
1438
+ method: 'GET',
1439
+ path: requestPath,
1440
+ queryParameters,
1441
+ headers,
1442
+ };
1443
+ return transporter.request(request, requestOptions);
1444
+ },
1445
+ /**
1446
+ * Returns top searches. Limited to the 1000 most frequent ones. For each search, also returns the average number of hits returned.
1447
+ *
1448
+ * @summary Get top searches.
1449
+ * @param getTopSearches - The getTopSearches object.
1450
+ * @param getTopSearches.index - The index name to target.
1451
+ * @param getTopSearches.clickAnalytics - Whether to include the click-through and conversion rates for a search.
1452
+ * @param getTopSearches.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1453
+ * @param getTopSearches.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1454
+ * @param getTopSearches.orderBy - Reorder the results.
1455
+ * @param getTopSearches.direction - The sorting of the result.
1456
+ * @param getTopSearches.limit - Number of records to return. Limit is the size of the page.
1457
+ * @param getTopSearches.offset - Position of the starting record. Used for paging. 0 is the first record.
1458
+ * @param getTopSearches.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1459
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1460
+ */
1461
+ getTopSearches({ index, clickAnalytics, startDate, endDate, orderBy, direction, limit, offset, tags, }, requestOptions) {
1462
+ if (!index) {
1463
+ throw new Error('Parameter `index` is required when calling `getTopSearches`.');
1464
+ }
1465
+ const requestPath = '/2/searches';
1466
+ const headers = {};
1467
+ const queryParameters = {};
1468
+ if (index !== undefined) {
1469
+ queryParameters.index = index.toString();
1470
+ }
1471
+ if (clickAnalytics !== undefined) {
1472
+ queryParameters.clickAnalytics = clickAnalytics.toString();
1473
+ }
1474
+ if (startDate !== undefined) {
1475
+ queryParameters.startDate = startDate.toString();
1476
+ }
1477
+ if (endDate !== undefined) {
1478
+ queryParameters.endDate = endDate.toString();
1479
+ }
1480
+ if (orderBy !== undefined) {
1481
+ queryParameters.orderBy = orderBy.toString();
1482
+ }
1483
+ if (direction !== undefined) {
1484
+ queryParameters.direction = direction.toString();
1485
+ }
1486
+ if (limit !== undefined) {
1487
+ queryParameters.limit = limit.toString();
1488
+ }
1489
+ if (offset !== undefined) {
1490
+ queryParameters.offset = offset.toString();
1491
+ }
1492
+ if (tags !== undefined) {
1493
+ queryParameters.tags = tags.toString();
1494
+ }
1495
+ const request = {
1496
+ method: 'GET',
1497
+ path: requestPath,
1498
+ queryParameters,
1499
+ headers,
1500
+ };
1501
+ return transporter.request(request, requestOptions);
1502
+ },
1503
+ /**
1504
+ * Returns the distinct count of users across the given time range. The endpoint returns a value for the complete given time range, as well as a value per day.
1505
+ *
1506
+ * @summary Get users count.
1507
+ * @param getUsersCount - The getUsersCount object.
1508
+ * @param getUsersCount.index - The index name to target.
1509
+ * @param getUsersCount.startDate - The lower bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1510
+ * @param getUsersCount.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze.
1511
+ * @param getUsersCount.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded.
1512
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1513
+ */
1514
+ getUsersCount({ index, startDate, endDate, tags }, requestOptions) {
1515
+ if (!index) {
1516
+ throw new Error('Parameter `index` is required when calling `getUsersCount`.');
1517
+ }
1518
+ const requestPath = '/2/users/count';
1519
+ const headers = {};
1520
+ const queryParameters = {};
1521
+ if (index !== undefined) {
1522
+ queryParameters.index = index.toString();
1523
+ }
1524
+ if (startDate !== undefined) {
1525
+ queryParameters.startDate = startDate.toString();
1526
+ }
1527
+ if (endDate !== undefined) {
1528
+ queryParameters.endDate = endDate.toString();
1529
+ }
1530
+ if (tags !== undefined) {
1531
+ queryParameters.tags = tags.toString();
1532
+ }
1533
+ const request = {
1534
+ method: 'GET',
1535
+ path: requestPath,
1536
+ queryParameters,
1537
+ headers,
1538
+ };
1539
+ return transporter.request(request, requestOptions);
1540
+ },
1541
+ /**
1542
+ * This method allow you to send requests to the Algolia REST API.
1543
+ *
1544
+ * @summary Send requests to the Algolia REST API.
1545
+ * @param post - The post object.
1546
+ * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
1547
+ * @param post.parameters - Query parameters to be applied to the current query.
1548
+ * @param post.body - The parameters to send with the custom request.
1549
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1550
+ */
1551
+ post({ path, parameters, body }, requestOptions) {
1552
+ if (!path) {
1553
+ throw new Error('Parameter `path` is required when calling `post`.');
1554
+ }
1555
+ const requestPath = '/1{path}'.replace('{path}', path);
1556
+ const headers = {};
1557
+ const queryParameters = parameters ? parameters : {};
1558
+ const request = {
1559
+ method: 'POST',
1560
+ path: requestPath,
1561
+ queryParameters,
1562
+ headers,
1563
+ data: body ? body : {},
1564
+ };
1565
+ return transporter.request(request, requestOptions);
1566
+ },
1567
+ /**
1568
+ * This method allow you to send requests to the Algolia REST API.
1569
+ *
1570
+ * @summary Send requests to the Algolia REST API.
1571
+ * @param put - The put object.
1572
+ * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
1573
+ * @param put.parameters - Query parameters to be applied to the current query.
1574
+ * @param put.body - The parameters to send with the custom request.
1575
+ * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1576
+ */
1577
+ put({ path, parameters, body }, requestOptions) {
1578
+ if (!path) {
1579
+ throw new Error('Parameter `path` is required when calling `put`.');
1580
+ }
1581
+ const requestPath = '/1{path}'.replace('{path}', path);
1582
+ const headers = {};
1583
+ const queryParameters = parameters ? parameters : {};
1584
+ const request = {
1585
+ method: 'PUT',
1586
+ path: requestPath,
1587
+ queryParameters,
1588
+ headers,
1589
+ data: body ? body : {},
1590
+ };
1591
+ return transporter.request(request, requestOptions);
1592
+ },
1593
+ };
1594
+ }
1595
+
1596
+ // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
1597
+ function analyticsClient(appId, apiKey, region, options) {
1598
+ if (!appId || typeof appId !== 'string') {
1599
+ throw new Error('`appId` is missing.');
1600
+ }
1601
+ if (!apiKey || typeof apiKey !== 'string') {
1602
+ throw new Error('`apiKey` is missing.');
1603
+ }
1604
+ if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
1605
+ throw new Error(`\`region\` must be one of the following: ${REGIONS.join(', ')}`);
1606
+ }
1607
+ return createAnalyticsClient({
1608
+ appId,
1609
+ apiKey,
1610
+ region,
1611
+ timeouts: {
1612
+ connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
1613
+ read: DEFAULT_READ_TIMEOUT_BROWSER,
1614
+ write: DEFAULT_WRITE_TIMEOUT_BROWSER,
1615
+ },
1616
+ requester: createXhrRequester(),
1617
+ algoliaAgents: [{ segment: 'Browser' }],
1618
+ authMode: 'WithinQueryParameters',
1619
+ responsesCache: createMemoryCache(),
1620
+ requestsCache: createMemoryCache({ serializable: false }),
1621
+ hostsCache: createFallbackableCache({
1622
+ caches: [
1623
+ createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }),
1624
+ createMemoryCache(),
1625
+ ],
1626
+ }),
1627
+ ...options,
1628
+ });
1629
+ }
1630
+
1631
+ export { analyticsClient, apiClientVersion };