@algolia/recommend 5.0.0-alpha.52 → 5.0.0-alpha.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builds/browser.d.ts +5 -5
- package/dist/builds/node.d.ts +5 -5
- package/dist/model/advancedSyntaxFeatures.d.ts +1 -1
- package/dist/model/alternativesAsExact.d.ts +1 -1
- package/dist/model/aroundRadius.d.ts +5 -5
- package/dist/model/aroundRadiusAll.d.ts +1 -1
- package/dist/model/baseRecommendRequest.d.ts +17 -17
- package/dist/model/baseRecommendationRequest.d.ts +8 -8
- package/dist/model/baseSearchParams.d.ts +3 -3
- package/dist/model/baseSearchParamsWithoutQuery.d.ts +122 -122
- package/dist/model/baseSearchResponse.d.ts +101 -101
- package/dist/model/baseTrendingRequest.d.ts +12 -12
- package/dist/model/clientMethodProps.d.ts +60 -60
- package/dist/model/distinct.d.ts +4 -4
- package/dist/model/errorBase.d.ts +6 -6
- package/dist/model/exactOnSingleWordQuery.d.ts +4 -4
- package/dist/model/facetFilters.d.ts +5 -5
- package/dist/model/facetOrdering.d.ts +12 -12
- package/dist/model/facets.d.ts +9 -9
- package/dist/model/facetsStats.d.ts +18 -18
- package/dist/model/getRecommendationsParams.d.ts +10 -10
- package/dist/model/getRecommendationsResponse.d.ts +4 -4
- package/dist/model/highlightResult.d.ts +2 -2
- package/dist/model/highlightResultOption.d.ts +19 -19
- package/dist/model/ignorePlurals.d.ts +4 -4
- package/dist/model/index.d.ts +53 -53
- package/dist/model/indexSettingsAsSearchParams.d.ts +156 -156
- package/dist/model/matchLevel.d.ts +4 -4
- package/dist/model/matchedGeoLocation.d.ts +14 -14
- package/dist/model/mixedSearchFilters.d.ts +1 -1
- package/dist/model/numericFilters.d.ts +5 -5
- package/dist/model/optionalFilters.d.ts +5 -5
- package/dist/model/personalization.d.ts +14 -14
- package/dist/model/queryType.d.ts +4 -4
- package/dist/model/rankingInfo.d.ts +50 -50
- package/dist/model/reRankingApplyFilter.d.ts +5 -5
- package/dist/model/recommendHit.d.ts +26 -26
- package/dist/model/recommendHits.d.ts +4 -4
- package/dist/model/recommendationModels.d.ts +4 -4
- package/dist/model/recommendationRequest.d.ts +3 -3
- package/dist/model/recommendationsRequest.d.ts +3 -3
- package/dist/model/recommendationsResponse.d.ts +3 -3
- package/dist/model/removeStopWords.d.ts +4 -4
- package/dist/model/removeWordsIfNoResults.d.ts +4 -4
- package/dist/model/renderingContent.d.ts +7 -7
- package/dist/model/searchParamsObject.d.ts +3 -3
- package/dist/model/searchParamsQuery.d.ts +6 -6
- package/dist/model/snippetResult.d.ts +2 -2
- package/dist/model/snippetResultOption.d.ts +11 -11
- package/dist/model/sortRemainingBy.d.ts +4 -4
- package/dist/model/tagFilters.d.ts +5 -5
- package/dist/model/trendingModels.d.ts +4 -4
- package/dist/model/trendingRequest.d.ts +3 -3
- package/dist/model/typoTolerance.d.ts +5 -5
- package/dist/model/typoToleranceEnum.d.ts +1 -1
- package/dist/model/value.d.ts +8 -8
- package/dist/recommend.cjs.js +235 -235
- package/dist/recommend.esm.browser.js +359 -359
- package/dist/recommend.esm.node.js +235 -235
- package/dist/recommend.umd.js +2 -2
- package/dist/src/recommendClient.d.ts +81 -81
- package/package.json +6 -6
|
@@ -379,16 +379,16 @@ function createTransporter({
|
|
|
379
379
|
return {
|
|
380
380
|
hosts: compatibleHostsAvailable,
|
|
381
381
|
getTimeout(timeoutsCount, baseTimeout) {
|
|
382
|
-
/**
|
|
383
|
-
* Imagine that you have 4 hosts, if timeouts will increase
|
|
384
|
-
* on the following way: 1 (timed out) > 4 (timed out) > 5 (200).
|
|
385
|
-
*
|
|
386
|
-
* Note that, the very next request, we start from the previous timeout.
|
|
387
|
-
*
|
|
388
|
-
* 5 (timed out) > 6 (timed out) > 7 ...
|
|
389
|
-
*
|
|
390
|
-
* This strategy may need to be reviewed, but is the strategy on the our
|
|
391
|
-
* current v3 version.
|
|
382
|
+
/**
|
|
383
|
+
* Imagine that you have 4 hosts, if timeouts will increase
|
|
384
|
+
* on the following way: 1 (timed out) > 4 (timed out) > 5 (200).
|
|
385
|
+
*
|
|
386
|
+
* Note that, the very next request, we start from the previous timeout.
|
|
387
|
+
*
|
|
388
|
+
* 5 (timed out) > 6 (timed out) > 7 ...
|
|
389
|
+
*
|
|
390
|
+
* This strategy may need to be reviewed, but is the strategy on the our
|
|
391
|
+
* current v3 version.
|
|
392
392
|
*/
|
|
393
393
|
const timeoutMultiplier = hostsTimedOut.length === 0 && timeoutsCount === 0 ? 1 : hostsTimedOut.length + 3 + timeoutsCount;
|
|
394
394
|
return timeoutMultiplier * baseTimeout;
|
|
@@ -397,8 +397,8 @@ function createTransporter({
|
|
|
397
397
|
}
|
|
398
398
|
async function retryableRequest(request, requestOptions, isRead = true) {
|
|
399
399
|
const stackTrace = [];
|
|
400
|
-
/**
|
|
401
|
-
* First we prepare the payload that do not depend from hosts.
|
|
400
|
+
/**
|
|
401
|
+
* First we prepare the payload that do not depend from hosts.
|
|
402
402
|
*/
|
|
403
403
|
const data = serializeData(request, requestOptions);
|
|
404
404
|
const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);
|
|
@@ -429,8 +429,8 @@ function createTransporter({
|
|
|
429
429
|
}
|
|
430
430
|
let timeoutsCount = 0;
|
|
431
431
|
const retry = async (retryableHosts, getTimeout) => {
|
|
432
|
-
/**
|
|
433
|
-
* We iterate on each host, until there is no host left.
|
|
432
|
+
/**
|
|
433
|
+
* We iterate on each host, until there is no host left.
|
|
434
434
|
*/
|
|
435
435
|
const host = retryableHosts.pop();
|
|
436
436
|
if (host === undefined) {
|
|
@@ -448,10 +448,10 @@ function createTransporter({
|
|
|
448
448
|
connectTimeout: getTimeout(timeoutsCount, timeouts.connect),
|
|
449
449
|
responseTimeout: getTimeout(timeoutsCount, responseTimeout)
|
|
450
450
|
};
|
|
451
|
-
/**
|
|
452
|
-
* The stackFrame is pushed to the stackTrace so we
|
|
453
|
-
* can have information about onRetry and onFailure
|
|
454
|
-
* decisions.
|
|
451
|
+
/**
|
|
452
|
+
* The stackFrame is pushed to the stackTrace so we
|
|
453
|
+
* can have information about onRetry and onFailure
|
|
454
|
+
* decisions.
|
|
455
455
|
*/
|
|
456
456
|
const pushToStackTrace = response => {
|
|
457
457
|
const stackFrame = {
|
|
@@ -470,17 +470,17 @@ function createTransporter({
|
|
|
470
470
|
if (response.isTimedOut) {
|
|
471
471
|
timeoutsCount++;
|
|
472
472
|
}
|
|
473
|
-
/**
|
|
474
|
-
* Failures are individually sent to the logger, allowing
|
|
475
|
-
* the end user to debug / store stack frames even
|
|
476
|
-
* when a retry error does not happen.
|
|
473
|
+
/**
|
|
474
|
+
* Failures are individually sent to the logger, allowing
|
|
475
|
+
* the end user to debug / store stack frames even
|
|
476
|
+
* when a retry error does not happen.
|
|
477
477
|
*/
|
|
478
478
|
// eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
|
|
479
479
|
console.log('Retryable failure', stackFrameWithoutCredentials(stackFrame));
|
|
480
|
-
/**
|
|
481
|
-
* We also store the state of the host in failure cases. If the host, is
|
|
482
|
-
* down it will remain down for the next 2 minutes. In a timeout situation,
|
|
483
|
-
* this host will be added end of the list of hosts on the next request.
|
|
480
|
+
/**
|
|
481
|
+
* We also store the state of the host in failure cases. If the host, is
|
|
482
|
+
* down it will remain down for the next 2 minutes. In a timeout situation,
|
|
483
|
+
* this host will be added end of the list of hosts on the next request.
|
|
484
484
|
*/
|
|
485
485
|
await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));
|
|
486
486
|
return retry(retryableHosts, getTimeout);
|
|
@@ -491,56 +491,56 @@ function createTransporter({
|
|
|
491
491
|
pushToStackTrace(response);
|
|
492
492
|
throw deserializeFailure(response, stackTrace);
|
|
493
493
|
};
|
|
494
|
-
/**
|
|
495
|
-
* Finally, for each retryable host perform request until we got a non
|
|
496
|
-
* retryable response. Some notes here:
|
|
497
|
-
*
|
|
498
|
-
* 1. The reverse here is applied so we can apply a `pop` later on => more performant.
|
|
499
|
-
* 2. We also get from the retryable options a timeout multiplier that is tailored
|
|
500
|
-
* for the current context.
|
|
494
|
+
/**
|
|
495
|
+
* Finally, for each retryable host perform request until we got a non
|
|
496
|
+
* retryable response. Some notes here:
|
|
497
|
+
*
|
|
498
|
+
* 1. The reverse here is applied so we can apply a `pop` later on => more performant.
|
|
499
|
+
* 2. We also get from the retryable options a timeout multiplier that is tailored
|
|
500
|
+
* for the current context.
|
|
501
501
|
*/
|
|
502
502
|
const compatibleHosts = hosts.filter(host => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'));
|
|
503
503
|
const options = await createRetryableOptions(compatibleHosts);
|
|
504
504
|
return retry([...options.hosts].reverse(), options.getTimeout);
|
|
505
505
|
}
|
|
506
506
|
function createRequest(request, requestOptions = {}) {
|
|
507
|
-
/**
|
|
508
|
-
* A read request is either a `GET` request, or a request that we make
|
|
509
|
-
* via the `read` transporter (e.g. `search`).
|
|
507
|
+
/**
|
|
508
|
+
* A read request is either a `GET` request, or a request that we make
|
|
509
|
+
* via the `read` transporter (e.g. `search`).
|
|
510
510
|
*/
|
|
511
511
|
const isRead = request.useReadTransporter || request.method === 'GET';
|
|
512
512
|
if (!isRead) {
|
|
513
|
-
/**
|
|
514
|
-
* On write requests, no cache mechanisms are applied, and we
|
|
515
|
-
* proxy the request immediately to the requester.
|
|
513
|
+
/**
|
|
514
|
+
* On write requests, no cache mechanisms are applied, and we
|
|
515
|
+
* proxy the request immediately to the requester.
|
|
516
516
|
*/
|
|
517
517
|
return retryableRequest(request, requestOptions, isRead);
|
|
518
518
|
}
|
|
519
519
|
const createRetryableRequest = () => {
|
|
520
|
-
/**
|
|
521
|
-
* Then, we prepare a function factory that contains the construction of
|
|
522
|
-
* the retryable request. At this point, we may *not* perform the actual
|
|
523
|
-
* request. But we want to have the function factory ready.
|
|
520
|
+
/**
|
|
521
|
+
* Then, we prepare a function factory that contains the construction of
|
|
522
|
+
* the retryable request. At this point, we may *not* perform the actual
|
|
523
|
+
* request. But we want to have the function factory ready.
|
|
524
524
|
*/
|
|
525
525
|
return retryableRequest(request, requestOptions);
|
|
526
526
|
};
|
|
527
|
-
/**
|
|
528
|
-
* Once we have the function factory ready, we need to determine of the
|
|
529
|
-
* request is "cacheable" - should be cached. Note that, once again,
|
|
530
|
-
* the user can force this option.
|
|
527
|
+
/**
|
|
528
|
+
* Once we have the function factory ready, we need to determine of the
|
|
529
|
+
* request is "cacheable" - should be cached. Note that, once again,
|
|
530
|
+
* the user can force this option.
|
|
531
531
|
*/
|
|
532
532
|
const cacheable = requestOptions.cacheable || request.cacheable;
|
|
533
|
-
/**
|
|
534
|
-
* If is not "cacheable", we immediately trigger the retryable request, no
|
|
535
|
-
* need to check cache implementations.
|
|
533
|
+
/**
|
|
534
|
+
* If is not "cacheable", we immediately trigger the retryable request, no
|
|
535
|
+
* need to check cache implementations.
|
|
536
536
|
*/
|
|
537
537
|
if (cacheable !== true) {
|
|
538
538
|
return createRetryableRequest();
|
|
539
539
|
}
|
|
540
|
-
/**
|
|
541
|
-
* If the request is "cacheable", we need to first compute the key to ask
|
|
542
|
-
* the cache implementations if this request is on progress or if the
|
|
543
|
-
* response already exists on the cache.
|
|
540
|
+
/**
|
|
541
|
+
* If the request is "cacheable", we need to first compute the key to ask
|
|
542
|
+
* the cache implementations if this request is on progress or if the
|
|
543
|
+
* response already exists on the cache.
|
|
544
544
|
*/
|
|
545
545
|
const key = {
|
|
546
546
|
request,
|
|
@@ -550,27 +550,27 @@ function createTransporter({
|
|
|
550
550
|
headers: baseHeaders
|
|
551
551
|
}
|
|
552
552
|
};
|
|
553
|
-
/**
|
|
554
|
-
* With the computed key, we first ask the responses cache
|
|
555
|
-
* implementation if this request was been resolved before.
|
|
553
|
+
/**
|
|
554
|
+
* With the computed key, we first ask the responses cache
|
|
555
|
+
* implementation if this request was been resolved before.
|
|
556
556
|
*/
|
|
557
557
|
return responsesCache.get(key, () => {
|
|
558
|
-
/**
|
|
559
|
-
* If the request has never resolved before, we actually ask if there
|
|
560
|
-
* is a current request with the same key on progress.
|
|
558
|
+
/**
|
|
559
|
+
* If the request has never resolved before, we actually ask if there
|
|
560
|
+
* is a current request with the same key on progress.
|
|
561
561
|
*/
|
|
562
562
|
return requestsCache.get(key, () =>
|
|
563
|
-
/**
|
|
564
|
-
* Finally, if there is no request in progress with the same key,
|
|
565
|
-
* this `createRetryableRequest()` will actually trigger the
|
|
566
|
-
* retryable request.
|
|
563
|
+
/**
|
|
564
|
+
* Finally, if there is no request in progress with the same key,
|
|
565
|
+
* this `createRetryableRequest()` will actually trigger the
|
|
566
|
+
* retryable request.
|
|
567
567
|
*/
|
|
568
568
|
requestsCache.set(key, createRetryableRequest()).then(response => Promise.all([requestsCache.delete(key), response]), err => Promise.all([requestsCache.delete(key), Promise.reject(err)])).then(([_, response]) => response));
|
|
569
569
|
}, {
|
|
570
|
-
/**
|
|
571
|
-
* Of course, once we get this response back from the server, we
|
|
572
|
-
* tell response cache to actually store the received response
|
|
573
|
-
* to be used later.
|
|
570
|
+
/**
|
|
571
|
+
* Of course, once we get this response back from the server, we
|
|
572
|
+
* tell response cache to actually store the received response
|
|
573
|
+
* to be used later.
|
|
574
574
|
*/
|
|
575
575
|
miss: response => responsesCache.set(key, response)
|
|
576
576
|
});
|
|
@@ -620,301 +620,301 @@ const DEFAULT_CONNECT_TIMEOUT_BROWSER = 1000;
|
|
|
620
620
|
const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
|
|
621
621
|
const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
|
|
622
622
|
|
|
623
|
-
function createXhrRequester() {
|
|
624
|
-
function send(request) {
|
|
625
|
-
return new Promise((resolve) => {
|
|
626
|
-
const baseRequester = new XMLHttpRequest();
|
|
627
|
-
baseRequester.open(request.method, request.url, true);
|
|
628
|
-
Object.keys(request.headers).forEach((key) => baseRequester.setRequestHeader(key, request.headers[key]));
|
|
629
|
-
const createTimeout = (timeout, content) => {
|
|
630
|
-
return setTimeout(() => {
|
|
631
|
-
baseRequester.abort();
|
|
632
|
-
resolve({
|
|
633
|
-
status: 0,
|
|
634
|
-
content,
|
|
635
|
-
isTimedOut: true,
|
|
636
|
-
});
|
|
637
|
-
}, timeout);
|
|
638
|
-
};
|
|
639
|
-
const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
|
|
640
|
-
let responseTimeout;
|
|
641
|
-
baseRequester.onreadystatechange = () => {
|
|
642
|
-
if (baseRequester.readyState > baseRequester.OPENED &&
|
|
643
|
-
responseTimeout === undefined) {
|
|
644
|
-
clearTimeout(connectTimeout);
|
|
645
|
-
responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
|
|
646
|
-
}
|
|
647
|
-
};
|
|
648
|
-
baseRequester.onerror = () => {
|
|
649
|
-
// istanbul ignore next
|
|
650
|
-
if (baseRequester.status === 0) {
|
|
651
|
-
clearTimeout(connectTimeout);
|
|
652
|
-
clearTimeout(responseTimeout);
|
|
653
|
-
resolve({
|
|
654
|
-
content: baseRequester.responseText || 'Network request failed',
|
|
655
|
-
status: baseRequester.status,
|
|
656
|
-
isTimedOut: false,
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
baseRequester.onload = () => {
|
|
661
|
-
clearTimeout(connectTimeout);
|
|
662
|
-
clearTimeout(responseTimeout);
|
|
663
|
-
resolve({
|
|
664
|
-
content: baseRequester.responseText,
|
|
665
|
-
status: baseRequester.status,
|
|
666
|
-
isTimedOut: false,
|
|
667
|
-
});
|
|
668
|
-
};
|
|
669
|
-
baseRequester.send(request.data);
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
return { send };
|
|
623
|
+
function createXhrRequester() {
|
|
624
|
+
function send(request) {
|
|
625
|
+
return new Promise((resolve) => {
|
|
626
|
+
const baseRequester = new XMLHttpRequest();
|
|
627
|
+
baseRequester.open(request.method, request.url, true);
|
|
628
|
+
Object.keys(request.headers).forEach((key) => baseRequester.setRequestHeader(key, request.headers[key]));
|
|
629
|
+
const createTimeout = (timeout, content) => {
|
|
630
|
+
return setTimeout(() => {
|
|
631
|
+
baseRequester.abort();
|
|
632
|
+
resolve({
|
|
633
|
+
status: 0,
|
|
634
|
+
content,
|
|
635
|
+
isTimedOut: true,
|
|
636
|
+
});
|
|
637
|
+
}, timeout);
|
|
638
|
+
};
|
|
639
|
+
const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
|
|
640
|
+
let responseTimeout;
|
|
641
|
+
baseRequester.onreadystatechange = () => {
|
|
642
|
+
if (baseRequester.readyState > baseRequester.OPENED &&
|
|
643
|
+
responseTimeout === undefined) {
|
|
644
|
+
clearTimeout(connectTimeout);
|
|
645
|
+
responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
baseRequester.onerror = () => {
|
|
649
|
+
// istanbul ignore next
|
|
650
|
+
if (baseRequester.status === 0) {
|
|
651
|
+
clearTimeout(connectTimeout);
|
|
652
|
+
clearTimeout(responseTimeout);
|
|
653
|
+
resolve({
|
|
654
|
+
content: baseRequester.responseText || 'Network request failed',
|
|
655
|
+
status: baseRequester.status,
|
|
656
|
+
isTimedOut: false,
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
baseRequester.onload = () => {
|
|
661
|
+
clearTimeout(connectTimeout);
|
|
662
|
+
clearTimeout(responseTimeout);
|
|
663
|
+
resolve({
|
|
664
|
+
content: baseRequester.responseText,
|
|
665
|
+
status: baseRequester.status,
|
|
666
|
+
isTimedOut: false,
|
|
667
|
+
});
|
|
668
|
+
};
|
|
669
|
+
baseRequester.send(request.data);
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
return { send };
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
-
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
676
|
-
const apiClientVersion = '5.0.0-alpha.
|
|
677
|
-
function getDefaultHosts(appId) {
|
|
678
|
-
return [
|
|
679
|
-
{
|
|
680
|
-
url: `${appId}-dsn.algolia.net`,
|
|
681
|
-
accept: 'read',
|
|
682
|
-
protocol: 'https',
|
|
683
|
-
},
|
|
684
|
-
{
|
|
685
|
-
url: `${appId}.algolia.net`,
|
|
686
|
-
accept: 'write',
|
|
687
|
-
protocol: 'https',
|
|
688
|
-
},
|
|
689
|
-
].concat(shuffle([
|
|
690
|
-
{
|
|
691
|
-
url: `${appId}-1.algolianet.com`,
|
|
692
|
-
accept: 'readWrite',
|
|
693
|
-
protocol: 'https',
|
|
694
|
-
},
|
|
695
|
-
{
|
|
696
|
-
url: `${appId}-2.algolianet.com`,
|
|
697
|
-
accept: 'readWrite',
|
|
698
|
-
protocol: 'https',
|
|
699
|
-
},
|
|
700
|
-
{
|
|
701
|
-
url: `${appId}-3.algolianet.com`,
|
|
702
|
-
accept: 'readWrite',
|
|
703
|
-
protocol: 'https',
|
|
704
|
-
},
|
|
705
|
-
]));
|
|
706
|
-
}
|
|
707
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
708
|
-
function createRecommendClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, ...options }) {
|
|
709
|
-
const auth = createAuth(appIdOption, apiKeyOption, authMode);
|
|
710
|
-
const transporter = createTransporter({
|
|
711
|
-
hosts: getDefaultHosts(appIdOption),
|
|
712
|
-
...options,
|
|
713
|
-
algoliaAgent: getAlgoliaAgent({
|
|
714
|
-
algoliaAgents,
|
|
715
|
-
client: 'Recommend',
|
|
716
|
-
version: apiClientVersion,
|
|
717
|
-
}),
|
|
718
|
-
baseHeaders: {
|
|
719
|
-
'content-type': 'text/plain',
|
|
720
|
-
...auth.headers(),
|
|
721
|
-
...options.baseHeaders,
|
|
722
|
-
},
|
|
723
|
-
baseQueryParameters: {
|
|
724
|
-
...auth.queryParameters(),
|
|
725
|
-
...options.baseQueryParameters,
|
|
726
|
-
},
|
|
727
|
-
});
|
|
728
|
-
return {
|
|
729
|
-
transporter,
|
|
730
|
-
/**
|
|
731
|
-
* The `appId` currently in use.
|
|
732
|
-
*/
|
|
733
|
-
appId: appIdOption,
|
|
734
|
-
/**
|
|
735
|
-
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
|
|
736
|
-
*/
|
|
737
|
-
clearCache() {
|
|
738
|
-
return Promise.all([
|
|
739
|
-
transporter.requestsCache.clear(),
|
|
740
|
-
transporter.responsesCache.clear(),
|
|
741
|
-
]).then(() => undefined);
|
|
742
|
-
},
|
|
743
|
-
/**
|
|
744
|
-
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
|
|
745
|
-
*/
|
|
746
|
-
get _ua() {
|
|
747
|
-
return transporter.algoliaAgent.value;
|
|
748
|
-
},
|
|
749
|
-
/**
|
|
750
|
-
* Adds a `segment` to the `x-algolia-agent` sent with every requests.
|
|
751
|
-
*
|
|
752
|
-
* @param segment - The algolia agent (user-agent) segment to add.
|
|
753
|
-
* @param version - The version of the agent.
|
|
754
|
-
*/
|
|
755
|
-
addAlgoliaAgent(segment, version) {
|
|
756
|
-
transporter.algoliaAgent.add({ segment, version });
|
|
757
|
-
},
|
|
758
|
-
/**
|
|
759
|
-
* This method allow you to send requests to the Algolia REST API.
|
|
760
|
-
*
|
|
761
|
-
* @summary Send requests to the Algolia REST API.
|
|
762
|
-
* @param del - The del object.
|
|
763
|
-
* @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
|
|
764
|
-
* @param del.parameters - Query parameters to be applied to the current query.
|
|
765
|
-
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
766
|
-
*/
|
|
767
|
-
del({ path, parameters }, requestOptions) {
|
|
768
|
-
if (!path) {
|
|
769
|
-
throw new Error('Parameter `path` is required when calling `del`.');
|
|
770
|
-
}
|
|
771
|
-
const requestPath = '/1{path}'.replace('{path}', path);
|
|
772
|
-
const headers = {};
|
|
773
|
-
const queryParameters = parameters ? parameters : {};
|
|
774
|
-
const request = {
|
|
775
|
-
method: 'DELETE',
|
|
776
|
-
path: requestPath,
|
|
777
|
-
queryParameters,
|
|
778
|
-
headers,
|
|
779
|
-
};
|
|
780
|
-
return transporter.request(request, requestOptions);
|
|
781
|
-
},
|
|
782
|
-
/**
|
|
783
|
-
* This method allow you to send requests to the Algolia REST API.
|
|
784
|
-
*
|
|
785
|
-
* @summary Send requests to the Algolia REST API.
|
|
786
|
-
* @param get - The get object.
|
|
787
|
-
* @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
|
|
788
|
-
* @param get.parameters - Query parameters to be applied to the current query.
|
|
789
|
-
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
790
|
-
*/
|
|
791
|
-
get({ path, parameters }, requestOptions) {
|
|
792
|
-
if (!path) {
|
|
793
|
-
throw new Error('Parameter `path` is required when calling `get`.');
|
|
794
|
-
}
|
|
795
|
-
const requestPath = '/1{path}'.replace('{path}', path);
|
|
796
|
-
const headers = {};
|
|
797
|
-
const queryParameters = parameters ? parameters : {};
|
|
798
|
-
const request = {
|
|
799
|
-
method: 'GET',
|
|
800
|
-
path: requestPath,
|
|
801
|
-
queryParameters,
|
|
802
|
-
headers,
|
|
803
|
-
};
|
|
804
|
-
return transporter.request(request, requestOptions);
|
|
805
|
-
},
|
|
806
|
-
/**
|
|
807
|
-
* Returns recommendations or trending results, for a specific model and `objectID`.
|
|
808
|
-
*
|
|
809
|
-
* @summary Get results.
|
|
810
|
-
* @param getRecommendationsParams - The getRecommendationsParams object.
|
|
811
|
-
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
812
|
-
*/
|
|
813
|
-
getRecommendations(getRecommendationsParams, requestOptions) {
|
|
814
|
-
if (!getRecommendationsParams) {
|
|
815
|
-
throw new Error('Parameter `getRecommendationsParams` is required when calling `getRecommendations`.');
|
|
816
|
-
}
|
|
817
|
-
if (!getRecommendationsParams.requests) {
|
|
818
|
-
throw new Error('Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.');
|
|
819
|
-
}
|
|
820
|
-
const requestPath = '/1/indexes/*/recommendations';
|
|
821
|
-
const headers = {};
|
|
822
|
-
const queryParameters = {};
|
|
823
|
-
const request = {
|
|
824
|
-
method: 'POST',
|
|
825
|
-
path: requestPath,
|
|
826
|
-
queryParameters,
|
|
827
|
-
headers,
|
|
828
|
-
data: getRecommendationsParams,
|
|
829
|
-
useReadTransporter: true,
|
|
830
|
-
cacheable: true,
|
|
831
|
-
};
|
|
832
|
-
return transporter.request(request, requestOptions);
|
|
833
|
-
},
|
|
834
|
-
/**
|
|
835
|
-
* This method allow you to send requests to the Algolia REST API.
|
|
836
|
-
*
|
|
837
|
-
* @summary Send requests to the Algolia REST API.
|
|
838
|
-
* @param post - The post object.
|
|
839
|
-
* @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
|
|
840
|
-
* @param post.parameters - Query parameters to be applied to the current query.
|
|
841
|
-
* @param post.body - The parameters to send with the custom request.
|
|
842
|
-
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
843
|
-
*/
|
|
844
|
-
post({ path, parameters, body }, requestOptions) {
|
|
845
|
-
if (!path) {
|
|
846
|
-
throw new Error('Parameter `path` is required when calling `post`.');
|
|
847
|
-
}
|
|
848
|
-
const requestPath = '/1{path}'.replace('{path}', path);
|
|
849
|
-
const headers = {};
|
|
850
|
-
const queryParameters = parameters ? parameters : {};
|
|
851
|
-
const request = {
|
|
852
|
-
method: 'POST',
|
|
853
|
-
path: requestPath,
|
|
854
|
-
queryParameters,
|
|
855
|
-
headers,
|
|
856
|
-
data: body ? body : {},
|
|
857
|
-
};
|
|
858
|
-
return transporter.request(request, requestOptions);
|
|
859
|
-
},
|
|
860
|
-
/**
|
|
861
|
-
* This method allow you to send requests to the Algolia REST API.
|
|
862
|
-
*
|
|
863
|
-
* @summary Send requests to the Algolia REST API.
|
|
864
|
-
* @param put - The put object.
|
|
865
|
-
* @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
|
|
866
|
-
* @param put.parameters - Query parameters to be applied to the current query.
|
|
867
|
-
* @param put.body - The parameters to send with the custom request.
|
|
868
|
-
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
869
|
-
*/
|
|
870
|
-
put({ path, parameters, body }, requestOptions) {
|
|
871
|
-
if (!path) {
|
|
872
|
-
throw new Error('Parameter `path` is required when calling `put`.');
|
|
873
|
-
}
|
|
874
|
-
const requestPath = '/1{path}'.replace('{path}', path);
|
|
875
|
-
const headers = {};
|
|
876
|
-
const queryParameters = parameters ? parameters : {};
|
|
877
|
-
const request = {
|
|
878
|
-
method: 'PUT',
|
|
879
|
-
path: requestPath,
|
|
880
|
-
queryParameters,
|
|
881
|
-
headers,
|
|
882
|
-
data: body ? body : {},
|
|
883
|
-
};
|
|
884
|
-
return transporter.request(request, requestOptions);
|
|
885
|
-
},
|
|
886
|
-
};
|
|
675
|
+
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
676
|
+
const apiClientVersion = '5.0.0-alpha.54';
|
|
677
|
+
function getDefaultHosts(appId) {
|
|
678
|
+
return [
|
|
679
|
+
{
|
|
680
|
+
url: `${appId}-dsn.algolia.net`,
|
|
681
|
+
accept: 'read',
|
|
682
|
+
protocol: 'https',
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
url: `${appId}.algolia.net`,
|
|
686
|
+
accept: 'write',
|
|
687
|
+
protocol: 'https',
|
|
688
|
+
},
|
|
689
|
+
].concat(shuffle([
|
|
690
|
+
{
|
|
691
|
+
url: `${appId}-1.algolianet.com`,
|
|
692
|
+
accept: 'readWrite',
|
|
693
|
+
protocol: 'https',
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
url: `${appId}-2.algolianet.com`,
|
|
697
|
+
accept: 'readWrite',
|
|
698
|
+
protocol: 'https',
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
url: `${appId}-3.algolianet.com`,
|
|
702
|
+
accept: 'readWrite',
|
|
703
|
+
protocol: 'https',
|
|
704
|
+
},
|
|
705
|
+
]));
|
|
706
|
+
}
|
|
707
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
708
|
+
function createRecommendClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, ...options }) {
|
|
709
|
+
const auth = createAuth(appIdOption, apiKeyOption, authMode);
|
|
710
|
+
const transporter = createTransporter({
|
|
711
|
+
hosts: getDefaultHosts(appIdOption),
|
|
712
|
+
...options,
|
|
713
|
+
algoliaAgent: getAlgoliaAgent({
|
|
714
|
+
algoliaAgents,
|
|
715
|
+
client: 'Recommend',
|
|
716
|
+
version: apiClientVersion,
|
|
717
|
+
}),
|
|
718
|
+
baseHeaders: {
|
|
719
|
+
'content-type': 'text/plain',
|
|
720
|
+
...auth.headers(),
|
|
721
|
+
...options.baseHeaders,
|
|
722
|
+
},
|
|
723
|
+
baseQueryParameters: {
|
|
724
|
+
...auth.queryParameters(),
|
|
725
|
+
...options.baseQueryParameters,
|
|
726
|
+
},
|
|
727
|
+
});
|
|
728
|
+
return {
|
|
729
|
+
transporter,
|
|
730
|
+
/**
|
|
731
|
+
* The `appId` currently in use.
|
|
732
|
+
*/
|
|
733
|
+
appId: appIdOption,
|
|
734
|
+
/**
|
|
735
|
+
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
|
|
736
|
+
*/
|
|
737
|
+
clearCache() {
|
|
738
|
+
return Promise.all([
|
|
739
|
+
transporter.requestsCache.clear(),
|
|
740
|
+
transporter.responsesCache.clear(),
|
|
741
|
+
]).then(() => undefined);
|
|
742
|
+
},
|
|
743
|
+
/**
|
|
744
|
+
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
|
|
745
|
+
*/
|
|
746
|
+
get _ua() {
|
|
747
|
+
return transporter.algoliaAgent.value;
|
|
748
|
+
},
|
|
749
|
+
/**
|
|
750
|
+
* Adds a `segment` to the `x-algolia-agent` sent with every requests.
|
|
751
|
+
*
|
|
752
|
+
* @param segment - The algolia agent (user-agent) segment to add.
|
|
753
|
+
* @param version - The version of the agent.
|
|
754
|
+
*/
|
|
755
|
+
addAlgoliaAgent(segment, version) {
|
|
756
|
+
transporter.algoliaAgent.add({ segment, version });
|
|
757
|
+
},
|
|
758
|
+
/**
|
|
759
|
+
* This method allow you to send requests to the Algolia REST API.
|
|
760
|
+
*
|
|
761
|
+
* @summary Send requests to the Algolia REST API.
|
|
762
|
+
* @param del - The del object.
|
|
763
|
+
* @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
|
|
764
|
+
* @param del.parameters - Query parameters to be applied to the current query.
|
|
765
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
766
|
+
*/
|
|
767
|
+
del({ path, parameters }, requestOptions) {
|
|
768
|
+
if (!path) {
|
|
769
|
+
throw new Error('Parameter `path` is required when calling `del`.');
|
|
770
|
+
}
|
|
771
|
+
const requestPath = '/1{path}'.replace('{path}', path);
|
|
772
|
+
const headers = {};
|
|
773
|
+
const queryParameters = parameters ? parameters : {};
|
|
774
|
+
const request = {
|
|
775
|
+
method: 'DELETE',
|
|
776
|
+
path: requestPath,
|
|
777
|
+
queryParameters,
|
|
778
|
+
headers,
|
|
779
|
+
};
|
|
780
|
+
return transporter.request(request, requestOptions);
|
|
781
|
+
},
|
|
782
|
+
/**
|
|
783
|
+
* This method allow you to send requests to the Algolia REST API.
|
|
784
|
+
*
|
|
785
|
+
* @summary Send requests to the Algolia REST API.
|
|
786
|
+
* @param get - The get object.
|
|
787
|
+
* @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
|
|
788
|
+
* @param get.parameters - Query parameters to be applied to the current query.
|
|
789
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
790
|
+
*/
|
|
791
|
+
get({ path, parameters }, requestOptions) {
|
|
792
|
+
if (!path) {
|
|
793
|
+
throw new Error('Parameter `path` is required when calling `get`.');
|
|
794
|
+
}
|
|
795
|
+
const requestPath = '/1{path}'.replace('{path}', path);
|
|
796
|
+
const headers = {};
|
|
797
|
+
const queryParameters = parameters ? parameters : {};
|
|
798
|
+
const request = {
|
|
799
|
+
method: 'GET',
|
|
800
|
+
path: requestPath,
|
|
801
|
+
queryParameters,
|
|
802
|
+
headers,
|
|
803
|
+
};
|
|
804
|
+
return transporter.request(request, requestOptions);
|
|
805
|
+
},
|
|
806
|
+
/**
|
|
807
|
+
* Returns recommendations or trending results, for a specific model and `objectID`.
|
|
808
|
+
*
|
|
809
|
+
* @summary Get results.
|
|
810
|
+
* @param getRecommendationsParams - The getRecommendationsParams object.
|
|
811
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
812
|
+
*/
|
|
813
|
+
getRecommendations(getRecommendationsParams, requestOptions) {
|
|
814
|
+
if (!getRecommendationsParams) {
|
|
815
|
+
throw new Error('Parameter `getRecommendationsParams` is required when calling `getRecommendations`.');
|
|
816
|
+
}
|
|
817
|
+
if (!getRecommendationsParams.requests) {
|
|
818
|
+
throw new Error('Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.');
|
|
819
|
+
}
|
|
820
|
+
const requestPath = '/1/indexes/*/recommendations';
|
|
821
|
+
const headers = {};
|
|
822
|
+
const queryParameters = {};
|
|
823
|
+
const request = {
|
|
824
|
+
method: 'POST',
|
|
825
|
+
path: requestPath,
|
|
826
|
+
queryParameters,
|
|
827
|
+
headers,
|
|
828
|
+
data: getRecommendationsParams,
|
|
829
|
+
useReadTransporter: true,
|
|
830
|
+
cacheable: true,
|
|
831
|
+
};
|
|
832
|
+
return transporter.request(request, requestOptions);
|
|
833
|
+
},
|
|
834
|
+
/**
|
|
835
|
+
* This method allow you to send requests to the Algolia REST API.
|
|
836
|
+
*
|
|
837
|
+
* @summary Send requests to the Algolia REST API.
|
|
838
|
+
* @param post - The post object.
|
|
839
|
+
* @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
|
|
840
|
+
* @param post.parameters - Query parameters to be applied to the current query.
|
|
841
|
+
* @param post.body - The parameters to send with the custom request.
|
|
842
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
843
|
+
*/
|
|
844
|
+
post({ path, parameters, body }, requestOptions) {
|
|
845
|
+
if (!path) {
|
|
846
|
+
throw new Error('Parameter `path` is required when calling `post`.');
|
|
847
|
+
}
|
|
848
|
+
const requestPath = '/1{path}'.replace('{path}', path);
|
|
849
|
+
const headers = {};
|
|
850
|
+
const queryParameters = parameters ? parameters : {};
|
|
851
|
+
const request = {
|
|
852
|
+
method: 'POST',
|
|
853
|
+
path: requestPath,
|
|
854
|
+
queryParameters,
|
|
855
|
+
headers,
|
|
856
|
+
data: body ? body : {},
|
|
857
|
+
};
|
|
858
|
+
return transporter.request(request, requestOptions);
|
|
859
|
+
},
|
|
860
|
+
/**
|
|
861
|
+
* This method allow you to send requests to the Algolia REST API.
|
|
862
|
+
*
|
|
863
|
+
* @summary Send requests to the Algolia REST API.
|
|
864
|
+
* @param put - The put object.
|
|
865
|
+
* @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
|
|
866
|
+
* @param put.parameters - Query parameters to be applied to the current query.
|
|
867
|
+
* @param put.body - The parameters to send with the custom request.
|
|
868
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
869
|
+
*/
|
|
870
|
+
put({ path, parameters, body }, requestOptions) {
|
|
871
|
+
if (!path) {
|
|
872
|
+
throw new Error('Parameter `path` is required when calling `put`.');
|
|
873
|
+
}
|
|
874
|
+
const requestPath = '/1{path}'.replace('{path}', path);
|
|
875
|
+
const headers = {};
|
|
876
|
+
const queryParameters = parameters ? parameters : {};
|
|
877
|
+
const request = {
|
|
878
|
+
method: 'PUT',
|
|
879
|
+
path: requestPath,
|
|
880
|
+
queryParameters,
|
|
881
|
+
headers,
|
|
882
|
+
data: body ? body : {},
|
|
883
|
+
};
|
|
884
|
+
return transporter.request(request, requestOptions);
|
|
885
|
+
},
|
|
886
|
+
};
|
|
887
887
|
}
|
|
888
888
|
|
|
889
|
-
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
890
|
-
function recommendClient(appId, apiKey, options) {
|
|
891
|
-
if (!appId || typeof appId !== 'string') {
|
|
892
|
-
throw new Error('`appId` is missing.');
|
|
893
|
-
}
|
|
894
|
-
if (!apiKey || typeof apiKey !== 'string') {
|
|
895
|
-
throw new Error('`apiKey` is missing.');
|
|
896
|
-
}
|
|
897
|
-
return createRecommendClient({
|
|
898
|
-
appId,
|
|
899
|
-
apiKey,
|
|
900
|
-
timeouts: {
|
|
901
|
-
connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
|
|
902
|
-
read: DEFAULT_READ_TIMEOUT_BROWSER,
|
|
903
|
-
write: DEFAULT_WRITE_TIMEOUT_BROWSER,
|
|
904
|
-
},
|
|
905
|
-
requester: createXhrRequester(),
|
|
906
|
-
algoliaAgents: [{ segment: 'Browser' }],
|
|
907
|
-
authMode: 'WithinQueryParameters',
|
|
908
|
-
responsesCache: createMemoryCache(),
|
|
909
|
-
requestsCache: createMemoryCache({ serializable: false }),
|
|
910
|
-
hostsCache: createFallbackableCache({
|
|
911
|
-
caches: [
|
|
912
|
-
createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }),
|
|
913
|
-
createMemoryCache(),
|
|
914
|
-
],
|
|
915
|
-
}),
|
|
916
|
-
...options,
|
|
917
|
-
});
|
|
889
|
+
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
|
|
890
|
+
function recommendClient(appId, apiKey, options) {
|
|
891
|
+
if (!appId || typeof appId !== 'string') {
|
|
892
|
+
throw new Error('`appId` is missing.');
|
|
893
|
+
}
|
|
894
|
+
if (!apiKey || typeof apiKey !== 'string') {
|
|
895
|
+
throw new Error('`apiKey` is missing.');
|
|
896
|
+
}
|
|
897
|
+
return createRecommendClient({
|
|
898
|
+
appId,
|
|
899
|
+
apiKey,
|
|
900
|
+
timeouts: {
|
|
901
|
+
connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
|
|
902
|
+
read: DEFAULT_READ_TIMEOUT_BROWSER,
|
|
903
|
+
write: DEFAULT_WRITE_TIMEOUT_BROWSER,
|
|
904
|
+
},
|
|
905
|
+
requester: createXhrRequester(),
|
|
906
|
+
algoliaAgents: [{ segment: 'Browser' }],
|
|
907
|
+
authMode: 'WithinQueryParameters',
|
|
908
|
+
responsesCache: createMemoryCache(),
|
|
909
|
+
requestsCache: createMemoryCache({ serializable: false }),
|
|
910
|
+
hostsCache: createFallbackableCache({
|
|
911
|
+
caches: [
|
|
912
|
+
createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }),
|
|
913
|
+
createMemoryCache(),
|
|
914
|
+
],
|
|
915
|
+
}),
|
|
916
|
+
...options,
|
|
917
|
+
});
|
|
918
918
|
}
|
|
919
919
|
|
|
920
920
|
export { apiClientVersion, recommendClient };
|