algoliasearch 5.0.0-alpha.26 → 5.0.0-alpha.28
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 +31 -111
- 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 +28 -104
- 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.28';
|
|
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.28';
|
|
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.28';
|
|
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.28';
|
|
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,29 +407,28 @@ 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 = {
|
|
476
|
-
'x-algolia-agent': algoliaAgent.value,
|
|
477
425
|
...baseQueryParameters,
|
|
478
426
|
...request.queryParameters,
|
|
479
427
|
...dataQueryParameters
|
|
480
428
|
};
|
|
481
|
-
|
|
429
|
+
if (algoliaAgent.value) {
|
|
430
|
+
queryParameters['x-algolia-agent'] = algoliaAgent.value;
|
|
431
|
+
}
|
|
482
432
|
if (requestOptions && requestOptions.queryParameters) {
|
|
483
433
|
for (const key of Object.keys(requestOptions.queryParameters)) {
|
|
484
434
|
// We want to keep `undefined` and `null` values,
|
|
@@ -491,25 +441,19 @@ function createTransporter({
|
|
|
491
441
|
}
|
|
492
442
|
}
|
|
493
443
|
}
|
|
494
|
-
|
|
495
444
|
let timeoutsCount = 0;
|
|
496
|
-
|
|
497
445
|
const retry = async (retryableHosts, getTimeout) => {
|
|
498
446
|
/**
|
|
499
447
|
* We iterate on each host, until there is no host left.
|
|
500
448
|
*/
|
|
501
449
|
const host = retryableHosts.pop();
|
|
502
|
-
|
|
503
450
|
if (host === undefined) {
|
|
504
451
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
505
452
|
}
|
|
506
|
-
|
|
507
453
|
let responseTimeout = requestOptions.timeout;
|
|
508
|
-
|
|
509
454
|
if (responseTimeout === undefined) {
|
|
510
455
|
responseTimeout = isRead ? timeouts.read : timeouts.write;
|
|
511
456
|
}
|
|
512
|
-
|
|
513
457
|
const payload = {
|
|
514
458
|
data,
|
|
515
459
|
headers,
|
|
@@ -523,7 +467,6 @@ function createTransporter({
|
|
|
523
467
|
* can have information about onRetry and onFailure
|
|
524
468
|
* decisions.
|
|
525
469
|
*/
|
|
526
|
-
|
|
527
470
|
const pushToStackTrace = response => {
|
|
528
471
|
const stackFrame = {
|
|
529
472
|
request: payload,
|
|
@@ -534,12 +477,10 @@ function createTransporter({
|
|
|
534
477
|
stackTrace.push(stackFrame);
|
|
535
478
|
return stackFrame;
|
|
536
479
|
};
|
|
537
|
-
|
|
538
480
|
const response = await requester.send(payload);
|
|
539
|
-
|
|
540
481
|
if (isRetryable(response)) {
|
|
541
|
-
const stackFrame = pushToStackTrace(response);
|
|
542
|
-
|
|
482
|
+
const stackFrame = pushToStackTrace(response);
|
|
483
|
+
// If response is a timeout, we increase the number of timeouts so we can increase the timeout later.
|
|
543
484
|
if (response.isTimedOut) {
|
|
544
485
|
timeoutsCount++;
|
|
545
486
|
}
|
|
@@ -549,23 +490,18 @@ function createTransporter({
|
|
|
549
490
|
* when a retry error does not happen.
|
|
550
491
|
*/
|
|
551
492
|
// eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
|
|
552
|
-
|
|
553
|
-
|
|
554
493
|
console.log('Retryable failure', stackFrameWithoutCredentials(stackFrame));
|
|
555
494
|
/**
|
|
556
495
|
* We also store the state of the host in failure cases. If the host, is
|
|
557
496
|
* down it will remain down for the next 2 minutes. In a timeout situation,
|
|
558
497
|
* this host will be added end of the list of hosts on the next request.
|
|
559
498
|
*/
|
|
560
|
-
|
|
561
499
|
await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));
|
|
562
500
|
return retry(retryableHosts, getTimeout);
|
|
563
501
|
}
|
|
564
|
-
|
|
565
502
|
if (isSuccess(response)) {
|
|
566
503
|
return deserializeSuccess(response);
|
|
567
504
|
}
|
|
568
|
-
|
|
569
505
|
pushToStackTrace(response);
|
|
570
506
|
throw deserializeFailure(response, stackTrace);
|
|
571
507
|
};
|
|
@@ -577,20 +513,16 @@ function createTransporter({
|
|
|
577
513
|
* 2. We also get from the retryable options a timeout multiplier that is tailored
|
|
578
514
|
* for the current context.
|
|
579
515
|
*/
|
|
580
|
-
|
|
581
|
-
|
|
582
516
|
const compatibleHosts = hosts.filter(host => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'));
|
|
583
517
|
const options = await createRetryableOptions(compatibleHosts);
|
|
584
518
|
return retry([...options.hosts].reverse(), options.getTimeout);
|
|
585
519
|
}
|
|
586
|
-
|
|
587
520
|
function createRequest(request, requestOptions = {}) {
|
|
588
521
|
/**
|
|
589
522
|
* A read request is either a `GET` request, or a request that we make
|
|
590
523
|
* via the `read` transporter (e.g. `search`).
|
|
591
524
|
*/
|
|
592
525
|
const isRead = request.useReadTransporter || request.method === 'GET';
|
|
593
|
-
|
|
594
526
|
if (!isRead) {
|
|
595
527
|
/**
|
|
596
528
|
* On write requests, no cache mechanisms are applied, and we
|
|
@@ -598,7 +530,6 @@ function createTransporter({
|
|
|
598
530
|
*/
|
|
599
531
|
return retryableRequest(request, requestOptions, isRead);
|
|
600
532
|
}
|
|
601
|
-
|
|
602
533
|
const createRetryableRequest = () => {
|
|
603
534
|
/**
|
|
604
535
|
* Then, we prepare a function factory that contains the construction of
|
|
@@ -612,14 +543,11 @@ function createTransporter({
|
|
|
612
543
|
* request is "cacheable" - should be cached. Note that, once again,
|
|
613
544
|
* the user can force this option.
|
|
614
545
|
*/
|
|
615
|
-
|
|
616
|
-
|
|
617
546
|
const cacheable = requestOptions.cacheable || request.cacheable;
|
|
618
547
|
/**
|
|
619
548
|
* If is not "cacheable", we immediately trigger the retryable request, no
|
|
620
549
|
* need to check cache implementations.
|
|
621
550
|
*/
|
|
622
|
-
|
|
623
551
|
if (cacheable !== true) {
|
|
624
552
|
return createRetryableRequest();
|
|
625
553
|
}
|
|
@@ -628,8 +556,6 @@ function createTransporter({
|
|
|
628
556
|
* the cache implementations if this request is on progress or if the
|
|
629
557
|
* response already exists on the cache.
|
|
630
558
|
*/
|
|
631
|
-
|
|
632
|
-
|
|
633
559
|
const key = {
|
|
634
560
|
request,
|
|
635
561
|
requestOptions,
|
|
@@ -642,7 +568,6 @@ function createTransporter({
|
|
|
642
568
|
* With the computed key, we first ask the responses cache
|
|
643
569
|
* implementation if this request was been resolved before.
|
|
644
570
|
*/
|
|
645
|
-
|
|
646
571
|
return responsesCache.get(key, () => {
|
|
647
572
|
/**
|
|
648
573
|
* If the request has never resolved before, we actually ask if there
|
|
@@ -664,7 +589,6 @@ function createTransporter({
|
|
|
664
589
|
miss: response => responsesCache.set(key, response)
|
|
665
590
|
});
|
|
666
591
|
}
|
|
667
|
-
|
|
668
592
|
return {
|
|
669
593
|
hostsCache,
|
|
670
594
|
requester,
|
|
@@ -682,17 +606,13 @@ function createTransporter({
|
|
|
682
606
|
function createAlgoliaAgent(version) {
|
|
683
607
|
const algoliaAgent = {
|
|
684
608
|
value: `Algolia for JavaScript (${version})`,
|
|
685
|
-
|
|
686
609
|
add(options) {
|
|
687
610
|
const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;
|
|
688
|
-
|
|
689
611
|
if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
|
|
690
612
|
algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
|
|
691
613
|
}
|
|
692
|
-
|
|
693
614
|
return algoliaAgent;
|
|
694
615
|
}
|
|
695
|
-
|
|
696
616
|
};
|
|
697
617
|
return algoliaAgent;
|
|
698
618
|
}
|
|
@@ -715,7 +635,7 @@ const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
|
|
|
715
635
|
const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
|
|
716
636
|
|
|
717
637
|
// 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.
|
|
638
|
+
const apiClientVersion$4 = '5.0.0-alpha.28';
|
|
719
639
|
const REGIONS$2 = ['de', 'us'];
|
|
720
640
|
function getDefaultHosts$3(region) {
|
|
721
641
|
const url = !region
|
|
@@ -1006,7 +926,7 @@ function createAbtestingClient({ appId: appIdOption, apiKey: apiKeyOption, authM
|
|
|
1006
926
|
}
|
|
1007
927
|
|
|
1008
928
|
// 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.
|
|
929
|
+
const apiClientVersion$3 = '5.0.0-alpha.28';
|
|
1010
930
|
const REGIONS$1 = ['de', 'us'];
|
|
1011
931
|
function getDefaultHosts$2(region) {
|
|
1012
932
|
const url = !region
|
|
@@ -1903,7 +1823,7 @@ function createAnalyticsClient({ appId: appIdOption, apiKey: apiKeyOption, authM
|
|
|
1903
1823
|
}
|
|
1904
1824
|
|
|
1905
1825
|
// 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.
|
|
1826
|
+
const apiClientVersion$2 = '5.0.0-alpha.28';
|
|
1907
1827
|
const REGIONS = ['eu', 'us'];
|
|
1908
1828
|
function getDefaultHosts$1(region) {
|
|
1909
1829
|
const url = 'personalization.{region}.algolia.com'.replace('{region}', region);
|
|
@@ -2160,7 +2080,7 @@ function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption,
|
|
|
2160
2080
|
}
|
|
2161
2081
|
|
|
2162
2082
|
// 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.
|
|
2083
|
+
const apiClientVersion$1 = '5.0.0-alpha.28';
|
|
2164
2084
|
function getDefaultHosts(appId) {
|
|
2165
2085
|
return [
|
|
2166
2086
|
{
|
|
@@ -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.28';
|
|
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.28';
|
|
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.28';
|
|
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.28';
|
|
1451
1451
|
function getDefaultHosts(appId) {
|
|
1452
1452
|
return [
|
|
1453
1453
|
{
|