@algolia/client-analytics 5.0.0-alpha.1 → 5.0.0-alpha.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builds/browser.d.ts +5 -5
- package/dist/builds/browser.d.ts.map +1 -1
- package/dist/builds/node.d.ts +5 -5
- package/dist/builds/node.d.ts.map +1 -1
- package/dist/{client-analytics.cjs.js → client-analytics.cjs} +952 -911
- package/dist/client-analytics.esm.browser.js +1164 -1145
- package/dist/client-analytics.esm.node.js +952 -909
- package/dist/client-analytics.umd.js +2 -2
- package/dist/model/averageClickEvent.d.ts +14 -14
- package/dist/model/averageClickEvent.d.ts.map +1 -1
- package/dist/model/clickPosition.d.ts +10 -10
- package/dist/model/clickPosition.d.ts.map +1 -1
- package/dist/model/clickThroughRateEvent.d.ts +18 -18
- package/dist/model/clickThroughRateEvent.d.ts.map +1 -1
- package/dist/model/clientMethodProps.d.ts +507 -507
- package/dist/model/clientMethodProps.d.ts.map +1 -1
- package/dist/model/conversionRateEvent.d.ts +18 -18
- package/dist/model/conversionRateEvent.d.ts.map +1 -1
- package/dist/model/direction.d.ts +1 -1
- package/dist/model/direction.d.ts.map +1 -1
- package/dist/model/errorBase.d.ts +6 -6
- package/dist/model/errorBase.d.ts.map +1 -1
- package/dist/model/getAverageClickPositionResponse.d.ts +15 -15
- package/dist/model/getAverageClickPositionResponse.d.ts.map +1 -1
- package/dist/model/getClickPositionsResponse.d.ts +7 -7
- package/dist/model/getClickPositionsResponse.d.ts.map +1 -1
- package/dist/model/getClickThroughRateResponse.d.ts +19 -19
- package/dist/model/getClickThroughRateResponse.d.ts.map +1 -1
- package/dist/model/getConversationRateResponse.d.ts +19 -19
- package/dist/model/getConversationRateResponse.d.ts.map +1 -1
- package/dist/model/getNoClickRateResponse.d.ts +19 -19
- package/dist/model/getNoClickRateResponse.d.ts.map +1 -1
- package/dist/model/getNoResultsRateResponse.d.ts +19 -19
- package/dist/model/getNoResultsRateResponse.d.ts.map +1 -1
- package/dist/model/getSearchesCountResponse.d.ts +11 -11
- package/dist/model/getSearchesCountResponse.d.ts.map +1 -1
- package/dist/model/getSearchesNoClicksResponse.d.ts +7 -7
- package/dist/model/getSearchesNoClicksResponse.d.ts.map +1 -1
- package/dist/model/getSearchesNoResultsResponse.d.ts +7 -7
- package/dist/model/getSearchesNoResultsResponse.d.ts.map +1 -1
- package/dist/model/getStatusResponse.d.ts +6 -6
- package/dist/model/getStatusResponse.d.ts.map +1 -1
- package/dist/model/getTopCountriesResponse.d.ts +7 -7
- package/dist/model/getTopCountriesResponse.d.ts.map +1 -1
- package/dist/model/getTopFilterAttribute.d.ts +10 -10
- package/dist/model/getTopFilterAttribute.d.ts.map +1 -1
- package/dist/model/getTopFilterAttributesResponse.d.ts +7 -7
- package/dist/model/getTopFilterAttributesResponse.d.ts.map +1 -1
- package/dist/model/getTopFilterForAttribute.d.ts +18 -18
- package/dist/model/getTopFilterForAttribute.d.ts.map +1 -1
- package/dist/model/getTopFilterForAttributeResponse.d.ts +7 -7
- package/dist/model/getTopFilterForAttributeResponse.d.ts.map +1 -1
- package/dist/model/getTopFiltersNoResultsResponse.d.ts +7 -7
- package/dist/model/getTopFiltersNoResultsResponse.d.ts.map +1 -1
- package/dist/model/getTopFiltersNoResultsValue.d.ts +14 -14
- package/dist/model/getTopFiltersNoResultsValue.d.ts.map +1 -1
- package/dist/model/getTopFiltersNoResultsValues.d.ts +11 -11
- package/dist/model/getTopFiltersNoResultsValues.d.ts.map +1 -1
- package/dist/model/getTopHitsResponse.d.ts +3 -3
- package/dist/model/getTopHitsResponse.d.ts.map +1 -1
- package/dist/model/getTopSearchesResponse.d.ts +3 -3
- package/dist/model/getTopSearchesResponse.d.ts.map +1 -1
- package/dist/model/getUsersCountResponse.d.ts +11 -11
- package/dist/model/getUsersCountResponse.d.ts.map +1 -1
- package/dist/model/index.d.ts +44 -44
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/noClickRateEvent.d.ts +18 -18
- package/dist/model/noClickRateEvent.d.ts.map +1 -1
- package/dist/model/noResultsRateEvent.d.ts +18 -18
- package/dist/model/noResultsRateEvent.d.ts.map +1 -1
- package/dist/model/orderBy.d.ts +4 -1
- package/dist/model/orderBy.d.ts.map +1 -1
- package/dist/model/searchEvent.d.ts +10 -10
- package/dist/model/searchEvent.d.ts.map +1 -1
- package/dist/model/searchNoClickEvent.d.ts +14 -14
- package/dist/model/searchNoClickEvent.d.ts.map +1 -1
- package/dist/model/searchNoResultEvent.d.ts +14 -14
- package/dist/model/searchNoResultEvent.d.ts.map +1 -1
- package/dist/model/topCountry.d.ts +10 -10
- package/dist/model/topCountry.d.ts.map +1 -1
- package/dist/model/topHit.d.ts +10 -10
- package/dist/model/topHit.d.ts.map +1 -1
- package/dist/model/topHitWithAnalytics.d.ts +30 -30
- package/dist/model/topHitWithAnalytics.d.ts.map +1 -1
- package/dist/model/topHitsResponse.d.ts +7 -7
- package/dist/model/topHitsResponse.d.ts.map +1 -1
- package/dist/model/topHitsResponseWithAnalytics.d.ts +7 -7
- package/dist/model/topHitsResponseWithAnalytics.d.ts.map +1 -1
- package/dist/model/topSearch.d.ts +14 -14
- package/dist/model/topSearch.d.ts.map +1 -1
- package/dist/model/topSearchWithAnalytics.d.ts +38 -38
- package/dist/model/topSearchWithAnalytics.d.ts.map +1 -1
- package/dist/model/topSearchesResponse.d.ts +7 -7
- package/dist/model/topSearchesResponse.d.ts.map +1 -1
- package/dist/model/topSearchesResponseWithAnalytics.d.ts +7 -7
- package/dist/model/topSearchesResponseWithAnalytics.d.ts.map +1 -1
- package/dist/model/userWithDate.d.ts +10 -10
- package/dist/model/userWithDate.d.ts.map +1 -1
- package/dist/src/analyticsClient.d.ts +348 -307
- package/dist/src/analyticsClient.d.ts.map +1 -1
- package/index.js +1 -1
- package/model/averageClickEvent.ts +6 -4
- package/model/clickPosition.ts +4 -3
- package/model/clickThroughRateEvent.ts +8 -5
- package/model/clientMethodProps.ts +126 -126
- package/model/conversionRateEvent.ts +8 -5
- package/model/direction.ts +1 -1
- package/model/errorBase.ts +1 -1
- package/model/getAverageClickPositionResponse.ts +6 -4
- package/model/getClickPositionsResponse.ts +2 -2
- package/model/getClickThroughRateResponse.ts +8 -5
- package/model/getConversationRateResponse.ts +8 -5
- package/model/getNoClickRateResponse.ts +8 -5
- package/model/getNoResultsRateResponse.ts +8 -5
- package/model/getSearchesCountResponse.ts +4 -3
- package/model/getSearchesNoClicksResponse.ts +2 -2
- package/model/getSearchesNoResultsResponse.ts +2 -2
- package/model/getStatusResponse.ts +2 -2
- package/model/getTopCountriesResponse.ts +2 -2
- package/model/getTopFilterAttribute.ts +4 -3
- package/model/getTopFilterAttributesResponse.ts +2 -2
- package/model/getTopFilterForAttribute.ts +8 -5
- package/model/getTopFilterForAttributeResponse.ts +2 -2
- package/model/getTopFiltersNoResultsResponse.ts +2 -2
- package/model/getTopFiltersNoResultsValue.ts +6 -4
- package/model/getTopFiltersNoResultsValues.ts +4 -3
- package/model/getTopHitsResponse.ts +1 -1
- package/model/getTopSearchesResponse.ts +1 -1
- package/model/getUsersCountResponse.ts +4 -3
- package/model/index.ts +1 -1
- package/model/noClickRateEvent.ts +8 -5
- package/model/noResultsRateEvent.ts +8 -5
- package/model/orderBy.ts +4 -1
- package/model/searchEvent.ts +4 -3
- package/model/searchNoClickEvent.ts +6 -4
- package/model/searchNoResultEvent.ts +6 -4
- package/model/topCountry.ts +4 -3
- package/model/topHit.ts +4 -3
- package/model/topHitWithAnalytics.ts +14 -8
- package/model/topHitsResponse.ts +2 -2
- package/model/topHitsResponseWithAnalytics.ts +2 -2
- package/model/topSearch.ts +6 -4
- package/model/topSearchWithAnalytics.ts +18 -10
- package/model/topSearchesResponse.ts +2 -2
- package/model/topSearchesResponseWithAnalytics.ts +2 -2
- package/model/userWithDate.ts +4 -3
- package/package.json +32 -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;
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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)] =
|
|
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
|
-
|
|
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);
|
|
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,
|
|
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,
|
|
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
273
|
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`;
|
|
268
|
-
|
|
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])}`).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
|
-
|
|
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
|
-
|
|
319
|
-
|
|
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 {
|
|
354
|
-
|
|
355
|
-
|
|
358
|
+
return {
|
|
359
|
+
...stackFrame,
|
|
360
|
+
request: {
|
|
361
|
+
...stackFrame.request,
|
|
362
|
+
headers: {
|
|
363
|
+
...stackFrame.request.headers,
|
|
356
364
|
...modifiedHeaders
|
|
357
365
|
}
|
|
358
366
|
}
|
|
@@ -377,51 +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());
|
|
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);
|
|
414
|
-
|
|
415
|
-
const dataQueryParameters = request.method === 'GET' ? {
|
|
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
423
|
const queryParameters = {
|
|
419
|
-
'x-algolia-agent': algoliaAgent.value,
|
|
420
424
|
...baseQueryParameters,
|
|
421
425
|
...request.queryParameters,
|
|
422
426
|
...dataQueryParameters
|
|
423
427
|
};
|
|
424
|
-
|
|
428
|
+
if (algoliaAgent.value) {
|
|
429
|
+
queryParameters['x-algolia-agent'] = algoliaAgent.value;
|
|
430
|
+
}
|
|
425
431
|
if (requestOptions && requestOptions.queryParameters) {
|
|
426
432
|
for (const key of Object.keys(requestOptions.queryParameters)) {
|
|
427
433
|
// We want to keep `undefined` and `null` values,
|
|
@@ -434,25 +440,19 @@ function createTransporter({
|
|
|
434
440
|
}
|
|
435
441
|
}
|
|
436
442
|
}
|
|
437
|
-
|
|
438
443
|
let timeoutsCount = 0;
|
|
439
|
-
|
|
440
444
|
const retry = async (retryableHosts, getTimeout) => {
|
|
441
|
-
/**
|
|
442
|
-
* We iterate on each host, until there is no host left.
|
|
445
|
+
/**
|
|
446
|
+
* We iterate on each host, until there is no host left.
|
|
443
447
|
*/
|
|
444
448
|
const host = retryableHosts.pop();
|
|
445
|
-
|
|
446
449
|
if (host === undefined) {
|
|
447
450
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
448
451
|
}
|
|
449
|
-
|
|
450
452
|
let responseTimeout = requestOptions.timeout;
|
|
451
|
-
|
|
452
453
|
if (responseTimeout === undefined) {
|
|
453
454
|
responseTimeout = isRead ? timeouts.read : timeouts.write;
|
|
454
455
|
}
|
|
455
|
-
|
|
456
456
|
const payload = {
|
|
457
457
|
data,
|
|
458
458
|
headers,
|
|
@@ -461,12 +461,11 @@ function createTransporter({
|
|
|
461
461
|
connectTimeout: getTimeout(timeoutsCount, timeouts.connect),
|
|
462
462
|
responseTimeout: getTimeout(timeoutsCount, responseTimeout)
|
|
463
463
|
};
|
|
464
|
-
/**
|
|
465
|
-
* The stackFrame is pushed to the stackTrace so we
|
|
466
|
-
* can have information about onRetry and onFailure
|
|
467
|
-
* decisions.
|
|
464
|
+
/**
|
|
465
|
+
* The stackFrame is pushed to the stackTrace so we
|
|
466
|
+
* can have information about onRetry and onFailure
|
|
467
|
+
* decisions.
|
|
468
468
|
*/
|
|
469
|
-
|
|
470
469
|
const pushToStackTrace = response => {
|
|
471
470
|
const stackFrame = {
|
|
472
471
|
request: payload,
|
|
@@ -477,102 +476,85 @@ function createTransporter({
|
|
|
477
476
|
stackTrace.push(stackFrame);
|
|
478
477
|
return stackFrame;
|
|
479
478
|
};
|
|
480
|
-
|
|
481
479
|
const response = await requester.send(payload);
|
|
482
|
-
|
|
483
480
|
if (isRetryable(response)) {
|
|
484
|
-
const stackFrame = pushToStackTrace(response);
|
|
485
|
-
|
|
481
|
+
const stackFrame = pushToStackTrace(response);
|
|
482
|
+
// If response is a timeout, we increase the number of timeouts so we can increase the timeout later.
|
|
486
483
|
if (response.isTimedOut) {
|
|
487
484
|
timeoutsCount++;
|
|
488
485
|
}
|
|
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.
|
|
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.
|
|
493
490
|
*/
|
|
494
491
|
// eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
|
|
495
|
-
|
|
496
|
-
|
|
497
492
|
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.
|
|
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.
|
|
502
497
|
*/
|
|
503
|
-
|
|
504
498
|
await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));
|
|
505
499
|
return retry(retryableHosts, getTimeout);
|
|
506
500
|
}
|
|
507
|
-
|
|
508
501
|
if (isSuccess(response)) {
|
|
509
502
|
return deserializeSuccess(response);
|
|
510
503
|
}
|
|
511
|
-
|
|
512
504
|
pushToStackTrace(response);
|
|
513
505
|
throw deserializeFailure(response, stackTrace);
|
|
514
506
|
};
|
|
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.
|
|
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.
|
|
522
514
|
*/
|
|
523
|
-
|
|
524
|
-
|
|
525
515
|
const compatibleHosts = hosts.filter(host => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'));
|
|
526
516
|
const options = await createRetryableOptions(compatibleHosts);
|
|
527
517
|
return retry([...options.hosts].reverse(), options.getTimeout);
|
|
528
518
|
}
|
|
529
|
-
|
|
530
519
|
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`).
|
|
520
|
+
/**
|
|
521
|
+
* A read request is either a `GET` request, or a request that we make
|
|
522
|
+
* via the `read` transporter (e.g. `search`).
|
|
534
523
|
*/
|
|
535
524
|
const isRead = request.useReadTransporter || request.method === 'GET';
|
|
536
|
-
|
|
537
525
|
if (!isRead) {
|
|
538
|
-
/**
|
|
539
|
-
* On write requests, no cache mechanisms are applied, and we
|
|
540
|
-
* 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.
|
|
541
529
|
*/
|
|
542
530
|
return retryableRequest(request, requestOptions, isRead);
|
|
543
531
|
}
|
|
544
|
-
|
|
545
532
|
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.
|
|
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.
|
|
550
537
|
*/
|
|
551
538
|
return retryableRequest(request, requestOptions);
|
|
552
539
|
};
|
|
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.
|
|
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.
|
|
557
544
|
*/
|
|
558
|
-
|
|
559
|
-
|
|
560
545
|
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.
|
|
546
|
+
/**
|
|
547
|
+
* If is not "cacheable", we immediately trigger the retryable request, no
|
|
548
|
+
* need to check cache implementations.
|
|
564
549
|
*/
|
|
565
|
-
|
|
566
550
|
if (cacheable !== true) {
|
|
567
551
|
return createRetryableRequest();
|
|
568
552
|
}
|
|
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.
|
|
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.
|
|
573
557
|
*/
|
|
574
|
-
|
|
575
|
-
|
|
576
558
|
const key = {
|
|
577
559
|
request,
|
|
578
560
|
requestOptions,
|
|
@@ -581,33 +563,31 @@ function createTransporter({
|
|
|
581
563
|
headers: baseHeaders
|
|
582
564
|
}
|
|
583
565
|
};
|
|
584
|
-
/**
|
|
585
|
-
* With the computed key, we first ask the responses cache
|
|
586
|
-
* 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.
|
|
587
569
|
*/
|
|
588
|
-
|
|
589
570
|
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.
|
|
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.
|
|
593
574
|
*/
|
|
594
575
|
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.
|
|
576
|
+
/**
|
|
577
|
+
* Finally, if there is no request in progress with the same key,
|
|
578
|
+
* this `createRetryableRequest()` will actually trigger the
|
|
579
|
+
* retryable request.
|
|
599
580
|
*/
|
|
600
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));
|
|
601
582
|
}, {
|
|
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.
|
|
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.
|
|
606
587
|
*/
|
|
607
588
|
miss: response => responsesCache.set(key, response)
|
|
608
589
|
});
|
|
609
590
|
}
|
|
610
|
-
|
|
611
591
|
return {
|
|
612
592
|
hostsCache,
|
|
613
593
|
requester,
|
|
@@ -625,17 +605,13 @@ function createTransporter({
|
|
|
625
605
|
function createAlgoliaAgent(version) {
|
|
626
606
|
const algoliaAgent = {
|
|
627
607
|
value: `Algolia for JavaScript (${version})`,
|
|
628
|
-
|
|
629
608
|
add(options) {
|
|
630
609
|
const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;
|
|
631
|
-
|
|
632
610
|
if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
|
|
633
611
|
algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
|
|
634
612
|
}
|
|
635
|
-
|
|
636
613
|
return algoliaAgent;
|
|
637
614
|
}
|
|
638
|
-
|
|
639
615
|
};
|
|
640
616
|
return algoliaAgent;
|
|
641
617
|
}
|
|
@@ -657,975 +633,1018 @@ const DEFAULT_CONNECT_TIMEOUT_BROWSER = 1000;
|
|
|
657
633
|
const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
|
|
658
634
|
const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
|
|
659
635
|
|
|
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 };
|
|
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 };
|
|
710
686
|
}
|
|
711
687
|
|
|
712
|
-
//
|
|
713
|
-
const apiClientVersion = '5.0.0-alpha.
|
|
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
|
-
*
|
|
746
|
-
*/
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
* @param
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
if (
|
|
829
|
-
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
*
|
|
847
|
-
*
|
|
848
|
-
* @
|
|
849
|
-
* @param
|
|
850
|
-
* @param
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
queryParameters
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
if (
|
|
972
|
-
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
if (
|
|
978
|
-
queryParameters.
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
*
|
|
999
|
-
*
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
*
|
|
1037
|
-
*
|
|
1038
|
-
* @
|
|
1039
|
-
* @param
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
queryParameters
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
*
|
|
1075
|
-
*
|
|
1076
|
-
* @
|
|
1077
|
-
* @param
|
|
1078
|
-
* @param
|
|
1079
|
-
* @param
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
queryParameters
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
queryParameters
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
queryParameters
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
*
|
|
1198
|
-
*
|
|
1199
|
-
*
|
|
1200
|
-
*
|
|
1201
|
-
*
|
|
1202
|
-
* @param
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
*
|
|
1246
|
-
*
|
|
1247
|
-
*
|
|
1248
|
-
*
|
|
1249
|
-
*
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
}
|
|
1261
|
-
if (
|
|
1262
|
-
queryParameters.
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
if (
|
|
1304
|
-
|
|
1305
|
-
}
|
|
1306
|
-
if (
|
|
1307
|
-
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
queryParameters
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
},
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
queryParameters
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
queryParameters
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
*
|
|
1543
|
-
*
|
|
1544
|
-
* @
|
|
1545
|
-
* @param
|
|
1546
|
-
* @param
|
|
1547
|
-
* @param
|
|
1548
|
-
* @param
|
|
1549
|
-
* @param
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
const
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
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.100';
|
|
690
|
+
const REGIONS = ['de', 'us'];
|
|
691
|
+
function getDefaultHosts(region) {
|
|
692
|
+
const url = !region
|
|
693
|
+
? 'analytics.algolia.com'
|
|
694
|
+
: 'analytics.{region}.algolia.com'.replace('{region}', region);
|
|
695
|
+
return [{ url, accept: 'readWrite', protocol: 'https' }];
|
|
696
|
+
}
|
|
697
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
698
|
+
function createAnalyticsClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }) {
|
|
699
|
+
const auth = createAuth(appIdOption, apiKeyOption, authMode);
|
|
700
|
+
const transporter = createTransporter({
|
|
701
|
+
hosts: getDefaultHosts(regionOption),
|
|
702
|
+
...options,
|
|
703
|
+
algoliaAgent: getAlgoliaAgent({
|
|
704
|
+
algoliaAgents,
|
|
705
|
+
client: 'Analytics',
|
|
706
|
+
version: apiClientVersion,
|
|
707
|
+
}),
|
|
708
|
+
baseHeaders: {
|
|
709
|
+
'content-type': 'text/plain',
|
|
710
|
+
...auth.headers(),
|
|
711
|
+
...options.baseHeaders,
|
|
712
|
+
},
|
|
713
|
+
baseQueryParameters: {
|
|
714
|
+
...auth.queryParameters(),
|
|
715
|
+
...options.baseQueryParameters,
|
|
716
|
+
},
|
|
717
|
+
});
|
|
718
|
+
return {
|
|
719
|
+
transporter,
|
|
720
|
+
/**
|
|
721
|
+
* The `appId` currently in use.
|
|
722
|
+
*/
|
|
723
|
+
appId: appIdOption,
|
|
724
|
+
/**
|
|
725
|
+
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
|
|
726
|
+
*/
|
|
727
|
+
clearCache() {
|
|
728
|
+
return Promise.all([
|
|
729
|
+
transporter.requestsCache.clear(),
|
|
730
|
+
transporter.responsesCache.clear(),
|
|
731
|
+
]).then(() => undefined);
|
|
732
|
+
},
|
|
733
|
+
/**
|
|
734
|
+
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
|
|
735
|
+
*/
|
|
736
|
+
get _ua() {
|
|
737
|
+
return transporter.algoliaAgent.value;
|
|
738
|
+
},
|
|
739
|
+
/**
|
|
740
|
+
* Adds a `segment` to the `x-algolia-agent` sent with every requests.
|
|
741
|
+
*
|
|
742
|
+
* @param segment - The algolia agent (user-agent) segment to add.
|
|
743
|
+
* @param version - The version of the agent.
|
|
744
|
+
*/
|
|
745
|
+
addAlgoliaAgent(segment, version) {
|
|
746
|
+
transporter.algoliaAgent.add({ segment, version });
|
|
747
|
+
},
|
|
748
|
+
/**
|
|
749
|
+
* This method allow you to send requests to the Algolia REST API.
|
|
750
|
+
*
|
|
751
|
+
* @param customDelete - The customDelete object.
|
|
752
|
+
* @param customDelete.path - Path of the endpoint, anything after \"/1\" must be specified.
|
|
753
|
+
* @param customDelete.parameters - Query parameters to apply to the current query.
|
|
754
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
755
|
+
*/
|
|
756
|
+
customDelete({ path, parameters }, requestOptions) {
|
|
757
|
+
if (!path) {
|
|
758
|
+
throw new Error('Parameter `path` is required when calling `customDelete`.');
|
|
759
|
+
}
|
|
760
|
+
const requestPath = '/1{path}'.replace('{path}', path);
|
|
761
|
+
const headers = {};
|
|
762
|
+
const queryParameters = parameters ? parameters : {};
|
|
763
|
+
const request = {
|
|
764
|
+
method: 'DELETE',
|
|
765
|
+
path: requestPath,
|
|
766
|
+
queryParameters,
|
|
767
|
+
headers,
|
|
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 customGet - The customGet object.
|
|
775
|
+
* @param customGet.path - Path of the endpoint, anything after \"/1\" must be specified.
|
|
776
|
+
* @param customGet.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
|
+
customGet({ path, parameters }, requestOptions) {
|
|
780
|
+
if (!path) {
|
|
781
|
+
throw new Error('Parameter `path` is required when calling `customGet`.');
|
|
782
|
+
}
|
|
783
|
+
const requestPath = '/1{path}'.replace('{path}', path);
|
|
784
|
+
const headers = {};
|
|
785
|
+
const queryParameters = parameters ? parameters : {};
|
|
786
|
+
const request = {
|
|
787
|
+
method: 'GET',
|
|
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 customPost - The customPost object.
|
|
798
|
+
* @param customPost.path - Path of the endpoint, anything after \"/1\" must be specified.
|
|
799
|
+
* @param customPost.parameters - Query parameters to apply to the current query.
|
|
800
|
+
* @param customPost.body - Parameters to send with the custom request.
|
|
801
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
802
|
+
*/
|
|
803
|
+
customPost({ path, parameters, body }, requestOptions) {
|
|
804
|
+
if (!path) {
|
|
805
|
+
throw new Error('Parameter `path` is required when calling `customPost`.');
|
|
806
|
+
}
|
|
807
|
+
const requestPath = '/1{path}'.replace('{path}', path);
|
|
808
|
+
const headers = {};
|
|
809
|
+
const queryParameters = parameters ? parameters : {};
|
|
810
|
+
const request = {
|
|
811
|
+
method: 'POST',
|
|
812
|
+
path: requestPath,
|
|
813
|
+
queryParameters,
|
|
814
|
+
headers,
|
|
815
|
+
data: body ? body : {},
|
|
816
|
+
};
|
|
817
|
+
return transporter.request(request, requestOptions);
|
|
818
|
+
},
|
|
819
|
+
/**
|
|
820
|
+
* This method allow you to send requests to the Algolia REST API.
|
|
821
|
+
*
|
|
822
|
+
* @param customPut - The customPut object.
|
|
823
|
+
* @param customPut.path - Path of the endpoint, anything after \"/1\" must be specified.
|
|
824
|
+
* @param customPut.parameters - Query parameters to apply to the current query.
|
|
825
|
+
* @param customPut.body - Parameters to send with the custom request.
|
|
826
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
827
|
+
*/
|
|
828
|
+
customPut({ path, parameters, body }, requestOptions) {
|
|
829
|
+
if (!path) {
|
|
830
|
+
throw new Error('Parameter `path` is required when calling `customPut`.');
|
|
831
|
+
}
|
|
832
|
+
const requestPath = '/1{path}'.replace('{path}', path);
|
|
833
|
+
const headers = {};
|
|
834
|
+
const queryParameters = parameters ? parameters : {};
|
|
835
|
+
const request = {
|
|
836
|
+
method: 'PUT',
|
|
837
|
+
path: requestPath,
|
|
838
|
+
queryParameters,
|
|
839
|
+
headers,
|
|
840
|
+
data: body ? body : {},
|
|
841
|
+
};
|
|
842
|
+
return transporter.request(request, requestOptions);
|
|
843
|
+
},
|
|
844
|
+
/**
|
|
845
|
+
* Return the average click position for the complete time range and for individual days. > **Note**: If all `positions` have a `clickCount` of `0` or `null`, it means Algolia didn\'t receive any click events for tracked searches. A _tracked_ search is a search request where the `clickAnalytics` parameter is `true`.
|
|
846
|
+
*
|
|
847
|
+
* Required API Key ACLs:
|
|
848
|
+
* - analytics.
|
|
849
|
+
*
|
|
850
|
+
* @param getAverageClickPosition - The getAverageClickPosition object.
|
|
851
|
+
* @param getAverageClickPosition.index - Index name to target.
|
|
852
|
+
* @param getAverageClickPosition.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
853
|
+
* @param getAverageClickPosition.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
854
|
+
* @param getAverageClickPosition.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
855
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
856
|
+
*/
|
|
857
|
+
getAverageClickPosition({ index, startDate, endDate, tags }, requestOptions) {
|
|
858
|
+
if (!index) {
|
|
859
|
+
throw new Error('Parameter `index` is required when calling `getAverageClickPosition`.');
|
|
860
|
+
}
|
|
861
|
+
const requestPath = '/2/clicks/averageClickPosition';
|
|
862
|
+
const headers = {};
|
|
863
|
+
const queryParameters = {};
|
|
864
|
+
if (index !== undefined) {
|
|
865
|
+
queryParameters.index = index.toString();
|
|
866
|
+
}
|
|
867
|
+
if (startDate !== undefined) {
|
|
868
|
+
queryParameters.startDate = startDate.toString();
|
|
869
|
+
}
|
|
870
|
+
if (endDate !== undefined) {
|
|
871
|
+
queryParameters.endDate = endDate.toString();
|
|
872
|
+
}
|
|
873
|
+
if (tags !== undefined) {
|
|
874
|
+
queryParameters.tags = tags.toString();
|
|
875
|
+
}
|
|
876
|
+
const request = {
|
|
877
|
+
method: 'GET',
|
|
878
|
+
path: requestPath,
|
|
879
|
+
queryParameters,
|
|
880
|
+
headers,
|
|
881
|
+
};
|
|
882
|
+
return transporter.request(request, requestOptions);
|
|
883
|
+
},
|
|
884
|
+
/**
|
|
885
|
+
* Show the number of clicks events and their associated position in the search results. > **Note**: If all `positions` have a `clickCount` of `0` or `null`, it means Algolia didn\'t receive any click events for tracked searches. A _tracked_ search is a search request where the `clickAnalytics` parameter is `true`.
|
|
886
|
+
*
|
|
887
|
+
* Required API Key ACLs:
|
|
888
|
+
* - analytics.
|
|
889
|
+
*
|
|
890
|
+
* @param getClickPositions - The getClickPositions object.
|
|
891
|
+
* @param getClickPositions.index - Index name to target.
|
|
892
|
+
* @param getClickPositions.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
893
|
+
* @param getClickPositions.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
894
|
+
* @param getClickPositions.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
895
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
896
|
+
*/
|
|
897
|
+
getClickPositions({ index, startDate, endDate, tags }, requestOptions) {
|
|
898
|
+
if (!index) {
|
|
899
|
+
throw new Error('Parameter `index` is required when calling `getClickPositions`.');
|
|
900
|
+
}
|
|
901
|
+
const requestPath = '/2/clicks/positions';
|
|
902
|
+
const headers = {};
|
|
903
|
+
const queryParameters = {};
|
|
904
|
+
if (index !== undefined) {
|
|
905
|
+
queryParameters.index = index.toString();
|
|
906
|
+
}
|
|
907
|
+
if (startDate !== undefined) {
|
|
908
|
+
queryParameters.startDate = startDate.toString();
|
|
909
|
+
}
|
|
910
|
+
if (endDate !== undefined) {
|
|
911
|
+
queryParameters.endDate = endDate.toString();
|
|
912
|
+
}
|
|
913
|
+
if (tags !== undefined) {
|
|
914
|
+
queryParameters.tags = tags.toString();
|
|
915
|
+
}
|
|
916
|
+
const request = {
|
|
917
|
+
method: 'GET',
|
|
918
|
+
path: requestPath,
|
|
919
|
+
queryParameters,
|
|
920
|
+
headers,
|
|
921
|
+
};
|
|
922
|
+
return transporter.request(request, requestOptions);
|
|
923
|
+
},
|
|
924
|
+
/**
|
|
925
|
+
* Returns a [click-through rate (CTR)](https://www.algolia.com/doc/guides/search-analytics/concepts/metrics/#click-through-rate).
|
|
926
|
+
*
|
|
927
|
+
* Required API Key ACLs:
|
|
928
|
+
* - analytics.
|
|
929
|
+
*
|
|
930
|
+
* @param getClickThroughRate - The getClickThroughRate object.
|
|
931
|
+
* @param getClickThroughRate.index - Index name to target.
|
|
932
|
+
* @param getClickThroughRate.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
933
|
+
* @param getClickThroughRate.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
934
|
+
* @param getClickThroughRate.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
935
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
936
|
+
*/
|
|
937
|
+
getClickThroughRate({ index, startDate, endDate, tags }, requestOptions) {
|
|
938
|
+
if (!index) {
|
|
939
|
+
throw new Error('Parameter `index` is required when calling `getClickThroughRate`.');
|
|
940
|
+
}
|
|
941
|
+
const requestPath = '/2/clicks/clickThroughRate';
|
|
942
|
+
const headers = {};
|
|
943
|
+
const queryParameters = {};
|
|
944
|
+
if (index !== undefined) {
|
|
945
|
+
queryParameters.index = index.toString();
|
|
946
|
+
}
|
|
947
|
+
if (startDate !== undefined) {
|
|
948
|
+
queryParameters.startDate = startDate.toString();
|
|
949
|
+
}
|
|
950
|
+
if (endDate !== undefined) {
|
|
951
|
+
queryParameters.endDate = endDate.toString();
|
|
952
|
+
}
|
|
953
|
+
if (tags !== undefined) {
|
|
954
|
+
queryParameters.tags = tags.toString();
|
|
955
|
+
}
|
|
956
|
+
const request = {
|
|
957
|
+
method: 'GET',
|
|
958
|
+
path: requestPath,
|
|
959
|
+
queryParameters,
|
|
960
|
+
headers,
|
|
961
|
+
};
|
|
962
|
+
return transporter.request(request, requestOptions);
|
|
963
|
+
},
|
|
964
|
+
/**
|
|
965
|
+
* Return a [conversion rate](https://www.algolia.com/doc/guides/search-analytics/concepts/metrics/#conversion-rate).
|
|
966
|
+
*
|
|
967
|
+
* Required API Key ACLs:
|
|
968
|
+
* - analytics.
|
|
969
|
+
*
|
|
970
|
+
* @param getConversationRate - The getConversationRate object.
|
|
971
|
+
* @param getConversationRate.index - Index name to target.
|
|
972
|
+
* @param getConversationRate.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
973
|
+
* @param getConversationRate.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
974
|
+
* @param getConversationRate.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
975
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
976
|
+
*/
|
|
977
|
+
getConversationRate({ index, startDate, endDate, tags }, requestOptions) {
|
|
978
|
+
if (!index) {
|
|
979
|
+
throw new Error('Parameter `index` is required when calling `getConversationRate`.');
|
|
980
|
+
}
|
|
981
|
+
const requestPath = '/2/conversions/conversionRate';
|
|
982
|
+
const headers = {};
|
|
983
|
+
const queryParameters = {};
|
|
984
|
+
if (index !== undefined) {
|
|
985
|
+
queryParameters.index = index.toString();
|
|
986
|
+
}
|
|
987
|
+
if (startDate !== undefined) {
|
|
988
|
+
queryParameters.startDate = startDate.toString();
|
|
989
|
+
}
|
|
990
|
+
if (endDate !== undefined) {
|
|
991
|
+
queryParameters.endDate = endDate.toString();
|
|
992
|
+
}
|
|
993
|
+
if (tags !== undefined) {
|
|
994
|
+
queryParameters.tags = tags.toString();
|
|
995
|
+
}
|
|
996
|
+
const request = {
|
|
997
|
+
method: 'GET',
|
|
998
|
+
path: requestPath,
|
|
999
|
+
queryParameters,
|
|
1000
|
+
headers,
|
|
1001
|
+
};
|
|
1002
|
+
return transporter.request(request, requestOptions);
|
|
1003
|
+
},
|
|
1004
|
+
/**
|
|
1005
|
+
* Returns the rate at which searches don\'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.
|
|
1006
|
+
*
|
|
1007
|
+
* Required API Key ACLs:
|
|
1008
|
+
* - analytics.
|
|
1009
|
+
*
|
|
1010
|
+
* @param getNoClickRate - The getNoClickRate object.
|
|
1011
|
+
* @param getNoClickRate.index - Index name to target.
|
|
1012
|
+
* @param getNoClickRate.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1013
|
+
* @param getNoClickRate.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1014
|
+
* @param getNoClickRate.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1015
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1016
|
+
*/
|
|
1017
|
+
getNoClickRate({ index, startDate, endDate, tags }, requestOptions) {
|
|
1018
|
+
if (!index) {
|
|
1019
|
+
throw new Error('Parameter `index` is required when calling `getNoClickRate`.');
|
|
1020
|
+
}
|
|
1021
|
+
const requestPath = '/2/searches/noClickRate';
|
|
1022
|
+
const headers = {};
|
|
1023
|
+
const queryParameters = {};
|
|
1024
|
+
if (index !== undefined) {
|
|
1025
|
+
queryParameters.index = index.toString();
|
|
1026
|
+
}
|
|
1027
|
+
if (startDate !== undefined) {
|
|
1028
|
+
queryParameters.startDate = startDate.toString();
|
|
1029
|
+
}
|
|
1030
|
+
if (endDate !== undefined) {
|
|
1031
|
+
queryParameters.endDate = endDate.toString();
|
|
1032
|
+
}
|
|
1033
|
+
if (tags !== undefined) {
|
|
1034
|
+
queryParameters.tags = tags.toString();
|
|
1035
|
+
}
|
|
1036
|
+
const request = {
|
|
1037
|
+
method: 'GET',
|
|
1038
|
+
path: requestPath,
|
|
1039
|
+
queryParameters,
|
|
1040
|
+
headers,
|
|
1041
|
+
};
|
|
1042
|
+
return transporter.request(request, requestOptions);
|
|
1043
|
+
},
|
|
1044
|
+
/**
|
|
1045
|
+
* Returns the rate at which searches didn\'t return any results.
|
|
1046
|
+
*
|
|
1047
|
+
* Required API Key ACLs:
|
|
1048
|
+
* - analytics.
|
|
1049
|
+
*
|
|
1050
|
+
* @param getNoResultsRate - The getNoResultsRate object.
|
|
1051
|
+
* @param getNoResultsRate.index - Index name to target.
|
|
1052
|
+
* @param getNoResultsRate.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1053
|
+
* @param getNoResultsRate.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1054
|
+
* @param getNoResultsRate.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1055
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1056
|
+
*/
|
|
1057
|
+
getNoResultsRate({ index, startDate, endDate, tags }, requestOptions) {
|
|
1058
|
+
if (!index) {
|
|
1059
|
+
throw new Error('Parameter `index` is required when calling `getNoResultsRate`.');
|
|
1060
|
+
}
|
|
1061
|
+
const requestPath = '/2/searches/noResultRate';
|
|
1062
|
+
const headers = {};
|
|
1063
|
+
const queryParameters = {};
|
|
1064
|
+
if (index !== undefined) {
|
|
1065
|
+
queryParameters.index = index.toString();
|
|
1066
|
+
}
|
|
1067
|
+
if (startDate !== undefined) {
|
|
1068
|
+
queryParameters.startDate = startDate.toString();
|
|
1069
|
+
}
|
|
1070
|
+
if (endDate !== undefined) {
|
|
1071
|
+
queryParameters.endDate = endDate.toString();
|
|
1072
|
+
}
|
|
1073
|
+
if (tags !== undefined) {
|
|
1074
|
+
queryParameters.tags = tags.toString();
|
|
1075
|
+
}
|
|
1076
|
+
const request = {
|
|
1077
|
+
method: 'GET',
|
|
1078
|
+
path: requestPath,
|
|
1079
|
+
queryParameters,
|
|
1080
|
+
headers,
|
|
1081
|
+
};
|
|
1082
|
+
return transporter.request(request, requestOptions);
|
|
1083
|
+
},
|
|
1084
|
+
/**
|
|
1085
|
+
* Returns the number of searches within a time range.
|
|
1086
|
+
*
|
|
1087
|
+
* Required API Key ACLs:
|
|
1088
|
+
* - analytics.
|
|
1089
|
+
*
|
|
1090
|
+
* @param getSearchesCount - The getSearchesCount object.
|
|
1091
|
+
* @param getSearchesCount.index - Index name to target.
|
|
1092
|
+
* @param getSearchesCount.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1093
|
+
* @param getSearchesCount.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1094
|
+
* @param getSearchesCount.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1095
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1096
|
+
*/
|
|
1097
|
+
getSearchesCount({ index, startDate, endDate, tags }, requestOptions) {
|
|
1098
|
+
if (!index) {
|
|
1099
|
+
throw new Error('Parameter `index` is required when calling `getSearchesCount`.');
|
|
1100
|
+
}
|
|
1101
|
+
const requestPath = '/2/searches/count';
|
|
1102
|
+
const headers = {};
|
|
1103
|
+
const queryParameters = {};
|
|
1104
|
+
if (index !== undefined) {
|
|
1105
|
+
queryParameters.index = index.toString();
|
|
1106
|
+
}
|
|
1107
|
+
if (startDate !== undefined) {
|
|
1108
|
+
queryParameters.startDate = startDate.toString();
|
|
1109
|
+
}
|
|
1110
|
+
if (endDate !== undefined) {
|
|
1111
|
+
queryParameters.endDate = endDate.toString();
|
|
1112
|
+
}
|
|
1113
|
+
if (tags !== undefined) {
|
|
1114
|
+
queryParameters.tags = tags.toString();
|
|
1115
|
+
}
|
|
1116
|
+
const request = {
|
|
1117
|
+
method: 'GET',
|
|
1118
|
+
path: requestPath,
|
|
1119
|
+
queryParameters,
|
|
1120
|
+
headers,
|
|
1121
|
+
};
|
|
1122
|
+
return transporter.request(request, requestOptions);
|
|
1123
|
+
},
|
|
1124
|
+
/**
|
|
1125
|
+
* Return the most popular of the last 1,000 searches that didn\'t lead to any clicks.
|
|
1126
|
+
*
|
|
1127
|
+
* Required API Key ACLs:
|
|
1128
|
+
* - analytics.
|
|
1129
|
+
*
|
|
1130
|
+
* @param getSearchesNoClicks - The getSearchesNoClicks object.
|
|
1131
|
+
* @param getSearchesNoClicks.index - Index name to target.
|
|
1132
|
+
* @param getSearchesNoClicks.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1133
|
+
* @param getSearchesNoClicks.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1134
|
+
* @param getSearchesNoClicks.limit - Number of records to return (page size).
|
|
1135
|
+
* @param getSearchesNoClicks.offset - Position of the starting record. Used for paging. 0 is the first record.
|
|
1136
|
+
* @param getSearchesNoClicks.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1137
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1138
|
+
*/
|
|
1139
|
+
getSearchesNoClicks({ index, startDate, endDate, limit, offset, tags, }, requestOptions) {
|
|
1140
|
+
if (!index) {
|
|
1141
|
+
throw new Error('Parameter `index` is required when calling `getSearchesNoClicks`.');
|
|
1142
|
+
}
|
|
1143
|
+
const requestPath = '/2/searches/noClicks';
|
|
1144
|
+
const headers = {};
|
|
1145
|
+
const queryParameters = {};
|
|
1146
|
+
if (index !== undefined) {
|
|
1147
|
+
queryParameters.index = index.toString();
|
|
1148
|
+
}
|
|
1149
|
+
if (startDate !== undefined) {
|
|
1150
|
+
queryParameters.startDate = startDate.toString();
|
|
1151
|
+
}
|
|
1152
|
+
if (endDate !== undefined) {
|
|
1153
|
+
queryParameters.endDate = endDate.toString();
|
|
1154
|
+
}
|
|
1155
|
+
if (limit !== undefined) {
|
|
1156
|
+
queryParameters.limit = limit.toString();
|
|
1157
|
+
}
|
|
1158
|
+
if (offset !== undefined) {
|
|
1159
|
+
queryParameters.offset = offset.toString();
|
|
1160
|
+
}
|
|
1161
|
+
if (tags !== undefined) {
|
|
1162
|
+
queryParameters.tags = tags.toString();
|
|
1163
|
+
}
|
|
1164
|
+
const request = {
|
|
1165
|
+
method: 'GET',
|
|
1166
|
+
path: requestPath,
|
|
1167
|
+
queryParameters,
|
|
1168
|
+
headers,
|
|
1169
|
+
};
|
|
1170
|
+
return transporter.request(request, requestOptions);
|
|
1171
|
+
},
|
|
1172
|
+
/**
|
|
1173
|
+
* Returns the most popular of the latest 1,000 searches that didn\'t return any results.
|
|
1174
|
+
*
|
|
1175
|
+
* Required API Key ACLs:
|
|
1176
|
+
* - analytics.
|
|
1177
|
+
*
|
|
1178
|
+
* @param getSearchesNoResults - The getSearchesNoResults object.
|
|
1179
|
+
* @param getSearchesNoResults.index - Index name to target.
|
|
1180
|
+
* @param getSearchesNoResults.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1181
|
+
* @param getSearchesNoResults.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1182
|
+
* @param getSearchesNoResults.limit - Number of records to return (page size).
|
|
1183
|
+
* @param getSearchesNoResults.offset - Position of the starting record. Used for paging. 0 is the first record.
|
|
1184
|
+
* @param getSearchesNoResults.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1185
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1186
|
+
*/
|
|
1187
|
+
getSearchesNoResults({ index, startDate, endDate, limit, offset, tags, }, requestOptions) {
|
|
1188
|
+
if (!index) {
|
|
1189
|
+
throw new Error('Parameter `index` is required when calling `getSearchesNoResults`.');
|
|
1190
|
+
}
|
|
1191
|
+
const requestPath = '/2/searches/noResults';
|
|
1192
|
+
const headers = {};
|
|
1193
|
+
const queryParameters = {};
|
|
1194
|
+
if (index !== undefined) {
|
|
1195
|
+
queryParameters.index = index.toString();
|
|
1196
|
+
}
|
|
1197
|
+
if (startDate !== undefined) {
|
|
1198
|
+
queryParameters.startDate = startDate.toString();
|
|
1199
|
+
}
|
|
1200
|
+
if (endDate !== undefined) {
|
|
1201
|
+
queryParameters.endDate = endDate.toString();
|
|
1202
|
+
}
|
|
1203
|
+
if (limit !== undefined) {
|
|
1204
|
+
queryParameters.limit = limit.toString();
|
|
1205
|
+
}
|
|
1206
|
+
if (offset !== undefined) {
|
|
1207
|
+
queryParameters.offset = offset.toString();
|
|
1208
|
+
}
|
|
1209
|
+
if (tags !== undefined) {
|
|
1210
|
+
queryParameters.tags = tags.toString();
|
|
1211
|
+
}
|
|
1212
|
+
const request = {
|
|
1213
|
+
method: 'GET',
|
|
1214
|
+
path: requestPath,
|
|
1215
|
+
queryParameters,
|
|
1216
|
+
headers,
|
|
1217
|
+
};
|
|
1218
|
+
return transporter.request(request, requestOptions);
|
|
1219
|
+
},
|
|
1220
|
+
/**
|
|
1221
|
+
* Return the latest update time of the Analytics API for an index. If the index has been recently created or no search has been performed yet, `updatedAt` will be `null`. > **Note**: The Analytics API is updated every 5 minutes.
|
|
1222
|
+
*
|
|
1223
|
+
* Required API Key ACLs:
|
|
1224
|
+
* - analytics.
|
|
1225
|
+
*
|
|
1226
|
+
* @param getStatus - The getStatus object.
|
|
1227
|
+
* @param getStatus.index - Index name to target.
|
|
1228
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1229
|
+
*/
|
|
1230
|
+
getStatus({ index }, requestOptions) {
|
|
1231
|
+
if (!index) {
|
|
1232
|
+
throw new Error('Parameter `index` is required when calling `getStatus`.');
|
|
1233
|
+
}
|
|
1234
|
+
const requestPath = '/2/status';
|
|
1235
|
+
const headers = {};
|
|
1236
|
+
const queryParameters = {};
|
|
1237
|
+
if (index !== undefined) {
|
|
1238
|
+
queryParameters.index = index.toString();
|
|
1239
|
+
}
|
|
1240
|
+
const request = {
|
|
1241
|
+
method: 'GET',
|
|
1242
|
+
path: requestPath,
|
|
1243
|
+
queryParameters,
|
|
1244
|
+
headers,
|
|
1245
|
+
};
|
|
1246
|
+
return transporter.request(request, requestOptions);
|
|
1247
|
+
},
|
|
1248
|
+
/**
|
|
1249
|
+
* Returns top countries. Limited to the 1,000 most frequent ones.
|
|
1250
|
+
*
|
|
1251
|
+
* Required API Key ACLs:
|
|
1252
|
+
* - analytics.
|
|
1253
|
+
*
|
|
1254
|
+
* @param getTopCountries - The getTopCountries object.
|
|
1255
|
+
* @param getTopCountries.index - Index name to target.
|
|
1256
|
+
* @param getTopCountries.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1257
|
+
* @param getTopCountries.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1258
|
+
* @param getTopCountries.limit - Number of records to return (page size).
|
|
1259
|
+
* @param getTopCountries.offset - Position of the starting record. Used for paging. 0 is the first record.
|
|
1260
|
+
* @param getTopCountries.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1261
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1262
|
+
*/
|
|
1263
|
+
getTopCountries({ index, startDate, endDate, limit, offset, tags }, requestOptions) {
|
|
1264
|
+
if (!index) {
|
|
1265
|
+
throw new Error('Parameter `index` is required when calling `getTopCountries`.');
|
|
1266
|
+
}
|
|
1267
|
+
const requestPath = '/2/countries';
|
|
1268
|
+
const headers = {};
|
|
1269
|
+
const queryParameters = {};
|
|
1270
|
+
if (index !== undefined) {
|
|
1271
|
+
queryParameters.index = index.toString();
|
|
1272
|
+
}
|
|
1273
|
+
if (startDate !== undefined) {
|
|
1274
|
+
queryParameters.startDate = startDate.toString();
|
|
1275
|
+
}
|
|
1276
|
+
if (endDate !== undefined) {
|
|
1277
|
+
queryParameters.endDate = endDate.toString();
|
|
1278
|
+
}
|
|
1279
|
+
if (limit !== undefined) {
|
|
1280
|
+
queryParameters.limit = limit.toString();
|
|
1281
|
+
}
|
|
1282
|
+
if (offset !== undefined) {
|
|
1283
|
+
queryParameters.offset = offset.toString();
|
|
1284
|
+
}
|
|
1285
|
+
if (tags !== undefined) {
|
|
1286
|
+
queryParameters.tags = tags.toString();
|
|
1287
|
+
}
|
|
1288
|
+
const request = {
|
|
1289
|
+
method: 'GET',
|
|
1290
|
+
path: requestPath,
|
|
1291
|
+
queryParameters,
|
|
1292
|
+
headers,
|
|
1293
|
+
};
|
|
1294
|
+
return transporter.request(request, requestOptions);
|
|
1295
|
+
},
|
|
1296
|
+
/**
|
|
1297
|
+
* Return the most popular [filterable attributes](https://www.algolia.com/doc/guides/managing-results/refine-results/filtering/) in the 1,000 most recently used filters.
|
|
1298
|
+
*
|
|
1299
|
+
* Required API Key ACLs:
|
|
1300
|
+
* - analytics.
|
|
1301
|
+
*
|
|
1302
|
+
* @param getTopFilterAttributes - The getTopFilterAttributes object.
|
|
1303
|
+
* @param getTopFilterAttributes.index - Index name to target.
|
|
1304
|
+
* @param getTopFilterAttributes.search - User query.
|
|
1305
|
+
* @param getTopFilterAttributes.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1306
|
+
* @param getTopFilterAttributes.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1307
|
+
* @param getTopFilterAttributes.limit - Number of records to return (page size).
|
|
1308
|
+
* @param getTopFilterAttributes.offset - Position of the starting record. Used for paging. 0 is the first record.
|
|
1309
|
+
* @param getTopFilterAttributes.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1310
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1311
|
+
*/
|
|
1312
|
+
getTopFilterAttributes({ index, search, startDate, endDate, limit, offset, tags, }, requestOptions) {
|
|
1313
|
+
if (!index) {
|
|
1314
|
+
throw new Error('Parameter `index` is required when calling `getTopFilterAttributes`.');
|
|
1315
|
+
}
|
|
1316
|
+
const requestPath = '/2/filters';
|
|
1317
|
+
const headers = {};
|
|
1318
|
+
const queryParameters = {};
|
|
1319
|
+
if (index !== undefined) {
|
|
1320
|
+
queryParameters.index = index.toString();
|
|
1321
|
+
}
|
|
1322
|
+
if (search !== undefined) {
|
|
1323
|
+
queryParameters.search = search.toString();
|
|
1324
|
+
}
|
|
1325
|
+
if (startDate !== undefined) {
|
|
1326
|
+
queryParameters.startDate = startDate.toString();
|
|
1327
|
+
}
|
|
1328
|
+
if (endDate !== undefined) {
|
|
1329
|
+
queryParameters.endDate = endDate.toString();
|
|
1330
|
+
}
|
|
1331
|
+
if (limit !== undefined) {
|
|
1332
|
+
queryParameters.limit = limit.toString();
|
|
1333
|
+
}
|
|
1334
|
+
if (offset !== undefined) {
|
|
1335
|
+
queryParameters.offset = offset.toString();
|
|
1336
|
+
}
|
|
1337
|
+
if (tags !== undefined) {
|
|
1338
|
+
queryParameters.tags = tags.toString();
|
|
1339
|
+
}
|
|
1340
|
+
const request = {
|
|
1341
|
+
method: 'GET',
|
|
1342
|
+
path: requestPath,
|
|
1343
|
+
queryParameters,
|
|
1344
|
+
headers,
|
|
1345
|
+
};
|
|
1346
|
+
return transporter.request(request, requestOptions);
|
|
1347
|
+
},
|
|
1348
|
+
/**
|
|
1349
|
+
* Returns the most popular filter values for an attribute in the 1,000 most recently used filters.
|
|
1350
|
+
*
|
|
1351
|
+
* Required API Key ACLs:
|
|
1352
|
+
* - analytics.
|
|
1353
|
+
*
|
|
1354
|
+
* @param getTopFilterForAttribute - The getTopFilterForAttribute object.
|
|
1355
|
+
* @param getTopFilterForAttribute.attribute - Attribute name.
|
|
1356
|
+
* @param getTopFilterForAttribute.index - Index name to target.
|
|
1357
|
+
* @param getTopFilterForAttribute.search - User query.
|
|
1358
|
+
* @param getTopFilterForAttribute.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1359
|
+
* @param getTopFilterForAttribute.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1360
|
+
* @param getTopFilterForAttribute.limit - Number of records to return (page size).
|
|
1361
|
+
* @param getTopFilterForAttribute.offset - Position of the starting record. Used for paging. 0 is the first record.
|
|
1362
|
+
* @param getTopFilterForAttribute.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1363
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1364
|
+
*/
|
|
1365
|
+
getTopFilterForAttribute({ attribute, index, search, startDate, endDate, limit, offset, tags, }, requestOptions) {
|
|
1366
|
+
if (!attribute) {
|
|
1367
|
+
throw new Error('Parameter `attribute` is required when calling `getTopFilterForAttribute`.');
|
|
1368
|
+
}
|
|
1369
|
+
if (!index) {
|
|
1370
|
+
throw new Error('Parameter `index` is required when calling `getTopFilterForAttribute`.');
|
|
1371
|
+
}
|
|
1372
|
+
const requestPath = '/2/filters/{attribute}'.replace('{attribute}', encodeURIComponent(attribute));
|
|
1373
|
+
const headers = {};
|
|
1374
|
+
const queryParameters = {};
|
|
1375
|
+
if (index !== undefined) {
|
|
1376
|
+
queryParameters.index = index.toString();
|
|
1377
|
+
}
|
|
1378
|
+
if (search !== undefined) {
|
|
1379
|
+
queryParameters.search = search.toString();
|
|
1380
|
+
}
|
|
1381
|
+
if (startDate !== undefined) {
|
|
1382
|
+
queryParameters.startDate = startDate.toString();
|
|
1383
|
+
}
|
|
1384
|
+
if (endDate !== undefined) {
|
|
1385
|
+
queryParameters.endDate = endDate.toString();
|
|
1386
|
+
}
|
|
1387
|
+
if (limit !== undefined) {
|
|
1388
|
+
queryParameters.limit = limit.toString();
|
|
1389
|
+
}
|
|
1390
|
+
if (offset !== undefined) {
|
|
1391
|
+
queryParameters.offset = offset.toString();
|
|
1392
|
+
}
|
|
1393
|
+
if (tags !== undefined) {
|
|
1394
|
+
queryParameters.tags = tags.toString();
|
|
1395
|
+
}
|
|
1396
|
+
const request = {
|
|
1397
|
+
method: 'GET',
|
|
1398
|
+
path: requestPath,
|
|
1399
|
+
queryParameters,
|
|
1400
|
+
headers,
|
|
1401
|
+
};
|
|
1402
|
+
return transporter.request(request, requestOptions);
|
|
1403
|
+
},
|
|
1404
|
+
/**
|
|
1405
|
+
* Returns top filters for filter-enabled searches that don\'t return results. Limited to the 1,000 most recently used filters.
|
|
1406
|
+
*
|
|
1407
|
+
* Required API Key ACLs:
|
|
1408
|
+
* - analytics.
|
|
1409
|
+
*
|
|
1410
|
+
* @param getTopFiltersNoResults - The getTopFiltersNoResults object.
|
|
1411
|
+
* @param getTopFiltersNoResults.index - Index name to target.
|
|
1412
|
+
* @param getTopFiltersNoResults.search - User query.
|
|
1413
|
+
* @param getTopFiltersNoResults.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1414
|
+
* @param getTopFiltersNoResults.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1415
|
+
* @param getTopFiltersNoResults.limit - Number of records to return (page size).
|
|
1416
|
+
* @param getTopFiltersNoResults.offset - Position of the starting record. Used for paging. 0 is the first record.
|
|
1417
|
+
* @param getTopFiltersNoResults.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1418
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1419
|
+
*/
|
|
1420
|
+
getTopFiltersNoResults({ index, search, startDate, endDate, limit, offset, tags, }, requestOptions) {
|
|
1421
|
+
if (!index) {
|
|
1422
|
+
throw new Error('Parameter `index` is required when calling `getTopFiltersNoResults`.');
|
|
1423
|
+
}
|
|
1424
|
+
const requestPath = '/2/filters/noResults';
|
|
1425
|
+
const headers = {};
|
|
1426
|
+
const queryParameters = {};
|
|
1427
|
+
if (index !== undefined) {
|
|
1428
|
+
queryParameters.index = index.toString();
|
|
1429
|
+
}
|
|
1430
|
+
if (search !== undefined) {
|
|
1431
|
+
queryParameters.search = search.toString();
|
|
1432
|
+
}
|
|
1433
|
+
if (startDate !== undefined) {
|
|
1434
|
+
queryParameters.startDate = startDate.toString();
|
|
1435
|
+
}
|
|
1436
|
+
if (endDate !== undefined) {
|
|
1437
|
+
queryParameters.endDate = endDate.toString();
|
|
1438
|
+
}
|
|
1439
|
+
if (limit !== undefined) {
|
|
1440
|
+
queryParameters.limit = limit.toString();
|
|
1441
|
+
}
|
|
1442
|
+
if (offset !== undefined) {
|
|
1443
|
+
queryParameters.offset = offset.toString();
|
|
1444
|
+
}
|
|
1445
|
+
if (tags !== undefined) {
|
|
1446
|
+
queryParameters.tags = tags.toString();
|
|
1447
|
+
}
|
|
1448
|
+
const request = {
|
|
1449
|
+
method: 'GET',
|
|
1450
|
+
path: requestPath,
|
|
1451
|
+
queryParameters,
|
|
1452
|
+
headers,
|
|
1453
|
+
};
|
|
1454
|
+
return transporter.request(request, requestOptions);
|
|
1455
|
+
},
|
|
1456
|
+
/**
|
|
1457
|
+
* Return the most popular clicked results in the last 1,000 searches.
|
|
1458
|
+
*
|
|
1459
|
+
* Required API Key ACLs:
|
|
1460
|
+
* - analytics.
|
|
1461
|
+
*
|
|
1462
|
+
* @param getTopHits - The getTopHits object.
|
|
1463
|
+
* @param getTopHits.index - Index name to target.
|
|
1464
|
+
* @param getTopHits.search - User query.
|
|
1465
|
+
* @param getTopHits.clickAnalytics - Whether to include [click and conversion](https://www.algolia.com/doc/guides/sending-events/getting-started/) rates for a search.
|
|
1466
|
+
* @param getTopHits.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1467
|
+
* @param getTopHits.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1468
|
+
* @param getTopHits.limit - Number of records to return (page size).
|
|
1469
|
+
* @param getTopHits.offset - Position of the starting record. Used for paging. 0 is the first record.
|
|
1470
|
+
* @param getTopHits.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1471
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1472
|
+
*/
|
|
1473
|
+
getTopHits({ index, search, clickAnalytics, startDate, endDate, limit, offset, tags, }, requestOptions) {
|
|
1474
|
+
if (!index) {
|
|
1475
|
+
throw new Error('Parameter `index` is required when calling `getTopHits`.');
|
|
1476
|
+
}
|
|
1477
|
+
const requestPath = '/2/hits';
|
|
1478
|
+
const headers = {};
|
|
1479
|
+
const queryParameters = {};
|
|
1480
|
+
if (index !== undefined) {
|
|
1481
|
+
queryParameters.index = index.toString();
|
|
1482
|
+
}
|
|
1483
|
+
if (search !== undefined) {
|
|
1484
|
+
queryParameters.search = search.toString();
|
|
1485
|
+
}
|
|
1486
|
+
if (clickAnalytics !== undefined) {
|
|
1487
|
+
queryParameters.clickAnalytics = clickAnalytics.toString();
|
|
1488
|
+
}
|
|
1489
|
+
if (startDate !== undefined) {
|
|
1490
|
+
queryParameters.startDate = startDate.toString();
|
|
1491
|
+
}
|
|
1492
|
+
if (endDate !== undefined) {
|
|
1493
|
+
queryParameters.endDate = endDate.toString();
|
|
1494
|
+
}
|
|
1495
|
+
if (limit !== undefined) {
|
|
1496
|
+
queryParameters.limit = limit.toString();
|
|
1497
|
+
}
|
|
1498
|
+
if (offset !== undefined) {
|
|
1499
|
+
queryParameters.offset = offset.toString();
|
|
1500
|
+
}
|
|
1501
|
+
if (tags !== undefined) {
|
|
1502
|
+
queryParameters.tags = tags.toString();
|
|
1503
|
+
}
|
|
1504
|
+
const request = {
|
|
1505
|
+
method: 'GET',
|
|
1506
|
+
path: requestPath,
|
|
1507
|
+
queryParameters,
|
|
1508
|
+
headers,
|
|
1509
|
+
};
|
|
1510
|
+
return transporter.request(request, requestOptions);
|
|
1511
|
+
},
|
|
1512
|
+
/**
|
|
1513
|
+
* Returns the most popular of the latest 1,000 searches. For each search, also returns the number of hits.
|
|
1514
|
+
*
|
|
1515
|
+
* Required API Key ACLs:
|
|
1516
|
+
* - analytics.
|
|
1517
|
+
*
|
|
1518
|
+
* @param getTopSearches - The getTopSearches object.
|
|
1519
|
+
* @param getTopSearches.index - Index name to target.
|
|
1520
|
+
* @param getTopSearches.clickAnalytics - Whether to include [click and conversion](https://www.algolia.com/doc/guides/sending-events/getting-started/) rates for a search.
|
|
1521
|
+
* @param getTopSearches.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1522
|
+
* @param getTopSearches.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1523
|
+
* @param getTopSearches.orderBy - Reorder the results.
|
|
1524
|
+
* @param getTopSearches.direction - Sorting direction of the results: ascending or descending.
|
|
1525
|
+
* @param getTopSearches.limit - Number of records to return (page size).
|
|
1526
|
+
* @param getTopSearches.offset - Position of the starting record. Used for paging. 0 is the first record.
|
|
1527
|
+
* @param getTopSearches.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1528
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1529
|
+
*/
|
|
1530
|
+
getTopSearches({ index, clickAnalytics, startDate, endDate, orderBy, direction, limit, offset, tags, }, requestOptions) {
|
|
1531
|
+
if (!index) {
|
|
1532
|
+
throw new Error('Parameter `index` is required when calling `getTopSearches`.');
|
|
1533
|
+
}
|
|
1534
|
+
const requestPath = '/2/searches';
|
|
1535
|
+
const headers = {};
|
|
1536
|
+
const queryParameters = {};
|
|
1537
|
+
if (index !== undefined) {
|
|
1538
|
+
queryParameters.index = index.toString();
|
|
1539
|
+
}
|
|
1540
|
+
if (clickAnalytics !== undefined) {
|
|
1541
|
+
queryParameters.clickAnalytics = clickAnalytics.toString();
|
|
1542
|
+
}
|
|
1543
|
+
if (startDate !== undefined) {
|
|
1544
|
+
queryParameters.startDate = startDate.toString();
|
|
1545
|
+
}
|
|
1546
|
+
if (endDate !== undefined) {
|
|
1547
|
+
queryParameters.endDate = endDate.toString();
|
|
1548
|
+
}
|
|
1549
|
+
if (orderBy !== undefined) {
|
|
1550
|
+
queryParameters.orderBy = orderBy.toString();
|
|
1551
|
+
}
|
|
1552
|
+
if (direction !== undefined) {
|
|
1553
|
+
queryParameters.direction = direction.toString();
|
|
1554
|
+
}
|
|
1555
|
+
if (limit !== undefined) {
|
|
1556
|
+
queryParameters.limit = limit.toString();
|
|
1557
|
+
}
|
|
1558
|
+
if (offset !== undefined) {
|
|
1559
|
+
queryParameters.offset = offset.toString();
|
|
1560
|
+
}
|
|
1561
|
+
if (tags !== undefined) {
|
|
1562
|
+
queryParameters.tags = tags.toString();
|
|
1563
|
+
}
|
|
1564
|
+
const request = {
|
|
1565
|
+
method: 'GET',
|
|
1566
|
+
path: requestPath,
|
|
1567
|
+
queryParameters,
|
|
1568
|
+
headers,
|
|
1569
|
+
};
|
|
1570
|
+
return transporter.request(request, requestOptions);
|
|
1571
|
+
},
|
|
1572
|
+
/**
|
|
1573
|
+
* Return the count of unique users.
|
|
1574
|
+
*
|
|
1575
|
+
* Required API Key ACLs:
|
|
1576
|
+
* - analytics.
|
|
1577
|
+
*
|
|
1578
|
+
* @param getUsersCount - The getUsersCount object.
|
|
1579
|
+
* @param getUsersCount.index - Index name to target.
|
|
1580
|
+
* @param getUsersCount.startDate - Start date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1581
|
+
* @param getUsersCount.endDate - End date (a string in the format `YYYY-MM-DD`) of the period to analyze.
|
|
1582
|
+
* @param getUsersCount.tags - Filter analytics on the [`analyticsTags`](https://www.algolia.com/doc/api-reference/api-parameters/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 must be URL-encoded.
|
|
1583
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1584
|
+
*/
|
|
1585
|
+
getUsersCount({ index, startDate, endDate, tags }, requestOptions) {
|
|
1586
|
+
if (!index) {
|
|
1587
|
+
throw new Error('Parameter `index` is required when calling `getUsersCount`.');
|
|
1588
|
+
}
|
|
1589
|
+
const requestPath = '/2/users/count';
|
|
1590
|
+
const headers = {};
|
|
1591
|
+
const queryParameters = {};
|
|
1592
|
+
if (index !== undefined) {
|
|
1593
|
+
queryParameters.index = index.toString();
|
|
1594
|
+
}
|
|
1595
|
+
if (startDate !== undefined) {
|
|
1596
|
+
queryParameters.startDate = startDate.toString();
|
|
1597
|
+
}
|
|
1598
|
+
if (endDate !== undefined) {
|
|
1599
|
+
queryParameters.endDate = endDate.toString();
|
|
1600
|
+
}
|
|
1601
|
+
if (tags !== undefined) {
|
|
1602
|
+
queryParameters.tags = tags.toString();
|
|
1603
|
+
}
|
|
1604
|
+
const request = {
|
|
1605
|
+
method: 'GET',
|
|
1606
|
+
path: requestPath,
|
|
1607
|
+
queryParameters,
|
|
1608
|
+
headers,
|
|
1609
|
+
};
|
|
1610
|
+
return transporter.request(request, requestOptions);
|
|
1611
|
+
},
|
|
1612
|
+
};
|
|
1594
1613
|
}
|
|
1595
1614
|
|
|
1596
|
-
//
|
|
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
|
-
});
|
|
1615
|
+
// 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.
|
|
1616
|
+
function analyticsClient(appId, apiKey, region, options) {
|
|
1617
|
+
if (!appId || typeof appId !== 'string') {
|
|
1618
|
+
throw new Error('`appId` is missing.');
|
|
1619
|
+
}
|
|
1620
|
+
if (!apiKey || typeof apiKey !== 'string') {
|
|
1621
|
+
throw new Error('`apiKey` is missing.');
|
|
1622
|
+
}
|
|
1623
|
+
if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
|
|
1624
|
+
throw new Error(`\`region\` must be one of the following: ${REGIONS.join(', ')}`);
|
|
1625
|
+
}
|
|
1626
|
+
return createAnalyticsClient({
|
|
1627
|
+
appId,
|
|
1628
|
+
apiKey,
|
|
1629
|
+
region,
|
|
1630
|
+
timeouts: {
|
|
1631
|
+
connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
|
|
1632
|
+
read: DEFAULT_READ_TIMEOUT_BROWSER,
|
|
1633
|
+
write: DEFAULT_WRITE_TIMEOUT_BROWSER,
|
|
1634
|
+
},
|
|
1635
|
+
requester: createXhrRequester(),
|
|
1636
|
+
algoliaAgents: [{ segment: 'Browser' }],
|
|
1637
|
+
authMode: 'WithinQueryParameters',
|
|
1638
|
+
responsesCache: createMemoryCache(),
|
|
1639
|
+
requestsCache: createMemoryCache({ serializable: false }),
|
|
1640
|
+
hostsCache: createFallbackableCache({
|
|
1641
|
+
caches: [
|
|
1642
|
+
createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }),
|
|
1643
|
+
createMemoryCache(),
|
|
1644
|
+
],
|
|
1645
|
+
}),
|
|
1646
|
+
...options,
|
|
1647
|
+
});
|
|
1629
1648
|
}
|
|
1630
1649
|
|
|
1631
1650
|
export { analyticsClient, apiClientVersion };
|