algoliasearch 5.0.0-alpha.25 → 5.0.0-alpha.27
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/algoliasearch.cjs.js +4 -4
- package/dist/algoliasearch.esm.browser.js +28 -110
- package/dist/algoliasearch.esm.node.js +4 -4
- package/dist/algoliasearch.umd.js +2 -2
- package/dist/builds/browser.d.ts +1 -1
- package/dist/builds/node.d.ts +1 -1
- package/dist/client-abtesting/src/abtestingClient.d.ts +1 -1
- package/dist/client-analytics/src/analyticsClient.d.ts +1 -1
- package/dist/client-personalization/src/personalizationClient.d.ts +1 -1
- package/dist/client-search/src/searchClient.d.ts +1 -1
- package/dist/lite/lite.cjs.js +1 -1
- package/dist/lite/lite.esm.browser.js +25 -103
- package/dist/lite/lite.esm.node.js +1 -1
- package/dist/lite/lite.umd.js +2 -2
- package/dist/lite/src/liteClient.d.ts +1 -1
- package/lite/src/liteClient.ts +1 -1
- package/package.json +9 -9
|
@@ -6,7 +6,7 @@ var clientCommon = require('@algolia/client-common');
|
|
|
6
6
|
var requesterNodeHttp = require('@algolia/requester-node-http');
|
|
7
7
|
|
|
8
8
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
9
|
-
const apiClientVersion$4 = '5.0.0-alpha.
|
|
9
|
+
const apiClientVersion$4 = '5.0.0-alpha.27';
|
|
10
10
|
const REGIONS$2 = ['de', 'us'];
|
|
11
11
|
function getDefaultHosts$3(region) {
|
|
12
12
|
const url = !region
|
|
@@ -297,7 +297,7 @@ function createAbtestingClient({ appId: appIdOption, apiKey: apiKeyOption, authM
|
|
|
297
297
|
}
|
|
298
298
|
|
|
299
299
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
300
|
-
const apiClientVersion$3 = '5.0.0-alpha.
|
|
300
|
+
const apiClientVersion$3 = '5.0.0-alpha.27';
|
|
301
301
|
const REGIONS$1 = ['de', 'us'];
|
|
302
302
|
function getDefaultHosts$2(region) {
|
|
303
303
|
const url = !region
|
|
@@ -1194,7 +1194,7 @@ function createAnalyticsClient({ appId: appIdOption, apiKey: apiKeyOption, authM
|
|
|
1194
1194
|
}
|
|
1195
1195
|
|
|
1196
1196
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
1197
|
-
const apiClientVersion$2 = '5.0.0-alpha.
|
|
1197
|
+
const apiClientVersion$2 = '5.0.0-alpha.27';
|
|
1198
1198
|
const REGIONS = ['eu', 'us'];
|
|
1199
1199
|
function getDefaultHosts$1(region) {
|
|
1200
1200
|
const url = 'personalization.{region}.algolia.com'.replace('{region}', region);
|
|
@@ -1451,7 +1451,7 @@ function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption,
|
|
|
1451
1451
|
}
|
|
1452
1452
|
|
|
1453
1453
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
1454
|
-
const apiClientVersion$1 = '5.0.0-alpha.
|
|
1454
|
+
const apiClientVersion$1 = '5.0.0-alpha.27';
|
|
1455
1455
|
function getDefaultHosts(appId) {
|
|
1456
1456
|
return [
|
|
1457
1457
|
{
|
|
@@ -7,11 +7,9 @@ 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
|
|
|
@@ -38,15 +36,12 @@ function createIterablePromise({
|
|
|
38
36
|
if (aggregator) {
|
|
39
37
|
aggregator(response);
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
if (validate(response)) {
|
|
43
40
|
return resolve(response);
|
|
44
41
|
}
|
|
45
|
-
|
|
46
42
|
if (error && error.validate(response)) {
|
|
47
43
|
return reject(new Error(error.message(response)));
|
|
48
44
|
}
|
|
49
|
-
|
|
50
45
|
return setTimeout(() => {
|
|
51
46
|
retry(response).then(resolve).catch(reject);
|
|
52
47
|
}, timeout());
|
|
@@ -55,27 +50,22 @@ function createIterablePromise({
|
|
|
55
50
|
});
|
|
56
51
|
});
|
|
57
52
|
};
|
|
58
|
-
|
|
59
53
|
return retry();
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
function createBrowserLocalStorageCache(options) {
|
|
63
|
-
let storage;
|
|
64
|
-
|
|
57
|
+
let storage;
|
|
58
|
+
// We've changed the namespace to avoid conflicts with v4, as this version is a huge breaking change
|
|
65
59
|
const namespaceKey = `algolia-client-js-${options.key}`;
|
|
66
|
-
|
|
67
60
|
function getStorage() {
|
|
68
61
|
if (storage === undefined) {
|
|
69
62
|
storage = options.localStorage || window.localStorage;
|
|
70
63
|
}
|
|
71
|
-
|
|
72
64
|
return storage;
|
|
73
65
|
}
|
|
74
|
-
|
|
75
66
|
function getNamespace() {
|
|
76
67
|
return JSON.parse(getStorage().getItem(namespaceKey) || '{}');
|
|
77
68
|
}
|
|
78
|
-
|
|
79
69
|
return {
|
|
80
70
|
get(key, defaultValue, events = {
|
|
81
71
|
miss: () => Promise.resolve()
|
|
@@ -88,7 +78,6 @@ function createBrowserLocalStorageCache(options) {
|
|
|
88
78
|
return Promise.all([value, exists || events.miss(value)]);
|
|
89
79
|
}).then(([value]) => value);
|
|
90
80
|
},
|
|
91
|
-
|
|
92
81
|
set(key, value) {
|
|
93
82
|
return Promise.resolve().then(() => {
|
|
94
83
|
const namespace = getNamespace();
|
|
@@ -97,7 +86,6 @@ function createBrowserLocalStorageCache(options) {
|
|
|
97
86
|
return value;
|
|
98
87
|
});
|
|
99
88
|
},
|
|
100
|
-
|
|
101
89
|
delete(key) {
|
|
102
90
|
return Promise.resolve().then(() => {
|
|
103
91
|
const namespace = getNamespace();
|
|
@@ -105,13 +93,11 @@ function createBrowserLocalStorageCache(options) {
|
|
|
105
93
|
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
|
106
94
|
});
|
|
107
95
|
},
|
|
108
|
-
|
|
109
96
|
clear() {
|
|
110
97
|
return Promise.resolve().then(() => {
|
|
111
98
|
getStorage().removeItem(namespaceKey);
|
|
112
99
|
});
|
|
113
100
|
}
|
|
114
|
-
|
|
115
101
|
};
|
|
116
102
|
}
|
|
117
103
|
|
|
@@ -123,30 +109,24 @@ function createNullCache() {
|
|
|
123
109
|
const value = defaultValue();
|
|
124
110
|
return value.then(result => Promise.all([result, events.miss(result)])).then(([result]) => result);
|
|
125
111
|
},
|
|
126
|
-
|
|
127
112
|
set(_key, value) {
|
|
128
113
|
return Promise.resolve(value);
|
|
129
114
|
},
|
|
130
|
-
|
|
131
115
|
delete(_key) {
|
|
132
116
|
return Promise.resolve();
|
|
133
117
|
},
|
|
134
|
-
|
|
135
118
|
clear() {
|
|
136
119
|
return Promise.resolve();
|
|
137
120
|
}
|
|
138
|
-
|
|
139
121
|
};
|
|
140
122
|
}
|
|
141
123
|
|
|
142
124
|
function createFallbackableCache(options) {
|
|
143
125
|
const caches = [...options.caches];
|
|
144
126
|
const current = caches.shift();
|
|
145
|
-
|
|
146
127
|
if (current === undefined) {
|
|
147
128
|
return createNullCache();
|
|
148
129
|
}
|
|
149
|
-
|
|
150
130
|
return {
|
|
151
131
|
get(key, defaultValue, events = {
|
|
152
132
|
miss: () => Promise.resolve()
|
|
@@ -157,7 +137,6 @@ function createFallbackableCache(options) {
|
|
|
157
137
|
}).get(key, defaultValue, events);
|
|
158
138
|
});
|
|
159
139
|
},
|
|
160
|
-
|
|
161
140
|
set(key, value) {
|
|
162
141
|
return current.set(key, value).catch(() => {
|
|
163
142
|
return createFallbackableCache({
|
|
@@ -165,7 +144,6 @@ function createFallbackableCache(options) {
|
|
|
165
144
|
}).set(key, value);
|
|
166
145
|
});
|
|
167
146
|
},
|
|
168
|
-
|
|
169
147
|
delete(key) {
|
|
170
148
|
return current.delete(key).catch(() => {
|
|
171
149
|
return createFallbackableCache({
|
|
@@ -173,7 +151,6 @@ function createFallbackableCache(options) {
|
|
|
173
151
|
}).delete(key);
|
|
174
152
|
});
|
|
175
153
|
},
|
|
176
|
-
|
|
177
154
|
clear() {
|
|
178
155
|
return current.clear().catch(() => {
|
|
179
156
|
return createFallbackableCache({
|
|
@@ -181,7 +158,6 @@ function createFallbackableCache(options) {
|
|
|
181
158
|
}).clear();
|
|
182
159
|
});
|
|
183
160
|
}
|
|
184
|
-
|
|
185
161
|
};
|
|
186
162
|
}
|
|
187
163
|
|
|
@@ -194,30 +170,24 @@ function createMemoryCache(options = {
|
|
|
194
170
|
miss: () => Promise.resolve()
|
|
195
171
|
}) {
|
|
196
172
|
const keyAsString = JSON.stringify(key);
|
|
197
|
-
|
|
198
173
|
if (keyAsString in cache) {
|
|
199
174
|
return Promise.resolve(options.serializable ? JSON.parse(cache[keyAsString]) : cache[keyAsString]);
|
|
200
175
|
}
|
|
201
|
-
|
|
202
176
|
const promise = defaultValue();
|
|
203
177
|
return promise.then(value => events.miss(value)).then(() => promise);
|
|
204
178
|
},
|
|
205
|
-
|
|
206
179
|
set(key, value) {
|
|
207
180
|
cache[JSON.stringify(key)] = options.serializable ? JSON.stringify(value) : value;
|
|
208
181
|
return Promise.resolve(value);
|
|
209
182
|
},
|
|
210
|
-
|
|
211
183
|
delete(key) {
|
|
212
184
|
delete cache[JSON.stringify(key)];
|
|
213
185
|
return Promise.resolve();
|
|
214
186
|
},
|
|
215
|
-
|
|
216
187
|
clear() {
|
|
217
188
|
cache = {};
|
|
218
189
|
return Promise.resolve();
|
|
219
190
|
}
|
|
220
|
-
|
|
221
191
|
};
|
|
222
192
|
}
|
|
223
193
|
|
|
@@ -226,16 +196,14 @@ function createMemoryCache(options = {
|
|
|
226
196
|
const EXPIRATION_DELAY = 2 * 60 * 1000;
|
|
227
197
|
function createStatefulHost(host, status = 'up') {
|
|
228
198
|
const lastUpdate = Date.now();
|
|
229
|
-
|
|
230
199
|
function isUp() {
|
|
231
200
|
return status === 'up' || Date.now() - lastUpdate > EXPIRATION_DELAY;
|
|
232
201
|
}
|
|
233
|
-
|
|
234
202
|
function isTimedOut() {
|
|
235
203
|
return status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY;
|
|
236
204
|
}
|
|
237
|
-
|
|
238
|
-
|
|
205
|
+
return {
|
|
206
|
+
...host,
|
|
239
207
|
status,
|
|
240
208
|
lastUpdate,
|
|
241
209
|
isUp,
|
|
@@ -254,92 +222,74 @@ function _defineProperty(obj, key, value) {
|
|
|
254
222
|
} else {
|
|
255
223
|
obj[key] = value;
|
|
256
224
|
}
|
|
257
|
-
|
|
258
225
|
return obj;
|
|
259
226
|
}
|
|
260
227
|
|
|
261
228
|
class AlgoliaError extends Error {
|
|
262
229
|
constructor(message, name) {
|
|
263
230
|
super(message);
|
|
264
|
-
|
|
265
231
|
_defineProperty(this, "name", 'AlgoliaError');
|
|
266
|
-
|
|
267
232
|
if (name) {
|
|
268
233
|
this.name = name;
|
|
269
234
|
}
|
|
270
235
|
}
|
|
271
|
-
|
|
272
236
|
}
|
|
273
237
|
class ErrorWithStackTrace extends AlgoliaError {
|
|
274
238
|
constructor(message, stackTrace, name) {
|
|
275
|
-
super(message, name);
|
|
276
|
-
|
|
239
|
+
super(message, name);
|
|
240
|
+
// the array and object should be frozen to reflect the stackTrace at the time of the error
|
|
277
241
|
_defineProperty(this, "stackTrace", void 0);
|
|
278
|
-
|
|
279
242
|
this.stackTrace = stackTrace;
|
|
280
243
|
}
|
|
281
|
-
|
|
282
244
|
}
|
|
283
245
|
class RetryError extends ErrorWithStackTrace {
|
|
284
246
|
constructor(stackTrace) {
|
|
285
247
|
super('Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.', stackTrace, 'RetryError');
|
|
286
248
|
}
|
|
287
|
-
|
|
288
249
|
}
|
|
289
250
|
class ApiError extends ErrorWithStackTrace {
|
|
290
251
|
constructor(message, status, stackTrace) {
|
|
291
252
|
super(message, stackTrace, 'ApiError');
|
|
292
|
-
|
|
293
253
|
_defineProperty(this, "status", void 0);
|
|
294
|
-
|
|
295
254
|
this.status = status;
|
|
296
255
|
}
|
|
297
|
-
|
|
298
256
|
}
|
|
299
257
|
class DeserializationError extends AlgoliaError {
|
|
300
258
|
constructor(message, response) {
|
|
301
259
|
super(message, 'DeserializationError');
|
|
302
|
-
|
|
303
260
|
_defineProperty(this, "response", void 0);
|
|
304
|
-
|
|
305
261
|
this.response = response;
|
|
306
262
|
}
|
|
307
|
-
|
|
308
263
|
}
|
|
309
264
|
|
|
310
265
|
function shuffle(array) {
|
|
311
266
|
const shuffledArray = array;
|
|
312
|
-
|
|
313
267
|
for (let c = array.length - 1; c > 0; c--) {
|
|
314
268
|
const b = Math.floor(Math.random() * (c + 1));
|
|
315
269
|
const a = array[c];
|
|
316
270
|
shuffledArray[c] = array[b];
|
|
317
271
|
shuffledArray[b] = a;
|
|
318
272
|
}
|
|
319
|
-
|
|
320
273
|
return shuffledArray;
|
|
321
274
|
}
|
|
322
275
|
function serializeUrl(host, path, queryParameters) {
|
|
323
276
|
const queryParametersAsString = serializeQueryParameters(queryParameters);
|
|
324
277
|
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`;
|
|
325
|
-
|
|
326
278
|
if (queryParametersAsString.length) {
|
|
327
279
|
url += `?${queryParametersAsString}`;
|
|
328
280
|
}
|
|
329
|
-
|
|
330
281
|
return url;
|
|
331
282
|
}
|
|
332
283
|
function serializeQueryParameters(parameters) {
|
|
333
284
|
const isObjectOrArray = value => Object.prototype.toString.call(value) === '[object Object]' || Object.prototype.toString.call(value) === '[object Array]';
|
|
334
|
-
|
|
335
285
|
return Object.keys(parameters).map(key => `${key}=${encodeURIComponent(isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key])}`).join('&');
|
|
336
286
|
}
|
|
337
287
|
function serializeData(request, requestOptions) {
|
|
338
288
|
if (request.method === 'GET' || request.data === undefined && requestOptions.data === undefined) {
|
|
339
289
|
return undefined;
|
|
340
290
|
}
|
|
341
|
-
|
|
342
|
-
|
|
291
|
+
const data = Array.isArray(request.data) ? request.data : {
|
|
292
|
+
...request.data,
|
|
343
293
|
...requestOptions.data
|
|
344
294
|
};
|
|
345
295
|
return JSON.stringify(data);
|
|
@@ -370,12 +320,11 @@ function deserializeFailure({
|
|
|
370
320
|
status
|
|
371
321
|
}, stackFrame) {
|
|
372
322
|
let message = content;
|
|
373
|
-
|
|
374
323
|
try {
|
|
375
324
|
message = JSON.parse(content).message;
|
|
376
|
-
} catch (e) {
|
|
325
|
+
} catch (e) {
|
|
326
|
+
// ..
|
|
377
327
|
}
|
|
378
|
-
|
|
379
328
|
return new ApiError(message, status, stackFrame);
|
|
380
329
|
}
|
|
381
330
|
|
|
@@ -407,9 +356,12 @@ function stackFrameWithoutCredentials(stackFrame) {
|
|
|
407
356
|
const modifiedHeaders = stackFrame.request.headers['x-algolia-api-key'] ? {
|
|
408
357
|
'x-algolia-api-key': '*****'
|
|
409
358
|
} : {};
|
|
410
|
-
return {
|
|
411
|
-
|
|
412
|
-
|
|
359
|
+
return {
|
|
360
|
+
...stackFrame,
|
|
361
|
+
request: {
|
|
362
|
+
...stackFrame.request,
|
|
363
|
+
headers: {
|
|
364
|
+
...stackFrame.request.headers,
|
|
413
365
|
...modifiedHeaders
|
|
414
366
|
}
|
|
415
367
|
}
|
|
@@ -434,13 +386,12 @@ function createTransporter({
|
|
|
434
386
|
});
|
|
435
387
|
}));
|
|
436
388
|
const hostsUp = statefulHosts.filter(host => host.isUp());
|
|
437
|
-
const hostsTimedOut = statefulHosts.filter(host => host.isTimedOut());
|
|
438
|
-
|
|
389
|
+
const hostsTimedOut = statefulHosts.filter(host => host.isTimedOut());
|
|
390
|
+
// Note, we put the hosts that previously timed out on the end of the list.
|
|
439
391
|
const hostsAvailable = [...hostsUp, ...hostsTimedOut];
|
|
440
392
|
const compatibleHostsAvailable = hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;
|
|
441
393
|
return {
|
|
442
394
|
hosts: compatibleHostsAvailable,
|
|
443
|
-
|
|
444
395
|
getTimeout(timeoutsCount, baseTimeout) {
|
|
445
396
|
/**
|
|
446
397
|
* Imagine that you have 4 hosts, if timeouts will increase
|
|
@@ -456,20 +407,18 @@ function createTransporter({
|
|
|
456
407
|
const timeoutMultiplier = hostsTimedOut.length === 0 && timeoutsCount === 0 ? 1 : hostsTimedOut.length + 3 + timeoutsCount;
|
|
457
408
|
return timeoutMultiplier * baseTimeout;
|
|
458
409
|
}
|
|
459
|
-
|
|
460
410
|
};
|
|
461
411
|
}
|
|
462
|
-
|
|
463
412
|
async function retryableRequest(request, requestOptions, isRead = true) {
|
|
464
413
|
const stackTrace = [];
|
|
465
414
|
/**
|
|
466
415
|
* First we prepare the payload that do not depend from hosts.
|
|
467
416
|
*/
|
|
468
|
-
|
|
469
417
|
const data = serializeData(request, requestOptions);
|
|
470
|
-
const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);
|
|
471
|
-
|
|
472
|
-
const dataQueryParameters = request.method === 'GET' ? {
|
|
418
|
+
const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);
|
|
419
|
+
// On `GET`, the data is proxied to query parameters.
|
|
420
|
+
const dataQueryParameters = request.method === 'GET' ? {
|
|
421
|
+
...request.data,
|
|
473
422
|
...requestOptions.data
|
|
474
423
|
} : {};
|
|
475
424
|
const queryParameters = {
|
|
@@ -478,7 +427,6 @@ function createTransporter({
|
|
|
478
427
|
...request.queryParameters,
|
|
479
428
|
...dataQueryParameters
|
|
480
429
|
};
|
|
481
|
-
|
|
482
430
|
if (requestOptions && requestOptions.queryParameters) {
|
|
483
431
|
for (const key of Object.keys(requestOptions.queryParameters)) {
|
|
484
432
|
// We want to keep `undefined` and `null` values,
|
|
@@ -491,25 +439,19 @@ function createTransporter({
|
|
|
491
439
|
}
|
|
492
440
|
}
|
|
493
441
|
}
|
|
494
|
-
|
|
495
442
|
let timeoutsCount = 0;
|
|
496
|
-
|
|
497
443
|
const retry = async (retryableHosts, getTimeout) => {
|
|
498
444
|
/**
|
|
499
445
|
* We iterate on each host, until there is no host left.
|
|
500
446
|
*/
|
|
501
447
|
const host = retryableHosts.pop();
|
|
502
|
-
|
|
503
448
|
if (host === undefined) {
|
|
504
449
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
505
450
|
}
|
|
506
|
-
|
|
507
451
|
let responseTimeout = requestOptions.timeout;
|
|
508
|
-
|
|
509
452
|
if (responseTimeout === undefined) {
|
|
510
453
|
responseTimeout = isRead ? timeouts.read : timeouts.write;
|
|
511
454
|
}
|
|
512
|
-
|
|
513
455
|
const payload = {
|
|
514
456
|
data,
|
|
515
457
|
headers,
|
|
@@ -523,7 +465,6 @@ function createTransporter({
|
|
|
523
465
|
* can have information about onRetry and onFailure
|
|
524
466
|
* decisions.
|
|
525
467
|
*/
|
|
526
|
-
|
|
527
468
|
const pushToStackTrace = response => {
|
|
528
469
|
const stackFrame = {
|
|
529
470
|
request: payload,
|
|
@@ -534,12 +475,10 @@ function createTransporter({
|
|
|
534
475
|
stackTrace.push(stackFrame);
|
|
535
476
|
return stackFrame;
|
|
536
477
|
};
|
|
537
|
-
|
|
538
478
|
const response = await requester.send(payload);
|
|
539
|
-
|
|
540
479
|
if (isRetryable(response)) {
|
|
541
|
-
const stackFrame = pushToStackTrace(response);
|
|
542
|
-
|
|
480
|
+
const stackFrame = pushToStackTrace(response);
|
|
481
|
+
// If response is a timeout, we increase the number of timeouts so we can increase the timeout later.
|
|
543
482
|
if (response.isTimedOut) {
|
|
544
483
|
timeoutsCount++;
|
|
545
484
|
}
|
|
@@ -549,23 +488,18 @@ function createTransporter({
|
|
|
549
488
|
* when a retry error does not happen.
|
|
550
489
|
*/
|
|
551
490
|
// eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
|
|
552
|
-
|
|
553
|
-
|
|
554
491
|
console.log('Retryable failure', stackFrameWithoutCredentials(stackFrame));
|
|
555
492
|
/**
|
|
556
493
|
* We also store the state of the host in failure cases. If the host, is
|
|
557
494
|
* down it will remain down for the next 2 minutes. In a timeout situation,
|
|
558
495
|
* this host will be added end of the list of hosts on the next request.
|
|
559
496
|
*/
|
|
560
|
-
|
|
561
497
|
await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));
|
|
562
498
|
return retry(retryableHosts, getTimeout);
|
|
563
499
|
}
|
|
564
|
-
|
|
565
500
|
if (isSuccess(response)) {
|
|
566
501
|
return deserializeSuccess(response);
|
|
567
502
|
}
|
|
568
|
-
|
|
569
503
|
pushToStackTrace(response);
|
|
570
504
|
throw deserializeFailure(response, stackTrace);
|
|
571
505
|
};
|
|
@@ -577,20 +511,16 @@ function createTransporter({
|
|
|
577
511
|
* 2. We also get from the retryable options a timeout multiplier that is tailored
|
|
578
512
|
* for the current context.
|
|
579
513
|
*/
|
|
580
|
-
|
|
581
|
-
|
|
582
514
|
const compatibleHosts = hosts.filter(host => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'));
|
|
583
515
|
const options = await createRetryableOptions(compatibleHosts);
|
|
584
516
|
return retry([...options.hosts].reverse(), options.getTimeout);
|
|
585
517
|
}
|
|
586
|
-
|
|
587
518
|
function createRequest(request, requestOptions = {}) {
|
|
588
519
|
/**
|
|
589
520
|
* A read request is either a `GET` request, or a request that we make
|
|
590
521
|
* via the `read` transporter (e.g. `search`).
|
|
591
522
|
*/
|
|
592
523
|
const isRead = request.useReadTransporter || request.method === 'GET';
|
|
593
|
-
|
|
594
524
|
if (!isRead) {
|
|
595
525
|
/**
|
|
596
526
|
* On write requests, no cache mechanisms are applied, and we
|
|
@@ -598,7 +528,6 @@ function createTransporter({
|
|
|
598
528
|
*/
|
|
599
529
|
return retryableRequest(request, requestOptions, isRead);
|
|
600
530
|
}
|
|
601
|
-
|
|
602
531
|
const createRetryableRequest = () => {
|
|
603
532
|
/**
|
|
604
533
|
* Then, we prepare a function factory that contains the construction of
|
|
@@ -612,14 +541,11 @@ function createTransporter({
|
|
|
612
541
|
* request is "cacheable" - should be cached. Note that, once again,
|
|
613
542
|
* the user can force this option.
|
|
614
543
|
*/
|
|
615
|
-
|
|
616
|
-
|
|
617
544
|
const cacheable = requestOptions.cacheable || request.cacheable;
|
|
618
545
|
/**
|
|
619
546
|
* If is not "cacheable", we immediately trigger the retryable request, no
|
|
620
547
|
* need to check cache implementations.
|
|
621
548
|
*/
|
|
622
|
-
|
|
623
549
|
if (cacheable !== true) {
|
|
624
550
|
return createRetryableRequest();
|
|
625
551
|
}
|
|
@@ -628,8 +554,6 @@ function createTransporter({
|
|
|
628
554
|
* the cache implementations if this request is on progress or if the
|
|
629
555
|
* response already exists on the cache.
|
|
630
556
|
*/
|
|
631
|
-
|
|
632
|
-
|
|
633
557
|
const key = {
|
|
634
558
|
request,
|
|
635
559
|
requestOptions,
|
|
@@ -642,7 +566,6 @@ function createTransporter({
|
|
|
642
566
|
* With the computed key, we first ask the responses cache
|
|
643
567
|
* implementation if this request was been resolved before.
|
|
644
568
|
*/
|
|
645
|
-
|
|
646
569
|
return responsesCache.get(key, () => {
|
|
647
570
|
/**
|
|
648
571
|
* If the request has never resolved before, we actually ask if there
|
|
@@ -664,7 +587,6 @@ function createTransporter({
|
|
|
664
587
|
miss: response => responsesCache.set(key, response)
|
|
665
588
|
});
|
|
666
589
|
}
|
|
667
|
-
|
|
668
590
|
return {
|
|
669
591
|
hostsCache,
|
|
670
592
|
requester,
|
|
@@ -682,17 +604,13 @@ function createTransporter({
|
|
|
682
604
|
function createAlgoliaAgent(version) {
|
|
683
605
|
const algoliaAgent = {
|
|
684
606
|
value: `Algolia for JavaScript (${version})`,
|
|
685
|
-
|
|
686
607
|
add(options) {
|
|
687
608
|
const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;
|
|
688
|
-
|
|
689
609
|
if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
|
|
690
610
|
algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
|
|
691
611
|
}
|
|
692
|
-
|
|
693
612
|
return algoliaAgent;
|
|
694
613
|
}
|
|
695
|
-
|
|
696
614
|
};
|
|
697
615
|
return algoliaAgent;
|
|
698
616
|
}
|
|
@@ -715,7 +633,7 @@ const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
|
|
|
715
633
|
const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
|
|
716
634
|
|
|
717
635
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
718
|
-
const apiClientVersion$4 = '5.0.0-alpha.
|
|
636
|
+
const apiClientVersion$4 = '5.0.0-alpha.27';
|
|
719
637
|
const REGIONS$2 = ['de', 'us'];
|
|
720
638
|
function getDefaultHosts$3(region) {
|
|
721
639
|
const url = !region
|
|
@@ -1006,7 +924,7 @@ function createAbtestingClient({ appId: appIdOption, apiKey: apiKeyOption, authM
|
|
|
1006
924
|
}
|
|
1007
925
|
|
|
1008
926
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
1009
|
-
const apiClientVersion$3 = '5.0.0-alpha.
|
|
927
|
+
const apiClientVersion$3 = '5.0.0-alpha.27';
|
|
1010
928
|
const REGIONS$1 = ['de', 'us'];
|
|
1011
929
|
function getDefaultHosts$2(region) {
|
|
1012
930
|
const url = !region
|
|
@@ -1903,7 +1821,7 @@ function createAnalyticsClient({ appId: appIdOption, apiKey: apiKeyOption, authM
|
|
|
1903
1821
|
}
|
|
1904
1822
|
|
|
1905
1823
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
1906
|
-
const apiClientVersion$2 = '5.0.0-alpha.
|
|
1824
|
+
const apiClientVersion$2 = '5.0.0-alpha.27';
|
|
1907
1825
|
const REGIONS = ['eu', 'us'];
|
|
1908
1826
|
function getDefaultHosts$1(region) {
|
|
1909
1827
|
const url = 'personalization.{region}.algolia.com'.replace('{region}', region);
|
|
@@ -2160,7 +2078,7 @@ function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption,
|
|
|
2160
2078
|
}
|
|
2161
2079
|
|
|
2162
2080
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
2163
|
-
const apiClientVersion$1 = '5.0.0-alpha.
|
|
2081
|
+
const apiClientVersion$1 = '5.0.0-alpha.27';
|
|
2164
2082
|
function getDefaultHosts(appId) {
|
|
2165
2083
|
return [
|
|
2166
2084
|
{
|
|
@@ -2,7 +2,7 @@ import { createAuth, createTransporter, getAlgoliaAgent, createIterablePromise,
|
|
|
2
2
|
import { createHttpRequester } from '@algolia/requester-node-http';
|
|
3
3
|
|
|
4
4
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
5
|
-
const apiClientVersion$4 = '5.0.0-alpha.
|
|
5
|
+
const apiClientVersion$4 = '5.0.0-alpha.27';
|
|
6
6
|
const REGIONS$2 = ['de', 'us'];
|
|
7
7
|
function getDefaultHosts$3(region) {
|
|
8
8
|
const url = !region
|
|
@@ -293,7 +293,7 @@ function createAbtestingClient({ appId: appIdOption, apiKey: apiKeyOption, authM
|
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
296
|
-
const apiClientVersion$3 = '5.0.0-alpha.
|
|
296
|
+
const apiClientVersion$3 = '5.0.0-alpha.27';
|
|
297
297
|
const REGIONS$1 = ['de', 'us'];
|
|
298
298
|
function getDefaultHosts$2(region) {
|
|
299
299
|
const url = !region
|
|
@@ -1190,7 +1190,7 @@ function createAnalyticsClient({ appId: appIdOption, apiKey: apiKeyOption, authM
|
|
|
1190
1190
|
}
|
|
1191
1191
|
|
|
1192
1192
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
1193
|
-
const apiClientVersion$2 = '5.0.0-alpha.
|
|
1193
|
+
const apiClientVersion$2 = '5.0.0-alpha.27';
|
|
1194
1194
|
const REGIONS = ['eu', 'us'];
|
|
1195
1195
|
function getDefaultHosts$1(region) {
|
|
1196
1196
|
const url = 'personalization.{region}.algolia.com'.replace('{region}', region);
|
|
@@ -1447,7 +1447,7 @@ function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption,
|
|
|
1447
1447
|
}
|
|
1448
1448
|
|
|
1449
1449
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
1450
|
-
const apiClientVersion$1 = '5.0.0-alpha.
|
|
1450
|
+
const apiClientVersion$1 = '5.0.0-alpha.27';
|
|
1451
1451
|
function getDefaultHosts(appId) {
|
|
1452
1452
|
return [
|
|
1453
1453
|
{
|