@algolia/recommend 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/recommend.cjs.js
CHANGED
|
@@ -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 = '5.0.0-alpha.
|
|
9
|
+
const apiClientVersion = '5.0.0-alpha.27';
|
|
10
10
|
function getDefaultHosts(appId) {
|
|
11
11
|
return [
|
|
12
12
|
{
|
|
@@ -7,31 +7,25 @@ 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
|
-
|
|
35
29
|
return {
|
|
36
30
|
get(key, defaultValue, events = {
|
|
37
31
|
miss: () => Promise.resolve()
|
|
@@ -44,7 +38,6 @@ function createBrowserLocalStorageCache(options) {
|
|
|
44
38
|
return Promise.all([value, exists || events.miss(value)]);
|
|
45
39
|
}).then(([value]) => value);
|
|
46
40
|
},
|
|
47
|
-
|
|
48
41
|
set(key, value) {
|
|
49
42
|
return Promise.resolve().then(() => {
|
|
50
43
|
const namespace = getNamespace();
|
|
@@ -53,7 +46,6 @@ function createBrowserLocalStorageCache(options) {
|
|
|
53
46
|
return value;
|
|
54
47
|
});
|
|
55
48
|
},
|
|
56
|
-
|
|
57
49
|
delete(key) {
|
|
58
50
|
return Promise.resolve().then(() => {
|
|
59
51
|
const namespace = getNamespace();
|
|
@@ -61,13 +53,11 @@ function createBrowserLocalStorageCache(options) {
|
|
|
61
53
|
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
|
62
54
|
});
|
|
63
55
|
},
|
|
64
|
-
|
|
65
56
|
clear() {
|
|
66
57
|
return Promise.resolve().then(() => {
|
|
67
58
|
getStorage().removeItem(namespaceKey);
|
|
68
59
|
});
|
|
69
60
|
}
|
|
70
|
-
|
|
71
61
|
};
|
|
72
62
|
}
|
|
73
63
|
|
|
@@ -79,30 +69,24 @@ function createNullCache() {
|
|
|
79
69
|
const value = defaultValue();
|
|
80
70
|
return value.then(result => Promise.all([result, events.miss(result)])).then(([result]) => result);
|
|
81
71
|
},
|
|
82
|
-
|
|
83
72
|
set(_key, value) {
|
|
84
73
|
return Promise.resolve(value);
|
|
85
74
|
},
|
|
86
|
-
|
|
87
75
|
delete(_key) {
|
|
88
76
|
return Promise.resolve();
|
|
89
77
|
},
|
|
90
|
-
|
|
91
78
|
clear() {
|
|
92
79
|
return Promise.resolve();
|
|
93
80
|
}
|
|
94
|
-
|
|
95
81
|
};
|
|
96
82
|
}
|
|
97
83
|
|
|
98
84
|
function createFallbackableCache(options) {
|
|
99
85
|
const caches = [...options.caches];
|
|
100
86
|
const current = caches.shift();
|
|
101
|
-
|
|
102
87
|
if (current === undefined) {
|
|
103
88
|
return createNullCache();
|
|
104
89
|
}
|
|
105
|
-
|
|
106
90
|
return {
|
|
107
91
|
get(key, defaultValue, events = {
|
|
108
92
|
miss: () => Promise.resolve()
|
|
@@ -113,7 +97,6 @@ function createFallbackableCache(options) {
|
|
|
113
97
|
}).get(key, defaultValue, events);
|
|
114
98
|
});
|
|
115
99
|
},
|
|
116
|
-
|
|
117
100
|
set(key, value) {
|
|
118
101
|
return current.set(key, value).catch(() => {
|
|
119
102
|
return createFallbackableCache({
|
|
@@ -121,7 +104,6 @@ function createFallbackableCache(options) {
|
|
|
121
104
|
}).set(key, value);
|
|
122
105
|
});
|
|
123
106
|
},
|
|
124
|
-
|
|
125
107
|
delete(key) {
|
|
126
108
|
return current.delete(key).catch(() => {
|
|
127
109
|
return createFallbackableCache({
|
|
@@ -129,7 +111,6 @@ function createFallbackableCache(options) {
|
|
|
129
111
|
}).delete(key);
|
|
130
112
|
});
|
|
131
113
|
},
|
|
132
|
-
|
|
133
114
|
clear() {
|
|
134
115
|
return current.clear().catch(() => {
|
|
135
116
|
return createFallbackableCache({
|
|
@@ -137,7 +118,6 @@ function createFallbackableCache(options) {
|
|
|
137
118
|
}).clear();
|
|
138
119
|
});
|
|
139
120
|
}
|
|
140
|
-
|
|
141
121
|
};
|
|
142
122
|
}
|
|
143
123
|
|
|
@@ -150,30 +130,24 @@ function createMemoryCache(options = {
|
|
|
150
130
|
miss: () => Promise.resolve()
|
|
151
131
|
}) {
|
|
152
132
|
const keyAsString = JSON.stringify(key);
|
|
153
|
-
|
|
154
133
|
if (keyAsString in cache) {
|
|
155
134
|
return Promise.resolve(options.serializable ? JSON.parse(cache[keyAsString]) : cache[keyAsString]);
|
|
156
135
|
}
|
|
157
|
-
|
|
158
136
|
const promise = defaultValue();
|
|
159
137
|
return promise.then(value => events.miss(value)).then(() => promise);
|
|
160
138
|
},
|
|
161
|
-
|
|
162
139
|
set(key, value) {
|
|
163
140
|
cache[JSON.stringify(key)] = options.serializable ? JSON.stringify(value) : value;
|
|
164
141
|
return Promise.resolve(value);
|
|
165
142
|
},
|
|
166
|
-
|
|
167
143
|
delete(key) {
|
|
168
144
|
delete cache[JSON.stringify(key)];
|
|
169
145
|
return Promise.resolve();
|
|
170
146
|
},
|
|
171
|
-
|
|
172
147
|
clear() {
|
|
173
148
|
cache = {};
|
|
174
149
|
return Promise.resolve();
|
|
175
150
|
}
|
|
176
|
-
|
|
177
151
|
};
|
|
178
152
|
}
|
|
179
153
|
|
|
@@ -182,16 +156,14 @@ function createMemoryCache(options = {
|
|
|
182
156
|
const EXPIRATION_DELAY = 2 * 60 * 1000;
|
|
183
157
|
function createStatefulHost(host, status = 'up') {
|
|
184
158
|
const lastUpdate = Date.now();
|
|
185
|
-
|
|
186
159
|
function isUp() {
|
|
187
160
|
return status === 'up' || Date.now() - lastUpdate > EXPIRATION_DELAY;
|
|
188
161
|
}
|
|
189
|
-
|
|
190
162
|
function isTimedOut() {
|
|
191
163
|
return status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY;
|
|
192
164
|
}
|
|
193
|
-
|
|
194
|
-
|
|
165
|
+
return {
|
|
166
|
+
...host,
|
|
195
167
|
status,
|
|
196
168
|
lastUpdate,
|
|
197
169
|
isUp,
|
|
@@ -210,92 +182,74 @@ function _defineProperty(obj, key, value) {
|
|
|
210
182
|
} else {
|
|
211
183
|
obj[key] = value;
|
|
212
184
|
}
|
|
213
|
-
|
|
214
185
|
return obj;
|
|
215
186
|
}
|
|
216
187
|
|
|
217
188
|
class AlgoliaError extends Error {
|
|
218
189
|
constructor(message, name) {
|
|
219
190
|
super(message);
|
|
220
|
-
|
|
221
191
|
_defineProperty(this, "name", 'AlgoliaError');
|
|
222
|
-
|
|
223
192
|
if (name) {
|
|
224
193
|
this.name = name;
|
|
225
194
|
}
|
|
226
195
|
}
|
|
227
|
-
|
|
228
196
|
}
|
|
229
197
|
class ErrorWithStackTrace extends AlgoliaError {
|
|
230
198
|
constructor(message, stackTrace, name) {
|
|
231
|
-
super(message, name);
|
|
232
|
-
|
|
199
|
+
super(message, name);
|
|
200
|
+
// the array and object should be frozen to reflect the stackTrace at the time of the error
|
|
233
201
|
_defineProperty(this, "stackTrace", void 0);
|
|
234
|
-
|
|
235
202
|
this.stackTrace = stackTrace;
|
|
236
203
|
}
|
|
237
|
-
|
|
238
204
|
}
|
|
239
205
|
class RetryError extends ErrorWithStackTrace {
|
|
240
206
|
constructor(stackTrace) {
|
|
241
207
|
super('Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.', stackTrace, 'RetryError');
|
|
242
208
|
}
|
|
243
|
-
|
|
244
209
|
}
|
|
245
210
|
class ApiError extends ErrorWithStackTrace {
|
|
246
211
|
constructor(message, status, stackTrace) {
|
|
247
212
|
super(message, stackTrace, 'ApiError');
|
|
248
|
-
|
|
249
213
|
_defineProperty(this, "status", void 0);
|
|
250
|
-
|
|
251
214
|
this.status = status;
|
|
252
215
|
}
|
|
253
|
-
|
|
254
216
|
}
|
|
255
217
|
class DeserializationError extends AlgoliaError {
|
|
256
218
|
constructor(message, response) {
|
|
257
219
|
super(message, 'DeserializationError');
|
|
258
|
-
|
|
259
220
|
_defineProperty(this, "response", void 0);
|
|
260
|
-
|
|
261
221
|
this.response = response;
|
|
262
222
|
}
|
|
263
|
-
|
|
264
223
|
}
|
|
265
224
|
|
|
266
225
|
function shuffle(array) {
|
|
267
226
|
const shuffledArray = array;
|
|
268
|
-
|
|
269
227
|
for (let c = array.length - 1; c > 0; c--) {
|
|
270
228
|
const b = Math.floor(Math.random() * (c + 1));
|
|
271
229
|
const a = array[c];
|
|
272
230
|
shuffledArray[c] = array[b];
|
|
273
231
|
shuffledArray[b] = a;
|
|
274
232
|
}
|
|
275
|
-
|
|
276
233
|
return shuffledArray;
|
|
277
234
|
}
|
|
278
235
|
function serializeUrl(host, path, queryParameters) {
|
|
279
236
|
const queryParametersAsString = serializeQueryParameters(queryParameters);
|
|
280
237
|
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`;
|
|
281
|
-
|
|
282
238
|
if (queryParametersAsString.length) {
|
|
283
239
|
url += `?${queryParametersAsString}`;
|
|
284
240
|
}
|
|
285
|
-
|
|
286
241
|
return url;
|
|
287
242
|
}
|
|
288
243
|
function serializeQueryParameters(parameters) {
|
|
289
244
|
const isObjectOrArray = value => Object.prototype.toString.call(value) === '[object Object]' || Object.prototype.toString.call(value) === '[object Array]';
|
|
290
|
-
|
|
291
245
|
return Object.keys(parameters).map(key => `${key}=${encodeURIComponent(isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key])}`).join('&');
|
|
292
246
|
}
|
|
293
247
|
function serializeData(request, requestOptions) {
|
|
294
248
|
if (request.method === 'GET' || request.data === undefined && requestOptions.data === undefined) {
|
|
295
249
|
return undefined;
|
|
296
250
|
}
|
|
297
|
-
|
|
298
|
-
|
|
251
|
+
const data = Array.isArray(request.data) ? request.data : {
|
|
252
|
+
...request.data,
|
|
299
253
|
...requestOptions.data
|
|
300
254
|
};
|
|
301
255
|
return JSON.stringify(data);
|
|
@@ -326,12 +280,11 @@ function deserializeFailure({
|
|
|
326
280
|
status
|
|
327
281
|
}, stackFrame) {
|
|
328
282
|
let message = content;
|
|
329
|
-
|
|
330
283
|
try {
|
|
331
284
|
message = JSON.parse(content).message;
|
|
332
|
-
} catch (e) {
|
|
285
|
+
} catch (e) {
|
|
286
|
+
// ..
|
|
333
287
|
}
|
|
334
|
-
|
|
335
288
|
return new ApiError(message, status, stackFrame);
|
|
336
289
|
}
|
|
337
290
|
|
|
@@ -363,9 +316,12 @@ function stackFrameWithoutCredentials(stackFrame) {
|
|
|
363
316
|
const modifiedHeaders = stackFrame.request.headers['x-algolia-api-key'] ? {
|
|
364
317
|
'x-algolia-api-key': '*****'
|
|
365
318
|
} : {};
|
|
366
|
-
return {
|
|
367
|
-
|
|
368
|
-
|
|
319
|
+
return {
|
|
320
|
+
...stackFrame,
|
|
321
|
+
request: {
|
|
322
|
+
...stackFrame.request,
|
|
323
|
+
headers: {
|
|
324
|
+
...stackFrame.request.headers,
|
|
369
325
|
...modifiedHeaders
|
|
370
326
|
}
|
|
371
327
|
}
|
|
@@ -390,13 +346,12 @@ function createTransporter({
|
|
|
390
346
|
});
|
|
391
347
|
}));
|
|
392
348
|
const hostsUp = statefulHosts.filter(host => host.isUp());
|
|
393
|
-
const hostsTimedOut = statefulHosts.filter(host => host.isTimedOut());
|
|
394
|
-
|
|
349
|
+
const hostsTimedOut = statefulHosts.filter(host => host.isTimedOut());
|
|
350
|
+
// Note, we put the hosts that previously timed out on the end of the list.
|
|
395
351
|
const hostsAvailable = [...hostsUp, ...hostsTimedOut];
|
|
396
352
|
const compatibleHostsAvailable = hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;
|
|
397
353
|
return {
|
|
398
354
|
hosts: compatibleHostsAvailable,
|
|
399
|
-
|
|
400
355
|
getTimeout(timeoutsCount, baseTimeout) {
|
|
401
356
|
/**
|
|
402
357
|
* Imagine that you have 4 hosts, if timeouts will increase
|
|
@@ -412,20 +367,18 @@ function createTransporter({
|
|
|
412
367
|
const timeoutMultiplier = hostsTimedOut.length === 0 && timeoutsCount === 0 ? 1 : hostsTimedOut.length + 3 + timeoutsCount;
|
|
413
368
|
return timeoutMultiplier * baseTimeout;
|
|
414
369
|
}
|
|
415
|
-
|
|
416
370
|
};
|
|
417
371
|
}
|
|
418
|
-
|
|
419
372
|
async function retryableRequest(request, requestOptions, isRead = true) {
|
|
420
373
|
const stackTrace = [];
|
|
421
374
|
/**
|
|
422
375
|
* First we prepare the payload that do not depend from hosts.
|
|
423
376
|
*/
|
|
424
|
-
|
|
425
377
|
const data = serializeData(request, requestOptions);
|
|
426
|
-
const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);
|
|
427
|
-
|
|
428
|
-
const dataQueryParameters = request.method === 'GET' ? {
|
|
378
|
+
const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);
|
|
379
|
+
// On `GET`, the data is proxied to query parameters.
|
|
380
|
+
const dataQueryParameters = request.method === 'GET' ? {
|
|
381
|
+
...request.data,
|
|
429
382
|
...requestOptions.data
|
|
430
383
|
} : {};
|
|
431
384
|
const queryParameters = {
|
|
@@ -434,7 +387,6 @@ function createTransporter({
|
|
|
434
387
|
...request.queryParameters,
|
|
435
388
|
...dataQueryParameters
|
|
436
389
|
};
|
|
437
|
-
|
|
438
390
|
if (requestOptions && requestOptions.queryParameters) {
|
|
439
391
|
for (const key of Object.keys(requestOptions.queryParameters)) {
|
|
440
392
|
// We want to keep `undefined` and `null` values,
|
|
@@ -447,25 +399,19 @@ function createTransporter({
|
|
|
447
399
|
}
|
|
448
400
|
}
|
|
449
401
|
}
|
|
450
|
-
|
|
451
402
|
let timeoutsCount = 0;
|
|
452
|
-
|
|
453
403
|
const retry = async (retryableHosts, getTimeout) => {
|
|
454
404
|
/**
|
|
455
405
|
* We iterate on each host, until there is no host left.
|
|
456
406
|
*/
|
|
457
407
|
const host = retryableHosts.pop();
|
|
458
|
-
|
|
459
408
|
if (host === undefined) {
|
|
460
409
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
461
410
|
}
|
|
462
|
-
|
|
463
411
|
let responseTimeout = requestOptions.timeout;
|
|
464
|
-
|
|
465
412
|
if (responseTimeout === undefined) {
|
|
466
413
|
responseTimeout = isRead ? timeouts.read : timeouts.write;
|
|
467
414
|
}
|
|
468
|
-
|
|
469
415
|
const payload = {
|
|
470
416
|
data,
|
|
471
417
|
headers,
|
|
@@ -479,7 +425,6 @@ function createTransporter({
|
|
|
479
425
|
* can have information about onRetry and onFailure
|
|
480
426
|
* decisions.
|
|
481
427
|
*/
|
|
482
|
-
|
|
483
428
|
const pushToStackTrace = response => {
|
|
484
429
|
const stackFrame = {
|
|
485
430
|
request: payload,
|
|
@@ -490,12 +435,10 @@ function createTransporter({
|
|
|
490
435
|
stackTrace.push(stackFrame);
|
|
491
436
|
return stackFrame;
|
|
492
437
|
};
|
|
493
|
-
|
|
494
438
|
const response = await requester.send(payload);
|
|
495
|
-
|
|
496
439
|
if (isRetryable(response)) {
|
|
497
|
-
const stackFrame = pushToStackTrace(response);
|
|
498
|
-
|
|
440
|
+
const stackFrame = pushToStackTrace(response);
|
|
441
|
+
// If response is a timeout, we increase the number of timeouts so we can increase the timeout later.
|
|
499
442
|
if (response.isTimedOut) {
|
|
500
443
|
timeoutsCount++;
|
|
501
444
|
}
|
|
@@ -505,23 +448,18 @@ function createTransporter({
|
|
|
505
448
|
* when a retry error does not happen.
|
|
506
449
|
*/
|
|
507
450
|
// eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
|
|
508
|
-
|
|
509
|
-
|
|
510
451
|
console.log('Retryable failure', stackFrameWithoutCredentials(stackFrame));
|
|
511
452
|
/**
|
|
512
453
|
* We also store the state of the host in failure cases. If the host, is
|
|
513
454
|
* down it will remain down for the next 2 minutes. In a timeout situation,
|
|
514
455
|
* this host will be added end of the list of hosts on the next request.
|
|
515
456
|
*/
|
|
516
|
-
|
|
517
457
|
await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));
|
|
518
458
|
return retry(retryableHosts, getTimeout);
|
|
519
459
|
}
|
|
520
|
-
|
|
521
460
|
if (isSuccess(response)) {
|
|
522
461
|
return deserializeSuccess(response);
|
|
523
462
|
}
|
|
524
|
-
|
|
525
463
|
pushToStackTrace(response);
|
|
526
464
|
throw deserializeFailure(response, stackTrace);
|
|
527
465
|
};
|
|
@@ -533,20 +471,16 @@ function createTransporter({
|
|
|
533
471
|
* 2. We also get from the retryable options a timeout multiplier that is tailored
|
|
534
472
|
* for the current context.
|
|
535
473
|
*/
|
|
536
|
-
|
|
537
|
-
|
|
538
474
|
const compatibleHosts = hosts.filter(host => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'));
|
|
539
475
|
const options = await createRetryableOptions(compatibleHosts);
|
|
540
476
|
return retry([...options.hosts].reverse(), options.getTimeout);
|
|
541
477
|
}
|
|
542
|
-
|
|
543
478
|
function createRequest(request, requestOptions = {}) {
|
|
544
479
|
/**
|
|
545
480
|
* A read request is either a `GET` request, or a request that we make
|
|
546
481
|
* via the `read` transporter (e.g. `search`).
|
|
547
482
|
*/
|
|
548
483
|
const isRead = request.useReadTransporter || request.method === 'GET';
|
|
549
|
-
|
|
550
484
|
if (!isRead) {
|
|
551
485
|
/**
|
|
552
486
|
* On write requests, no cache mechanisms are applied, and we
|
|
@@ -554,7 +488,6 @@ function createTransporter({
|
|
|
554
488
|
*/
|
|
555
489
|
return retryableRequest(request, requestOptions, isRead);
|
|
556
490
|
}
|
|
557
|
-
|
|
558
491
|
const createRetryableRequest = () => {
|
|
559
492
|
/**
|
|
560
493
|
* Then, we prepare a function factory that contains the construction of
|
|
@@ -568,14 +501,11 @@ function createTransporter({
|
|
|
568
501
|
* request is "cacheable" - should be cached. Note that, once again,
|
|
569
502
|
* the user can force this option.
|
|
570
503
|
*/
|
|
571
|
-
|
|
572
|
-
|
|
573
504
|
const cacheable = requestOptions.cacheable || request.cacheable;
|
|
574
505
|
/**
|
|
575
506
|
* If is not "cacheable", we immediately trigger the retryable request, no
|
|
576
507
|
* need to check cache implementations.
|
|
577
508
|
*/
|
|
578
|
-
|
|
579
509
|
if (cacheable !== true) {
|
|
580
510
|
return createRetryableRequest();
|
|
581
511
|
}
|
|
@@ -584,8 +514,6 @@ function createTransporter({
|
|
|
584
514
|
* the cache implementations if this request is on progress or if the
|
|
585
515
|
* response already exists on the cache.
|
|
586
516
|
*/
|
|
587
|
-
|
|
588
|
-
|
|
589
517
|
const key = {
|
|
590
518
|
request,
|
|
591
519
|
requestOptions,
|
|
@@ -598,7 +526,6 @@ function createTransporter({
|
|
|
598
526
|
* With the computed key, we first ask the responses cache
|
|
599
527
|
* implementation if this request was been resolved before.
|
|
600
528
|
*/
|
|
601
|
-
|
|
602
529
|
return responsesCache.get(key, () => {
|
|
603
530
|
/**
|
|
604
531
|
* If the request has never resolved before, we actually ask if there
|
|
@@ -620,7 +547,6 @@ function createTransporter({
|
|
|
620
547
|
miss: response => responsesCache.set(key, response)
|
|
621
548
|
});
|
|
622
549
|
}
|
|
623
|
-
|
|
624
550
|
return {
|
|
625
551
|
hostsCache,
|
|
626
552
|
requester,
|
|
@@ -638,17 +564,13 @@ function createTransporter({
|
|
|
638
564
|
function createAlgoliaAgent(version) {
|
|
639
565
|
const algoliaAgent = {
|
|
640
566
|
value: `Algolia for JavaScript (${version})`,
|
|
641
|
-
|
|
642
567
|
add(options) {
|
|
643
568
|
const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;
|
|
644
|
-
|
|
645
569
|
if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
|
|
646
570
|
algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
|
|
647
571
|
}
|
|
648
|
-
|
|
649
572
|
return algoliaAgent;
|
|
650
573
|
}
|
|
651
|
-
|
|
652
574
|
};
|
|
653
575
|
return algoliaAgent;
|
|
654
576
|
}
|
|
@@ -723,7 +645,7 @@ function createXhrRequester() {
|
|
|
723
645
|
}
|
|
724
646
|
|
|
725
647
|
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
726
|
-
const apiClientVersion = '5.0.0-alpha.
|
|
648
|
+
const apiClientVersion = '5.0.0-alpha.27';
|
|
727
649
|
function getDefaultHosts(appId) {
|
|
728
650
|
return [
|
|
729
651
|
{
|
|
@@ -2,7 +2,7 @@ import { createAuth, createTransporter, getAlgoliaAgent, shuffle, DEFAULT_CONNEC
|
|
|
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 = '5.0.0-alpha.
|
|
5
|
+
const apiClientVersion = '5.0.0-alpha.27';
|
|
6
6
|
function getDefaultHosts(appId) {
|
|
7
7
|
return [
|
|
8
8
|
{
|
package/dist/recommend.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! recommend.umd.js | 5.0.0-alpha.
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/recommend"]={})}(this,(function(e){"use strict";function t(e){let t;const r=`algolia-client-js-${e.key}`;function s(){return void 0===t&&(t=e.localStorage||window.localStorage),t}function a(){return JSON.parse(s().getItem(r)||"{}")}return{get:(e,t,r={miss:()=>Promise.resolve()})=>Promise.resolve().then((()=>{const r=JSON.stringify(e),s=a()[r];return Promise.all([s||t(),void 0!==s])})).then((([e,t])=>Promise.all([e,t||r.miss(e)]))).then((([e])=>e)),set:(e,t)=>Promise.resolve().then((()=>{const o=a();return o[JSON.stringify(e)]=t,s().setItem(r,JSON.stringify(o)),t})),delete:e=>Promise.resolve().then((()=>{const t=a();delete t[JSON.stringify(e)],s().setItem(r,JSON.stringify(t))})),clear:()=>Promise.resolve().then((()=>{s().removeItem(r)}))}}function r(e){const t=[...e.caches],s=t.shift();return void 0===s?{get:(e,t,r={miss:()=>Promise.resolve()})=>t().then((e=>Promise.all([e,r.miss(e)]))).then((([e])=>e)),set:(e,t)=>Promise.resolve(t),delete:e=>Promise.resolve(),clear:()=>Promise.resolve()}:{get:(e,a,o={miss:()=>Promise.resolve()})=>s.get(e,a,o).catch((()=>r({caches:t}).get(e,a,o))),set:(e,a)=>s.set(e,a).catch((()=>r({caches:t}).set(e,a))),delete:e=>s.delete(e).catch((()=>r({caches:t}).delete(e))),clear:()=>s.clear().catch((()=>r({caches:t}).clear()))}}function s(e={serializable:!0}){let t={};return{get(r,s,a={miss:()=>Promise.resolve()}){const o=JSON.stringify(r);if(o in t)return Promise.resolve(e.serializable?JSON.parse(t[o]):t[o]);const n=s();return n.then((e=>a.miss(e))).then((()=>n))},set:(r,s)=>(t[JSON.stringify(r)]=e.serializable?JSON.stringify(s):s,Promise.resolve(s)),delete:e=>(delete t[JSON.stringify(e)],Promise.resolve()),clear:()=>(t={},Promise.resolve())}}const a=12e4;function o(e,t="up"){const r=Date.now();return{...e,status:t,lastUpdate:r,isUp:function(){return"up"===t||Date.now()-r>a},isTimedOut:function(){return"timed out"===t&&Date.now()-r<=a}}}function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class i extends Error{constructor(e,t){super(e),n(this,"name","AlgoliaError"),t&&(this.name=t)}}class c extends i{constructor(e,t,r){super(e,r),n(this,"stackTrace",void 0),this.stackTrace=t}}class u extends c{constructor(e){super("Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.",e,"RetryError")}}class l extends c{constructor(e,t,r){super(e,r,"ApiError"),n(this,"status",void 0),this.status=t}}class d extends i{constructor(e,t){super(e,"DeserializationError"),n(this,"response",void 0),this.response=t}}function h(e,t,r){const s=function(e){const t=e=>"[object Object]"===Object.prototype.toString.call(e)||"[object Array]"===Object.prototype.toString.call(e);return Object.keys(e).map((r=>`${r}=${encodeURIComponent(t(e[r])?JSON.stringify(e[r]):e[r])}`)).join("&")}(r);let a=`${e.protocol}://${e.url}/${"/"===t.charAt(0)?t.substr(1):t}`;return s.length&&(a+=`?${s}`),a}function m(e){const t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...e,request:{...e.request,headers:{...e.request.headers,...t}}}}function p({hosts:e,hostsCache:t,baseHeaders:r,baseQueryParameters:s,algoliaAgent:a,timeouts:n,requester:i,requestsCache:c,responsesCache:p}){async function g(c,p,g=!0){const f=[],y=function(e,t){if("GET"===e.method||void 0===e.data&&void 0===t.data)return;const r=Array.isArray(e.data)?e.data:{...e.data,...t.data};return JSON.stringify(r)}(c,p),P=function(e,t,r){const s={Accept:"application/json",...e,...t,...r},a={};return Object.keys(s).forEach((e=>{const t=s[e];a[e.toLowerCase()]=t})),a}(r,c.headers,p.headers),w="GET"===c.method?{...c.data,...p.data}:{},q={"x-algolia-agent":a.value,...s,...c.queryParameters,...w};if(p&&p.queryParameters)for(const e of Object.keys(p.queryParameters))p.queryParameters[e]&&"[object Object]"!==Object.prototype.toString.call(p.queryParameters[e])?q[e]=p.queryParameters[e].toString():q[e]=p.queryParameters[e];let v=0;const b=async(e,r)=>{const s=e.pop();if(void 0===s)throw new u(function(e){return e.map((e=>m(e)))}(f));let a=p.timeout;void 0===a&&(a=g?n.read:n.write);const w={data:y,headers:P,method:c.method,url:h(s,c.path,q),connectTimeout:r(v,n.connect),responseTimeout:r(v,a)},O=t=>{const r={request:w,response:t,host:s,triesLeft:e.length};return f.push(r),r},T=await i.send(w);if(function({isTimedOut:e,status:t}){return e||function({isTimedOut:e,status:t}){return!e&&0==~~t}({isTimedOut:e,status:t})||2!=~~(t/100)&&4!=~~(t/100)}(T)){const a=O(T);return T.isTimedOut&&v++,console.log("Retryable failure",m(a)),await t.set(s,o(s,T.isTimedOut?"timed out":"down")),b(e,r)}if(function({status:e}){return 2==~~(e/100)}(T))return function(e){try{return JSON.parse(e.content)}catch(t){throw new d(t.message,e)}}(T);throw O(T),function({content:e,status:t},r){let s=e;try{s=JSON.parse(e).message}catch(e){}return new l(s,t,r)}(T,f)},O=e.filter((e=>"readWrite"===e.accept||(g?"read"===e.accept:"write"===e.accept))),T=await async function(e){const r=await Promise.all(e.map((e=>t.get(e,(()=>Promise.resolve(o(e))))))),s=r.filter((e=>e.isUp())),a=r.filter((e=>e.isTimedOut())),n=[...s,...a];return{hosts:n.length>0?n:e,getTimeout:(e,t)=>(0===a.length&&0===e?1:a.length+3+e)*t}}(O);return b([...T.hosts].reverse(),T.getTimeout)}return{hostsCache:t,requester:i,timeouts:n,algoliaAgent:a,baseHeaders:r,baseQueryParameters:s,hosts:e,request:function(e,t={}){const a=e.useReadTransporter||"GET"===e.method;if(!a)return g(e,t,a);const o=()=>g(e,t);if(!0!==(t.cacheable||e.cacheable))return o();const n={request:e,requestOptions:t,transporter:{queryParameters:s,headers:r}};return p.get(n,(()=>c.get(n,(()=>c.set(n,o()).then((e=>Promise.all([c.delete(n),e])),(e=>Promise.all([c.delete(n),Promise.reject(e)]))).then((([e,t])=>t))))),{miss:e=>p.set(n,e)})},requestsCache:c,responsesCache:p}}function g({algoliaAgents:e,client:t,version:r}){const s=function(e){const t={value:`Algolia for JavaScript (${e})`,add(e){const r=`; ${e.segment}${void 0!==e.version?` (${e.version})`:""}`;return-1===t.value.indexOf(r)&&(t.value=`${t.value}${r}`),t}};return t}(r).add({segment:t,version:r});return e.forEach((e=>s.add(e))),s}const f="5.0.0-alpha.25";function y(e){return[{url:`${e}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${e}.algolia.net`,accept:"write",protocol:"https"}].concat(function(e){const t=e;for(let r=e.length-1;r>0;r--){const s=Math.floor(Math.random()*(r+1)),a=e[r];t[r]=e[s],t[s]=a}return t}([{url:`${e}-1.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${e}-2.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${e}-3.algolianet.com`,accept:"readWrite",protocol:"https"}]))}e.apiClientVersion=f,e.recommendClient=function(e,a,o){if(!e||"string"!=typeof e)throw new Error("`appId` is missing.");if(!a||"string"!=typeof a)throw new Error("`apiKey` is missing.");return function({appId:e,apiKey:t,authMode:r,algoliaAgents:s,...a}){const o=function(e,t,r="WithinHeaders"){const s={"x-algolia-api-key":t,"x-algolia-application-id":e};return{headers:()=>"WithinHeaders"===r?s:{},queryParameters:()=>"WithinQueryParameters"===r?s:{}}}(e,t,r),n=p({hosts:y(e),...a,algoliaAgent:g({algoliaAgents:s,client:"Recommend",version:f}),baseHeaders:{"content-type":"text/plain",...o.headers(),...a.baseHeaders},baseQueryParameters:{...o.queryParameters(),...a.baseQueryParameters}});return{transporter:n,appId:e,clearCache:()=>Promise.all([n.requestsCache.clear(),n.responsesCache.clear()]).then((()=>{})),get _ua(){return n.algoliaAgent.value},addAlgoliaAgent(e,t){n.algoliaAgent.add({segment:e,version:t})},del({path:e,parameters:t},r){if(!e)throw new Error("Parameter `path` is required when calling `del`.");const s={method:"DELETE",path:"/1{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return n.request(s,r)},get({path:e,parameters:t},r){if(!e)throw new Error("Parameter `path` is required when calling `get`.");const s={method:"GET",path:"/1{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return n.request(s,r)},getRecommendations(e,t){if(!e)throw new Error("Parameter `getRecommendationsParams` is required when calling `getRecommendations`.");if(!e.requests)throw new Error("Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.");const r={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:e,useReadTransporter:!0,cacheable:!0};return n.request(r,t)},post({path:e,parameters:t,body:r},s){if(!e)throw new Error("Parameter `path` is required when calling `post`.");const a={method:"POST",path:"/1{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:r||{}};return n.request(a,s)},put({path:e,parameters:t,body:r},s){if(!e)throw new Error("Parameter `path` is required when calling `put`.");const a={method:"PUT",path:"/1{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:r||{}};return n.request(a,s)}}}({appId:e,apiKey:a,timeouts:{connect:1e3,read:2e3,write:3e4},requester:{send:function(e){return new Promise((t=>{const r=new XMLHttpRequest;r.open(e.method,e.url,!0),Object.keys(e.headers).forEach((t=>r.setRequestHeader(t,e.headers[t])));const s=(e,s)=>setTimeout((()=>{r.abort(),t({status:0,content:s,isTimedOut:!0})}),e),a=s(e.connectTimeout,"Connection timeout");let o;r.onreadystatechange=()=>{r.readyState>r.OPENED&&void 0===o&&(clearTimeout(a),o=s(e.responseTimeout,"Socket timeout"))},r.onerror=()=>{0===r.status&&(clearTimeout(a),clearTimeout(o),t({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}))},r.onload=()=>{clearTimeout(a),clearTimeout(o),t({content:r.responseText,status:r.status,isTimedOut:!1})},r.send(e.data)}))}},algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:s(),requestsCache:s({serializable:!1}),hostsCache:r({caches:[t({key:`5.0.0-alpha.25-${e}`}),s()]}),...o})}}));
|
|
1
|
+
/*! recommend.umd.js | 5.0.0-alpha.27 | © Algolia, inc. | https://github.com/algolia/algoliasearch-client-javascript */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@algolia/recommend"]={})}(this,(function(e){"use strict";function t(e){let t;const r=`algolia-client-js-${e.key}`;function s(){return void 0===t&&(t=e.localStorage||window.localStorage),t}function a(){return JSON.parse(s().getItem(r)||"{}")}return{get:(e,t,r={miss:()=>Promise.resolve()})=>Promise.resolve().then((()=>{const r=JSON.stringify(e),s=a()[r];return Promise.all([s||t(),void 0!==s])})).then((([e,t])=>Promise.all([e,t||r.miss(e)]))).then((([e])=>e)),set:(e,t)=>Promise.resolve().then((()=>{const o=a();return o[JSON.stringify(e)]=t,s().setItem(r,JSON.stringify(o)),t})),delete:e=>Promise.resolve().then((()=>{const t=a();delete t[JSON.stringify(e)],s().setItem(r,JSON.stringify(t))})),clear:()=>Promise.resolve().then((()=>{s().removeItem(r)}))}}function r(e){const t=[...e.caches],s=t.shift();return void 0===s?{get:(e,t,r={miss:()=>Promise.resolve()})=>t().then((e=>Promise.all([e,r.miss(e)]))).then((([e])=>e)),set:(e,t)=>Promise.resolve(t),delete:e=>Promise.resolve(),clear:()=>Promise.resolve()}:{get:(e,a,o={miss:()=>Promise.resolve()})=>s.get(e,a,o).catch((()=>r({caches:t}).get(e,a,o))),set:(e,a)=>s.set(e,a).catch((()=>r({caches:t}).set(e,a))),delete:e=>s.delete(e).catch((()=>r({caches:t}).delete(e))),clear:()=>s.clear().catch((()=>r({caches:t}).clear()))}}function s(e={serializable:!0}){let t={};return{get(r,s,a={miss:()=>Promise.resolve()}){const o=JSON.stringify(r);if(o in t)return Promise.resolve(e.serializable?JSON.parse(t[o]):t[o]);const n=s();return n.then((e=>a.miss(e))).then((()=>n))},set:(r,s)=>(t[JSON.stringify(r)]=e.serializable?JSON.stringify(s):s,Promise.resolve(s)),delete:e=>(delete t[JSON.stringify(e)],Promise.resolve()),clear:()=>(t={},Promise.resolve())}}const a=12e4;function o(e,t="up"){const r=Date.now();return{...e,status:t,lastUpdate:r,isUp:function(){return"up"===t||Date.now()-r>a},isTimedOut:function(){return"timed out"===t&&Date.now()-r<=a}}}function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class i extends Error{constructor(e,t){super(e),n(this,"name","AlgoliaError"),t&&(this.name=t)}}class c extends i{constructor(e,t,r){super(e,r),n(this,"stackTrace",void 0),this.stackTrace=t}}class u extends c{constructor(e){super("Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.",e,"RetryError")}}class l extends c{constructor(e,t,r){super(e,r,"ApiError"),n(this,"status",void 0),this.status=t}}class d extends i{constructor(e,t){super(e,"DeserializationError"),n(this,"response",void 0),this.response=t}}function h(e,t,r){const s=function(e){const t=e=>"[object Object]"===Object.prototype.toString.call(e)||"[object Array]"===Object.prototype.toString.call(e);return Object.keys(e).map((r=>`${r}=${encodeURIComponent(t(e[r])?JSON.stringify(e[r]):e[r])}`)).join("&")}(r);let a=`${e.protocol}://${e.url}/${"/"===t.charAt(0)?t.substr(1):t}`;return s.length&&(a+=`?${s}`),a}function m(e){const t=e.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...e,request:{...e.request,headers:{...e.request.headers,...t}}}}function p({hosts:e,hostsCache:t,baseHeaders:r,baseQueryParameters:s,algoliaAgent:a,timeouts:n,requester:i,requestsCache:c,responsesCache:p}){async function g(c,p,g=!0){const f=[],y=function(e,t){if("GET"===e.method||void 0===e.data&&void 0===t.data)return;const r=Array.isArray(e.data)?e.data:{...e.data,...t.data};return JSON.stringify(r)}(c,p),P=function(e,t,r){const s={Accept:"application/json",...e,...t,...r},a={};return Object.keys(s).forEach((e=>{const t=s[e];a[e.toLowerCase()]=t})),a}(r,c.headers,p.headers),w="GET"===c.method?{...c.data,...p.data}:{},q={"x-algolia-agent":a.value,...s,...c.queryParameters,...w};if(p&&p.queryParameters)for(const e of Object.keys(p.queryParameters))p.queryParameters[e]&&"[object Object]"!==Object.prototype.toString.call(p.queryParameters[e])?q[e]=p.queryParameters[e].toString():q[e]=p.queryParameters[e];let v=0;const b=async(e,r)=>{const s=e.pop();if(void 0===s)throw new u(function(e){return e.map((e=>m(e)))}(f));let a=p.timeout;void 0===a&&(a=g?n.read:n.write);const w={data:y,headers:P,method:c.method,url:h(s,c.path,q),connectTimeout:r(v,n.connect),responseTimeout:r(v,a)},O=t=>{const r={request:w,response:t,host:s,triesLeft:e.length};return f.push(r),r},T=await i.send(w);if(function({isTimedOut:e,status:t}){return e||function({isTimedOut:e,status:t}){return!e&&0==~~t}({isTimedOut:e,status:t})||2!=~~(t/100)&&4!=~~(t/100)}(T)){const a=O(T);return T.isTimedOut&&v++,console.log("Retryable failure",m(a)),await t.set(s,o(s,T.isTimedOut?"timed out":"down")),b(e,r)}if(function({status:e}){return 2==~~(e/100)}(T))return function(e){try{return JSON.parse(e.content)}catch(t){throw new d(t.message,e)}}(T);throw O(T),function({content:e,status:t},r){let s=e;try{s=JSON.parse(e).message}catch(e){}return new l(s,t,r)}(T,f)},O=e.filter((e=>"readWrite"===e.accept||(g?"read"===e.accept:"write"===e.accept))),T=await async function(e){const r=await Promise.all(e.map((e=>t.get(e,(()=>Promise.resolve(o(e))))))),s=r.filter((e=>e.isUp())),a=r.filter((e=>e.isTimedOut())),n=[...s,...a];return{hosts:n.length>0?n:e,getTimeout:(e,t)=>(0===a.length&&0===e?1:a.length+3+e)*t}}(O);return b([...T.hosts].reverse(),T.getTimeout)}return{hostsCache:t,requester:i,timeouts:n,algoliaAgent:a,baseHeaders:r,baseQueryParameters:s,hosts:e,request:function(e,t={}){const a=e.useReadTransporter||"GET"===e.method;if(!a)return g(e,t,a);const o=()=>g(e,t);if(!0!==(t.cacheable||e.cacheable))return o();const n={request:e,requestOptions:t,transporter:{queryParameters:s,headers:r}};return p.get(n,(()=>c.get(n,(()=>c.set(n,o()).then((e=>Promise.all([c.delete(n),e])),(e=>Promise.all([c.delete(n),Promise.reject(e)]))).then((([e,t])=>t))))),{miss:e=>p.set(n,e)})},requestsCache:c,responsesCache:p}}function g({algoliaAgents:e,client:t,version:r}){const s=function(e){const t={value:`Algolia for JavaScript (${e})`,add(e){const r=`; ${e.segment}${void 0!==e.version?` (${e.version})`:""}`;return-1===t.value.indexOf(r)&&(t.value=`${t.value}${r}`),t}};return t}(r).add({segment:t,version:r});return e.forEach((e=>s.add(e))),s}const f="5.0.0-alpha.27";function y(e){return[{url:`${e}-dsn.algolia.net`,accept:"read",protocol:"https"},{url:`${e}.algolia.net`,accept:"write",protocol:"https"}].concat(function(e){const t=e;for(let r=e.length-1;r>0;r--){const s=Math.floor(Math.random()*(r+1)),a=e[r];t[r]=e[s],t[s]=a}return t}([{url:`${e}-1.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${e}-2.algolianet.com`,accept:"readWrite",protocol:"https"},{url:`${e}-3.algolianet.com`,accept:"readWrite",protocol:"https"}]))}e.apiClientVersion=f,e.recommendClient=function(e,a,o){if(!e||"string"!=typeof e)throw new Error("`appId` is missing.");if(!a||"string"!=typeof a)throw new Error("`apiKey` is missing.");return function({appId:e,apiKey:t,authMode:r,algoliaAgents:s,...a}){const o=function(e,t,r="WithinHeaders"){const s={"x-algolia-api-key":t,"x-algolia-application-id":e};return{headers:()=>"WithinHeaders"===r?s:{},queryParameters:()=>"WithinQueryParameters"===r?s:{}}}(e,t,r),n=p({hosts:y(e),...a,algoliaAgent:g({algoliaAgents:s,client:"Recommend",version:f}),baseHeaders:{"content-type":"text/plain",...o.headers(),...a.baseHeaders},baseQueryParameters:{...o.queryParameters(),...a.baseQueryParameters}});return{transporter:n,appId:e,clearCache:()=>Promise.all([n.requestsCache.clear(),n.responsesCache.clear()]).then((()=>{})),get _ua(){return n.algoliaAgent.value},addAlgoliaAgent(e,t){n.algoliaAgent.add({segment:e,version:t})},del({path:e,parameters:t},r){if(!e)throw new Error("Parameter `path` is required when calling `del`.");const s={method:"DELETE",path:"/1{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return n.request(s,r)},get({path:e,parameters:t},r){if(!e)throw new Error("Parameter `path` is required when calling `get`.");const s={method:"GET",path:"/1{path}".replace("{path}",e),queryParameters:t||{},headers:{}};return n.request(s,r)},getRecommendations(e,t){if(!e)throw new Error("Parameter `getRecommendationsParams` is required when calling `getRecommendations`.");if(!e.requests)throw new Error("Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.");const r={method:"POST",path:"/1/indexes/*/recommendations",queryParameters:{},headers:{},data:e,useReadTransporter:!0,cacheable:!0};return n.request(r,t)},post({path:e,parameters:t,body:r},s){if(!e)throw new Error("Parameter `path` is required when calling `post`.");const a={method:"POST",path:"/1{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:r||{}};return n.request(a,s)},put({path:e,parameters:t,body:r},s){if(!e)throw new Error("Parameter `path` is required when calling `put`.");const a={method:"PUT",path:"/1{path}".replace("{path}",e),queryParameters:t||{},headers:{},data:r||{}};return n.request(a,s)}}}({appId:e,apiKey:a,timeouts:{connect:1e3,read:2e3,write:3e4},requester:{send:function(e){return new Promise((t=>{const r=new XMLHttpRequest;r.open(e.method,e.url,!0),Object.keys(e.headers).forEach((t=>r.setRequestHeader(t,e.headers[t])));const s=(e,s)=>setTimeout((()=>{r.abort(),t({status:0,content:s,isTimedOut:!0})}),e),a=s(e.connectTimeout,"Connection timeout");let o;r.onreadystatechange=()=>{r.readyState>r.OPENED&&void 0===o&&(clearTimeout(a),o=s(e.responseTimeout,"Socket timeout"))},r.onerror=()=>{0===r.status&&(clearTimeout(a),clearTimeout(o),t({content:r.responseText||"Network request failed",status:r.status,isTimedOut:!1}))},r.onload=()=>{clearTimeout(a),clearTimeout(o),t({content:r.responseText,status:r.status,isTimedOut:!1})},r.send(e.data)}))}},algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:s(),requestsCache:s({serializable:!1}),hostsCache:r({caches:[t({key:`5.0.0-alpha.27-${e}`}),s()]}),...o})}}));
|
|
@@ -2,7 +2,7 @@ import type { CreateClientOptions, RequestOptions } from '@algolia/client-common
|
|
|
2
2
|
import type { DelProps, GetProps, PostProps, PutProps } from '../model/clientMethodProps';
|
|
3
3
|
import type { GetRecommendationsParams } from '../model/getRecommendationsParams';
|
|
4
4
|
import type { GetRecommendationsResponse } from '../model/getRecommendationsResponse';
|
|
5
|
-
export declare const apiClientVersion = "5.0.0-alpha.
|
|
5
|
+
export declare const apiClientVersion = "5.0.0-alpha.27";
|
|
6
6
|
export declare function createRecommendClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, ...options }: CreateClientOptions): {
|
|
7
7
|
transporter: import("@algolia/client-common").Transporter;
|
|
8
8
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algolia/recommend",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.27",
|
|
4
4
|
"description": "JavaScript client for recommend",
|
|
5
5
|
"repository": "algolia/algoliasearch-client-javascript",
|
|
6
6
|
"license": "MIT",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"clean": "rm -rf ./dist || true"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@algolia/client-common": "5.0.0-alpha.
|
|
42
|
-
"@algolia/requester-browser-xhr": "5.0.0-alpha.
|
|
43
|
-
"@algolia/requester-node-http": "5.0.0-alpha.
|
|
41
|
+
"@algolia/client-common": "5.0.0-alpha.27",
|
|
42
|
+
"@algolia/requester-browser-xhr": "5.0.0-alpha.27",
|
|
43
|
+
"@algolia/requester-node-http": "5.0.0-alpha.27"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "16.11.59",
|