@algolia/recommend 5.0.0-alpha.11 → 5.0.0-alpha.110
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 +23 -5
- package/dist/builds/browser.d.ts.map +1 -1
- package/dist/builds/node.d.ts +23 -5
- package/dist/builds/node.d.ts.map +1 -1
- package/dist/model/advancedSyntaxFeatures.d.ts +1 -1
- package/dist/model/advancedSyntaxFeatures.d.ts.map +1 -1
- package/dist/model/alternativesAsExact.d.ts +1 -1
- package/dist/model/alternativesAsExact.d.ts.map +1 -1
- package/dist/model/anchoring.d.ts +5 -0
- package/dist/model/anchoring.d.ts.map +1 -0
- package/dist/model/aroundPrecision.d.ts +6 -0
- package/dist/model/aroundPrecision.d.ts.map +1 -0
- package/dist/model/aroundPrecisionFromValueInner.d.ts +14 -0
- package/dist/model/aroundPrecisionFromValueInner.d.ts.map +1 -0
- package/dist/model/aroundRadius.d.ts +5 -5
- package/dist/model/aroundRadius.d.ts.map +1 -1
- package/dist/model/aroundRadiusAll.d.ts +4 -1
- package/dist/model/aroundRadiusAll.d.ts.map +1 -1
- package/dist/model/automaticFacetFilter.d.ts +18 -0
- package/dist/model/automaticFacetFilter.d.ts.map +1 -0
- package/dist/model/automaticFacetFilters.d.ts +6 -0
- package/dist/model/automaticFacetFilters.d.ts.map +1 -0
- package/dist/model/baseRecommendRequest.d.ts +14 -17
- package/dist/model/baseRecommendRequest.d.ts.map +1 -1
- package/dist/model/baseRecommendationsQuery.d.ts +12 -0
- package/dist/model/baseRecommendationsQuery.d.ts.map +1 -0
- package/dist/model/baseRecommendedForYouQuery.d.ts +8 -0
- package/dist/model/baseRecommendedForYouQuery.d.ts.map +1 -0
- package/dist/model/baseRecommendedForYouQueryParameters.d.ts +7 -0
- package/dist/model/baseRecommendedForYouQueryParameters.d.ts.map +1 -0
- package/dist/model/baseSearchParams.d.ts +3 -3
- package/dist/model/baseSearchParams.d.ts.map +1 -1
- package/dist/model/baseSearchParamsWithoutQuery.d.ts +114 -122
- package/dist/model/baseSearchParamsWithoutQuery.d.ts.map +1 -1
- package/dist/model/baseSearchResponse.d.ts +109 -101
- package/dist/model/baseSearchResponse.d.ts.map +1 -1
- package/dist/model/baseTrendingFacetsQuery.d.ts +9 -0
- package/dist/model/baseTrendingFacetsQuery.d.ts.map +1 -0
- package/dist/model/baseTrendingItemsQuery.d.ts +16 -0
- package/dist/model/baseTrendingItemsQuery.d.ts.map +1 -0
- package/dist/model/clientMethodProps.d.ts +127 -60
- package/dist/model/clientMethodProps.d.ts.map +1 -1
- package/dist/model/condition.d.ts +21 -0
- package/dist/model/condition.d.ts.map +1 -0
- package/dist/model/consequence.d.ts +26 -0
- package/dist/model/consequence.d.ts.map +1 -0
- package/dist/model/consequenceHide.d.ts +10 -0
- package/dist/model/consequenceHide.d.ts.map +1 -0
- package/dist/model/consequenceParams.d.ts +5 -0
- package/dist/model/consequenceParams.d.ts.map +1 -0
- package/dist/model/consequenceQuery.d.ts +6 -0
- package/dist/model/consequenceQuery.d.ts.map +1 -0
- package/dist/model/consequenceQueryObject.d.ts +12 -0
- package/dist/model/consequenceQueryObject.d.ts.map +1 -0
- package/dist/model/deletedAtResponse.d.ts +14 -0
- package/dist/model/deletedAtResponse.d.ts.map +1 -0
- package/dist/model/distinct.d.ts +4 -4
- package/dist/model/distinct.d.ts.map +1 -1
- package/dist/model/edit.d.ts +13 -0
- package/dist/model/edit.d.ts.map +1 -0
- package/dist/model/editType.d.ts +5 -0
- package/dist/model/editType.d.ts.map +1 -0
- package/dist/model/errorBase.d.ts +6 -6
- package/dist/model/errorBase.d.ts.map +1 -1
- package/dist/model/exactOnSingleWordQuery.d.ts +4 -4
- package/dist/model/exactOnSingleWordQuery.d.ts.map +1 -1
- package/dist/model/exhaustive.d.ts +26 -0
- package/dist/model/exhaustive.d.ts.map +1 -0
- package/dist/model/facetFilters.d.ts +5 -5
- package/dist/model/facetFilters.d.ts.map +1 -1
- package/dist/model/facetOrdering.d.ts +12 -12
- package/dist/model/facetOrdering.d.ts.map +1 -1
- package/dist/model/facets.d.ts +9 -9
- package/dist/model/facets.d.ts.map +1 -1
- package/dist/model/facetsStats.d.ts +18 -18
- package/dist/model/facetsStats.d.ts.map +1 -1
- package/dist/model/getRecommendTaskResponse.d.ts +5 -0
- package/dist/model/getRecommendTaskResponse.d.ts.map +1 -0
- package/dist/model/getRecommendationsParams.d.ts +10 -10
- package/dist/model/getRecommendationsParams.d.ts.map +1 -1
- package/dist/model/getRecommendationsResponse.d.ts +4 -4
- package/dist/model/getRecommendationsResponse.d.ts.map +1 -1
- package/dist/model/highlightResult.d.ts +2 -2
- package/dist/model/highlightResult.d.ts.map +1 -1
- package/dist/model/highlightResultOption.d.ts +19 -19
- package/dist/model/highlightResultOption.d.ts.map +1 -1
- package/dist/model/ignorePlurals.d.ts +5 -4
- package/dist/model/ignorePlurals.d.ts.map +1 -1
- package/dist/model/index.d.ts +95 -53
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/indexSettingsAsSearchParams.d.ts +159 -160
- package/dist/model/indexSettingsAsSearchParams.d.ts.map +1 -1
- package/dist/model/matchLevel.d.ts +4 -4
- package/dist/model/matchLevel.d.ts.map +1 -1
- package/dist/model/matchedGeoLocation.d.ts +14 -14
- package/dist/model/matchedGeoLocation.d.ts.map +1 -1
- package/dist/model/mixedSearchFilters.d.ts +1 -1
- package/dist/model/mixedSearchFilters.d.ts.map +1 -1
- package/dist/model/mode.d.ts +5 -0
- package/dist/model/mode.d.ts.map +1 -0
- package/dist/model/numericFilters.d.ts +5 -5
- package/dist/model/numericFilters.d.ts.map +1 -1
- package/dist/model/optionalFilters.d.ts +5 -5
- package/dist/model/optionalFilters.d.ts.map +1 -1
- package/dist/model/params.d.ts +13 -0
- package/dist/model/params.d.ts.map +1 -0
- package/dist/model/personalization.d.ts +14 -14
- package/dist/model/personalization.d.ts.map +1 -1
- package/dist/model/promote.d.ts +4 -0
- package/dist/model/promote.d.ts.map +1 -0
- package/dist/model/promoteObjectID.d.ts +14 -0
- package/dist/model/promoteObjectID.d.ts.map +1 -0
- package/dist/model/promoteObjectIDs.d.ts +14 -0
- package/dist/model/promoteObjectIDs.d.ts.map +1 -0
- package/dist/model/queryType.d.ts +4 -4
- package/dist/model/queryType.d.ts.map +1 -1
- package/dist/model/rankingInfo.d.ts +53 -50
- package/dist/model/rankingInfo.d.ts.map +1 -1
- package/dist/model/reRankingApplyFilter.d.ts +5 -5
- package/dist/model/reRankingApplyFilter.d.ts.map +1 -1
- package/dist/model/recommendHit.d.ts +26 -26
- package/dist/model/recommendHit.d.ts.map +1 -1
- package/dist/model/recommendModels.d.ts +2 -0
- package/dist/model/recommendModels.d.ts.map +1 -0
- package/dist/model/recommendationModels.d.ts +4 -4
- package/dist/model/recommendationModels.d.ts.map +1 -1
- package/dist/model/recommendationsHit.d.ts +4 -0
- package/dist/model/recommendationsHit.d.ts.map +1 -0
- package/dist/model/recommendationsHits.d.ts +13 -0
- package/dist/model/recommendationsHits.d.ts.map +1 -0
- package/dist/model/recommendationsQuery.d.ts +4 -0
- package/dist/model/recommendationsQuery.d.ts.map +1 -0
- package/dist/model/recommendationsRequest.d.ts +5 -3
- package/dist/model/recommendationsRequest.d.ts.map +1 -1
- package/dist/model/recommendationsResults.d.ts +4 -0
- package/dist/model/recommendationsResults.d.ts.map +1 -0
- package/dist/model/recommendedForYouModel.d.ts +5 -0
- package/dist/model/recommendedForYouModel.d.ts.map +1 -0
- package/dist/model/recommendedForYouQuery.d.ts +4 -0
- package/dist/model/recommendedForYouQuery.d.ts.map +1 -0
- package/dist/model/recommendedForYouQueryParameters.d.ts +4 -0
- package/dist/model/recommendedForYouQueryParameters.d.ts.map +1 -0
- package/dist/model/redirect.d.ts +8 -0
- package/dist/model/redirect.d.ts.map +1 -0
- package/dist/model/redirectRuleIndexMetadata.d.ts +21 -0
- package/dist/model/redirectRuleIndexMetadata.d.ts.map +1 -0
- package/dist/model/redirectRuleIndexMetadataData.d.ts +7 -0
- package/dist/model/redirectRuleIndexMetadataData.d.ts.map +1 -0
- package/dist/model/removeStopWords.d.ts +5 -4
- package/dist/model/removeStopWords.d.ts.map +1 -1
- package/dist/model/removeWordsIfNoResults.d.ts +4 -4
- package/dist/model/removeWordsIfNoResults.d.ts.map +1 -1
- package/dist/model/renderingContent.d.ts +7 -7
- package/dist/model/renderingContent.d.ts.map +1 -1
- package/dist/model/ruleResponse.d.ts +27 -0
- package/dist/model/ruleResponse.d.ts.map +1 -0
- package/dist/model/ruleResponseMetadata.d.ts +7 -0
- package/dist/model/ruleResponseMetadata.d.ts.map +1 -0
- package/dist/model/searchParamsObject.d.ts +3 -3
- package/dist/model/searchParamsObject.d.ts.map +1 -1
- package/dist/model/searchParamsQuery.d.ts +6 -6
- package/dist/model/searchParamsQuery.d.ts.map +1 -1
- package/dist/model/searchRecommendRulesParams.d.ts +26 -0
- package/dist/model/searchRecommendRulesParams.d.ts.map +1 -0
- package/dist/model/searchRecommendRulesResponse.d.ts +20 -0
- package/dist/model/searchRecommendRulesResponse.d.ts.map +1 -0
- package/dist/model/semanticSearch.d.ts +10 -0
- package/dist/model/semanticSearch.d.ts.map +1 -0
- package/dist/model/snippetResult.d.ts +2 -2
- package/dist/model/snippetResult.d.ts.map +1 -1
- package/dist/model/snippetResultOption.d.ts +11 -11
- package/dist/model/snippetResultOption.d.ts.map +1 -1
- package/dist/model/sortRemainingBy.d.ts +4 -4
- package/dist/model/sortRemainingBy.d.ts.map +1 -1
- package/dist/model/supportedLanguage.d.ts +5 -0
- package/dist/model/supportedLanguage.d.ts.map +1 -0
- package/dist/model/tagFilters.d.ts +5 -5
- package/dist/model/tagFilters.d.ts.map +1 -1
- package/dist/model/taskStatus.d.ts +5 -0
- package/dist/model/taskStatus.d.ts.map +1 -0
- package/dist/model/trendingFacetHit.d.ts +18 -0
- package/dist/model/trendingFacetHit.d.ts.map +1 -0
- package/dist/model/trendingFacetsModel.d.ts +5 -0
- package/dist/model/trendingFacetsModel.d.ts.map +1 -0
- package/dist/model/trendingFacetsQuery.d.ts +4 -0
- package/dist/model/trendingFacetsQuery.d.ts.map +1 -0
- package/dist/model/trendingItemsModel.d.ts +5 -0
- package/dist/model/trendingItemsModel.d.ts.map +1 -0
- package/dist/model/trendingItemsQuery.d.ts +4 -0
- package/dist/model/trendingItemsQuery.d.ts.map +1 -0
- package/dist/model/typoTolerance.d.ts +5 -5
- package/dist/model/typoTolerance.d.ts.map +1 -1
- package/dist/model/typoToleranceEnum.d.ts +4 -1
- package/dist/model/typoToleranceEnum.d.ts.map +1 -1
- package/dist/model/value.d.ts +8 -8
- package/dist/model/value.d.ts.map +1 -1
- package/dist/recommend.cjs +390 -0
- package/dist/recommend.esm.browser.js +589 -475
- package/dist/recommend.esm.node.js +379 -235
- package/dist/recommend.umd.js +2 -2
- package/dist/src/recommendClient.d.ts +131 -81
- package/dist/src/recommendClient.d.ts.map +1 -1
- package/index.js +1 -1
- package/model/advancedSyntaxFeatures.ts +1 -1
- package/model/alternativesAsExact.ts +1 -1
- package/model/anchoring.ts +6 -0
- package/model/aroundPrecision.ts +8 -0
- package/model/aroundPrecisionFromValueInner.ts +16 -0
- package/model/aroundRadius.ts +2 -2
- package/model/aroundRadiusAll.ts +4 -1
- package/model/automaticFacetFilter.ts +21 -0
- package/model/automaticFacetFilters.ts +8 -0
- package/model/baseRecommendRequest.ts +5 -11
- package/model/baseRecommendationsQuery.ts +17 -0
- package/model/baseRecommendedForYouQuery.ts +12 -0
- package/model/baseRecommendedForYouQueryParameters.ts +8 -0
- package/model/baseSearchParams.ts +1 -1
- package/model/baseSearchParamsWithoutQuery.ts +36 -46
- package/model/baseSearchResponse.ts +42 -31
- package/model/baseTrendingFacetsQuery.ts +12 -0
- package/model/baseTrendingItemsQuery.ts +22 -0
- package/model/clientMethodProps.ts +91 -19
- package/model/condition.ts +27 -0
- package/model/consequence.ts +32 -0
- package/model/consequenceHide.ts +11 -0
- package/model/consequenceParams.ts +9 -0
- package/model/consequenceQuery.ts +8 -0
- package/model/consequenceQueryObject.ts +15 -0
- package/model/deletedAtResponse.ts +16 -0
- package/model/distinct.ts +2 -2
- package/model/edit.ts +17 -0
- package/model/editType.ts +6 -0
- package/model/errorBase.ts +1 -1
- package/model/exactOnSingleWordQuery.ts +2 -2
- package/model/exhaustive.ts +31 -0
- package/model/facetFilters.ts +2 -2
- package/model/facetOrdering.ts +3 -3
- package/model/facets.ts +3 -3
- package/model/facetsStats.ts +5 -5
- package/model/getRecommendTaskResponse.ts +7 -0
- package/model/getRecommendationsParams.ts +3 -3
- package/model/getRecommendationsResponse.ts +3 -3
- package/model/highlightResult.ts +5 -2
- package/model/highlightResultOption.ts +4 -4
- package/model/ignorePlurals.ts +5 -3
- package/model/index.ts +50 -8
- package/model/indexSettingsAsSearchParams.ts +54 -54
- package/model/matchLevel.ts +2 -2
- package/model/matchedGeoLocation.ts +1 -1
- package/model/mixedSearchFilters.ts +1 -1
- package/model/mode.ts +6 -0
- package/model/numericFilters.ts +2 -2
- package/model/optionalFilters.ts +2 -2
- package/model/params.ts +18 -0
- package/model/personalization.ts +1 -1
- package/model/promote.ts +6 -0
- package/model/promoteObjectID.ts +16 -0
- package/model/promoteObjectIDs.ts +16 -0
- package/model/queryType.ts +2 -2
- package/model/rankingInfo.ts +11 -8
- package/model/reRankingApplyFilter.ts +2 -2
- package/model/recommendHit.ts +6 -6
- package/model/recommendModels.ts +7 -0
- package/model/recommendationModels.ts +2 -2
- package/model/recommendationsHit.ts +6 -0
- package/model/recommendationsHits.ts +17 -0
- package/model/recommendationsQuery.ts +7 -0
- package/model/recommendationsRequest.ts +10 -4
- package/model/recommendationsResults.ts +6 -0
- package/model/recommendedForYouModel.ts +6 -0
- package/model/recommendedForYouQuery.ts +7 -0
- package/model/recommendedForYouQueryParameters.ts +7 -0
- package/model/redirect.ts +10 -0
- package/model/redirectRuleIndexMetadata.ts +27 -0
- package/model/redirectRuleIndexMetadataData.ts +8 -0
- package/model/removeStopWords.ts +5 -3
- package/model/removeWordsIfNoResults.ts +2 -2
- package/model/renderingContent.ts +2 -2
- package/model/ruleResponse.ts +34 -0
- package/model/ruleResponseMetadata.ts +8 -0
- package/model/searchParamsObject.ts +1 -1
- package/model/searchParamsQuery.ts +2 -2
- package/model/searchRecommendRulesParams.ts +31 -0
- package/model/searchRecommendRulesResponse.ts +25 -0
- package/model/semanticSearch.ts +11 -0
- package/model/snippetResult.ts +5 -2
- package/model/snippetResultOption.ts +3 -3
- package/model/sortRemainingBy.ts +2 -2
- package/model/supportedLanguage.ts +74 -0
- package/model/tagFilters.ts +2 -2
- package/model/taskStatus.ts +6 -0
- package/model/trendingFacetHit.ts +21 -0
- package/model/trendingFacetsModel.ts +6 -0
- package/model/trendingFacetsQuery.ts +7 -0
- package/model/trendingItemsModel.ts +6 -0
- package/model/trendingItemsQuery.ts +6 -0
- package/model/typoTolerance.ts +2 -2
- package/model/typoToleranceEnum.ts +4 -1
- package/model/value.ts +2 -2
- package/package.json +10 -9
- package/dist/model/baseRecommendationRequest.d.ts +0 -9
- package/dist/model/baseRecommendationRequest.d.ts.map +0 -1
- package/dist/model/baseTrendingRequest.d.ts +0 -13
- package/dist/model/baseTrendingRequest.d.ts.map +0 -1
- package/dist/model/recommendHits.d.ts +0 -5
- package/dist/model/recommendHits.d.ts.map +0 -1
- package/dist/model/recommendationRequest.d.ts +0 -4
- package/dist/model/recommendationRequest.d.ts.map +0 -1
- package/dist/model/recommendationsResponse.d.ts +0 -4
- package/dist/model/recommendationsResponse.d.ts.map +0 -1
- package/dist/model/trendingModels.d.ts +0 -5
- package/dist/model/trendingModels.d.ts.map +0 -1
- package/dist/model/trendingRequest.d.ts +0 -4
- package/dist/model/trendingRequest.d.ts.map +0 -1
- package/dist/recommend.cjs.js +0 -248
- package/model/baseRecommendationRequest.ts +0 -12
- package/model/baseTrendingRequest.ts +0 -17
- package/model/recommendHits.ts +0 -7
- package/model/recommendationRequest.ts +0 -7
- package/model/recommendationsResponse.ts +0 -6
- package/model/trendingModels.ts +0 -6
- package/model/trendingRequest.ts +0 -6
|
@@ -7,53 +7,69 @@ function createAuth(appId, apiKey, authMode = 'WithinHeaders') {
|
|
|
7
7
|
headers() {
|
|
8
8
|
return authMode === 'WithinHeaders' ? credentials : {};
|
|
9
9
|
},
|
|
10
|
-
|
|
11
10
|
queryParameters() {
|
|
12
11
|
return authMode === 'WithinQueryParameters' ? credentials : {};
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
};
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
function createBrowserLocalStorageCache(options) {
|
|
19
|
-
let storage;
|
|
20
|
-
|
|
17
|
+
let storage;
|
|
18
|
+
// We've changed the namespace to avoid conflicts with v4, as this version is a huge breaking change
|
|
21
19
|
const namespaceKey = `algolia-client-js-${options.key}`;
|
|
22
|
-
|
|
23
20
|
function getStorage() {
|
|
24
21
|
if (storage === undefined) {
|
|
25
22
|
storage = options.localStorage || window.localStorage;
|
|
26
23
|
}
|
|
27
|
-
|
|
28
24
|
return storage;
|
|
29
25
|
}
|
|
30
|
-
|
|
31
26
|
function getNamespace() {
|
|
32
27
|
return JSON.parse(getStorage().getItem(namespaceKey) || '{}');
|
|
33
28
|
}
|
|
34
|
-
|
|
29
|
+
function setNamespace(namespace) {
|
|
30
|
+
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
|
31
|
+
}
|
|
32
|
+
function removeOutdatedCacheItems() {
|
|
33
|
+
const timeToLive = options.timeToLive ? options.timeToLive * 1000 : null;
|
|
34
|
+
const namespace = getNamespace();
|
|
35
|
+
const filteredNamespaceWithoutOldFormattedCacheItems = Object.fromEntries(Object.entries(namespace).filter(([, cacheItem]) => {
|
|
36
|
+
return cacheItem.timestamp !== undefined;
|
|
37
|
+
}));
|
|
38
|
+
setNamespace(filteredNamespaceWithoutOldFormattedCacheItems);
|
|
39
|
+
if (!timeToLive) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const filteredNamespaceWithoutExpiredItems = Object.fromEntries(Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(([, cacheItem]) => {
|
|
43
|
+
const currentTimestamp = new Date().getTime();
|
|
44
|
+
const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;
|
|
45
|
+
return !isExpired;
|
|
46
|
+
}));
|
|
47
|
+
setNamespace(filteredNamespaceWithoutExpiredItems);
|
|
48
|
+
}
|
|
35
49
|
return {
|
|
36
50
|
get(key, defaultValue, events = {
|
|
37
51
|
miss: () => Promise.resolve()
|
|
38
52
|
}) {
|
|
39
53
|
return Promise.resolve().then(() => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
removeOutdatedCacheItems();
|
|
55
|
+
return getNamespace()[JSON.stringify(key)];
|
|
56
|
+
}).then(value => {
|
|
57
|
+
return Promise.all([value ? value.value : defaultValue(), value !== undefined]);
|
|
43
58
|
}).then(([value, exists]) => {
|
|
44
59
|
return Promise.all([value, exists || events.miss(value)]);
|
|
45
60
|
}).then(([value]) => value);
|
|
46
61
|
},
|
|
47
|
-
|
|
48
62
|
set(key, value) {
|
|
49
63
|
return Promise.resolve().then(() => {
|
|
50
64
|
const namespace = getNamespace();
|
|
51
|
-
namespace[JSON.stringify(key)] =
|
|
65
|
+
namespace[JSON.stringify(key)] = {
|
|
66
|
+
timestamp: new Date().getTime(),
|
|
67
|
+
value
|
|
68
|
+
};
|
|
52
69
|
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
|
53
70
|
return value;
|
|
54
71
|
});
|
|
55
72
|
},
|
|
56
|
-
|
|
57
73
|
delete(key) {
|
|
58
74
|
return Promise.resolve().then(() => {
|
|
59
75
|
const namespace = getNamespace();
|
|
@@ -61,13 +77,11 @@ function createBrowserLocalStorageCache(options) {
|
|
|
61
77
|
getStorage().setItem(namespaceKey, JSON.stringify(namespace));
|
|
62
78
|
});
|
|
63
79
|
},
|
|
64
|
-
|
|
65
80
|
clear() {
|
|
66
81
|
return Promise.resolve().then(() => {
|
|
67
82
|
getStorage().removeItem(namespaceKey);
|
|
68
83
|
});
|
|
69
84
|
}
|
|
70
|
-
|
|
71
85
|
};
|
|
72
86
|
}
|
|
73
87
|
|
|
@@ -79,30 +93,24 @@ function createNullCache() {
|
|
|
79
93
|
const value = defaultValue();
|
|
80
94
|
return value.then(result => Promise.all([result, events.miss(result)])).then(([result]) => result);
|
|
81
95
|
},
|
|
82
|
-
|
|
83
96
|
set(_key, value) {
|
|
84
97
|
return Promise.resolve(value);
|
|
85
98
|
},
|
|
86
|
-
|
|
87
99
|
delete(_key) {
|
|
88
100
|
return Promise.resolve();
|
|
89
101
|
},
|
|
90
|
-
|
|
91
102
|
clear() {
|
|
92
103
|
return Promise.resolve();
|
|
93
104
|
}
|
|
94
|
-
|
|
95
105
|
};
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
function createFallbackableCache(options) {
|
|
99
109
|
const caches = [...options.caches];
|
|
100
110
|
const current = caches.shift();
|
|
101
|
-
|
|
102
111
|
if (current === undefined) {
|
|
103
112
|
return createNullCache();
|
|
104
113
|
}
|
|
105
|
-
|
|
106
114
|
return {
|
|
107
115
|
get(key, defaultValue, events = {
|
|
108
116
|
miss: () => Promise.resolve()
|
|
@@ -113,7 +121,6 @@ function createFallbackableCache(options) {
|
|
|
113
121
|
}).get(key, defaultValue, events);
|
|
114
122
|
});
|
|
115
123
|
},
|
|
116
|
-
|
|
117
124
|
set(key, value) {
|
|
118
125
|
return current.set(key, value).catch(() => {
|
|
119
126
|
return createFallbackableCache({
|
|
@@ -121,7 +128,6 @@ function createFallbackableCache(options) {
|
|
|
121
128
|
}).set(key, value);
|
|
122
129
|
});
|
|
123
130
|
},
|
|
124
|
-
|
|
125
131
|
delete(key) {
|
|
126
132
|
return current.delete(key).catch(() => {
|
|
127
133
|
return createFallbackableCache({
|
|
@@ -129,7 +135,6 @@ function createFallbackableCache(options) {
|
|
|
129
135
|
}).delete(key);
|
|
130
136
|
});
|
|
131
137
|
},
|
|
132
|
-
|
|
133
138
|
clear() {
|
|
134
139
|
return current.clear().catch(() => {
|
|
135
140
|
return createFallbackableCache({
|
|
@@ -137,7 +142,6 @@ function createFallbackableCache(options) {
|
|
|
137
142
|
}).clear();
|
|
138
143
|
});
|
|
139
144
|
}
|
|
140
|
-
|
|
141
145
|
};
|
|
142
146
|
}
|
|
143
147
|
|
|
@@ -150,30 +154,24 @@ function createMemoryCache(options = {
|
|
|
150
154
|
miss: () => Promise.resolve()
|
|
151
155
|
}) {
|
|
152
156
|
const keyAsString = JSON.stringify(key);
|
|
153
|
-
|
|
154
157
|
if (keyAsString in cache) {
|
|
155
158
|
return Promise.resolve(options.serializable ? JSON.parse(cache[keyAsString]) : cache[keyAsString]);
|
|
156
159
|
}
|
|
157
|
-
|
|
158
160
|
const promise = defaultValue();
|
|
159
161
|
return promise.then(value => events.miss(value)).then(() => promise);
|
|
160
162
|
},
|
|
161
|
-
|
|
162
163
|
set(key, value) {
|
|
163
164
|
cache[JSON.stringify(key)] = options.serializable ? JSON.stringify(value) : value;
|
|
164
165
|
return Promise.resolve(value);
|
|
165
166
|
},
|
|
166
|
-
|
|
167
167
|
delete(key) {
|
|
168
168
|
delete cache[JSON.stringify(key)];
|
|
169
169
|
return Promise.resolve();
|
|
170
170
|
},
|
|
171
|
-
|
|
172
171
|
clear() {
|
|
173
172
|
cache = {};
|
|
174
173
|
return Promise.resolve();
|
|
175
174
|
}
|
|
176
|
-
|
|
177
175
|
};
|
|
178
176
|
}
|
|
179
177
|
|
|
@@ -182,16 +180,14 @@ function createMemoryCache(options = {
|
|
|
182
180
|
const EXPIRATION_DELAY = 2 * 60 * 1000;
|
|
183
181
|
function createStatefulHost(host, status = 'up') {
|
|
184
182
|
const lastUpdate = Date.now();
|
|
185
|
-
|
|
186
183
|
function isUp() {
|
|
187
184
|
return status === 'up' || Date.now() - lastUpdate > EXPIRATION_DELAY;
|
|
188
185
|
}
|
|
189
|
-
|
|
190
186
|
function isTimedOut() {
|
|
191
187
|
return status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY;
|
|
192
188
|
}
|
|
193
|
-
|
|
194
|
-
|
|
189
|
+
return {
|
|
190
|
+
...host,
|
|
195
191
|
status,
|
|
196
192
|
lastUpdate,
|
|
197
193
|
isUp,
|
|
@@ -199,7 +195,22 @@ function createStatefulHost(host, status = 'up') {
|
|
|
199
195
|
};
|
|
200
196
|
}
|
|
201
197
|
|
|
198
|
+
function _toPrimitive(t, r) {
|
|
199
|
+
if ("object" != typeof t || !t) return t;
|
|
200
|
+
var e = t[Symbol.toPrimitive];
|
|
201
|
+
if (void 0 !== e) {
|
|
202
|
+
var i = e.call(t, r || "default");
|
|
203
|
+
if ("object" != typeof i) return i;
|
|
204
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
205
|
+
}
|
|
206
|
+
return ("string" === r ? String : Number)(t);
|
|
207
|
+
}
|
|
208
|
+
function _toPropertyKey(t) {
|
|
209
|
+
var i = _toPrimitive(t, "string");
|
|
210
|
+
return "symbol" == typeof i ? i : i + "";
|
|
211
|
+
}
|
|
202
212
|
function _defineProperty(obj, key, value) {
|
|
213
|
+
key = _toPropertyKey(key);
|
|
203
214
|
if (key in obj) {
|
|
204
215
|
Object.defineProperty(obj, key, {
|
|
205
216
|
value: value,
|
|
@@ -210,92 +221,82 @@ function _defineProperty(obj, key, value) {
|
|
|
210
221
|
} else {
|
|
211
222
|
obj[key] = value;
|
|
212
223
|
}
|
|
213
|
-
|
|
214
224
|
return obj;
|
|
215
225
|
}
|
|
216
226
|
|
|
217
227
|
class AlgoliaError extends Error {
|
|
218
228
|
constructor(message, name) {
|
|
219
229
|
super(message);
|
|
220
|
-
|
|
221
230
|
_defineProperty(this, "name", 'AlgoliaError');
|
|
222
|
-
|
|
223
231
|
if (name) {
|
|
224
232
|
this.name = name;
|
|
225
233
|
}
|
|
226
234
|
}
|
|
227
|
-
|
|
228
235
|
}
|
|
229
236
|
class ErrorWithStackTrace extends AlgoliaError {
|
|
230
237
|
constructor(message, stackTrace, name) {
|
|
231
|
-
super(message, name);
|
|
232
|
-
|
|
238
|
+
super(message, name);
|
|
239
|
+
// the array and object should be frozen to reflect the stackTrace at the time of the error
|
|
233
240
|
_defineProperty(this, "stackTrace", void 0);
|
|
234
|
-
|
|
235
241
|
this.stackTrace = stackTrace;
|
|
236
242
|
}
|
|
237
|
-
|
|
238
243
|
}
|
|
239
244
|
class RetryError extends ErrorWithStackTrace {
|
|
240
245
|
constructor(stackTrace) {
|
|
241
|
-
super('Unreachable hosts - your application id may be incorrect. If the error persists,
|
|
246
|
+
super('Unreachable hosts - your application id may be incorrect. If the error persists, please create a ticket at https://support.algolia.com/ sharing steps we can use to reproduce the issue.', stackTrace, 'RetryError');
|
|
242
247
|
}
|
|
243
|
-
|
|
244
248
|
}
|
|
245
249
|
class ApiError extends ErrorWithStackTrace {
|
|
246
|
-
constructor(message, status, stackTrace) {
|
|
247
|
-
super(message, stackTrace,
|
|
248
|
-
|
|
250
|
+
constructor(message, status, stackTrace, name = 'ApiError') {
|
|
251
|
+
super(message, stackTrace, name);
|
|
249
252
|
_defineProperty(this, "status", void 0);
|
|
250
|
-
|
|
251
253
|
this.status = status;
|
|
252
254
|
}
|
|
253
|
-
|
|
254
255
|
}
|
|
255
256
|
class DeserializationError extends AlgoliaError {
|
|
256
257
|
constructor(message, response) {
|
|
257
258
|
super(message, 'DeserializationError');
|
|
258
|
-
|
|
259
259
|
_defineProperty(this, "response", void 0);
|
|
260
|
-
|
|
261
260
|
this.response = response;
|
|
262
261
|
}
|
|
263
|
-
|
|
262
|
+
}
|
|
263
|
+
// DetailedApiError is only used by the ingestion client to return more informative error, other clients will use ApiClient.
|
|
264
|
+
class DetailedApiError extends ApiError {
|
|
265
|
+
constructor(message, status, error, stackTrace) {
|
|
266
|
+
super(message, status, stackTrace, 'DetailedApiError');
|
|
267
|
+
_defineProperty(this, "error", void 0);
|
|
268
|
+
this.error = error;
|
|
269
|
+
}
|
|
264
270
|
}
|
|
265
271
|
|
|
266
272
|
function shuffle(array) {
|
|
267
273
|
const shuffledArray = array;
|
|
268
|
-
|
|
269
274
|
for (let c = array.length - 1; c > 0; c--) {
|
|
270
275
|
const b = Math.floor(Math.random() * (c + 1));
|
|
271
276
|
const a = array[c];
|
|
272
277
|
shuffledArray[c] = array[b];
|
|
273
278
|
shuffledArray[b] = a;
|
|
274
279
|
}
|
|
275
|
-
|
|
276
280
|
return shuffledArray;
|
|
277
281
|
}
|
|
278
282
|
function serializeUrl(host, path, queryParameters) {
|
|
279
283
|
const queryParametersAsString = serializeQueryParameters(queryParameters);
|
|
280
|
-
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.
|
|
281
|
-
|
|
284
|
+
let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${path.charAt(0) === '/' ? path.substring(1) : path}`;
|
|
282
285
|
if (queryParametersAsString.length) {
|
|
283
286
|
url += `?${queryParametersAsString}`;
|
|
284
287
|
}
|
|
285
|
-
|
|
286
288
|
return url;
|
|
287
289
|
}
|
|
288
290
|
function serializeQueryParameters(parameters) {
|
|
289
291
|
const isObjectOrArray = value => Object.prototype.toString.call(value) === '[object Object]' || Object.prototype.toString.call(value) === '[object Array]';
|
|
290
|
-
|
|
291
|
-
return Object.keys(parameters).map(key => `${key}=${isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]}`).join('&');
|
|
292
|
+
return Object.keys(parameters).map(key => `${key}=${encodeURIComponent(isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]).replaceAll('+', '%20')}`).join('&');
|
|
292
293
|
}
|
|
293
294
|
function serializeData(request, requestOptions) {
|
|
294
295
|
if (request.method === 'GET' || request.data === undefined && requestOptions.data === undefined) {
|
|
295
296
|
return undefined;
|
|
296
297
|
}
|
|
297
|
-
|
|
298
|
-
|
|
298
|
+
const data = Array.isArray(request.data) ? request.data : {
|
|
299
|
+
...request.data,
|
|
299
300
|
...requestOptions.data
|
|
300
301
|
};
|
|
301
302
|
return JSON.stringify(data);
|
|
@@ -325,14 +326,16 @@ function deserializeFailure({
|
|
|
325
326
|
content,
|
|
326
327
|
status
|
|
327
328
|
}, stackFrame) {
|
|
328
|
-
let message = content;
|
|
329
|
-
|
|
330
329
|
try {
|
|
331
|
-
|
|
332
|
-
|
|
330
|
+
const parsed = JSON.parse(content);
|
|
331
|
+
if ('error' in parsed) {
|
|
332
|
+
return new DetailedApiError(parsed.message, status, parsed.error, stackFrame);
|
|
333
|
+
}
|
|
334
|
+
return new ApiError(parsed.message, status, stackFrame);
|
|
335
|
+
} catch (e) {
|
|
336
|
+
// ..
|
|
333
337
|
}
|
|
334
|
-
|
|
335
|
-
return new ApiError(message, status, stackFrame);
|
|
338
|
+
return new ApiError(content, status, stackFrame);
|
|
336
339
|
}
|
|
337
340
|
|
|
338
341
|
function isNetworkError({
|
|
@@ -363,9 +366,12 @@ function stackFrameWithoutCredentials(stackFrame) {
|
|
|
363
366
|
const modifiedHeaders = stackFrame.request.headers['x-algolia-api-key'] ? {
|
|
364
367
|
'x-algolia-api-key': '*****'
|
|
365
368
|
} : {};
|
|
366
|
-
return {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
+
return {
|
|
370
|
+
...stackFrame,
|
|
371
|
+
request: {
|
|
372
|
+
...stackFrame.request,
|
|
373
|
+
headers: {
|
|
374
|
+
...stackFrame.request.headers,
|
|
369
375
|
...modifiedHeaders
|
|
370
376
|
}
|
|
371
377
|
}
|
|
@@ -390,53 +396,49 @@ function createTransporter({
|
|
|
390
396
|
});
|
|
391
397
|
}));
|
|
392
398
|
const hostsUp = statefulHosts.filter(host => host.isUp());
|
|
393
|
-
const hostsTimedOut = statefulHosts.filter(host => host.isTimedOut());
|
|
394
|
-
|
|
399
|
+
const hostsTimedOut = statefulHosts.filter(host => host.isTimedOut());
|
|
400
|
+
// Note, we put the hosts that previously timed out on the end of the list.
|
|
395
401
|
const hostsAvailable = [...hostsUp, ...hostsTimedOut];
|
|
396
402
|
const compatibleHostsAvailable = hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;
|
|
397
403
|
return {
|
|
398
404
|
hosts: compatibleHostsAvailable,
|
|
399
|
-
|
|
400
405
|
getTimeout(timeoutsCount, baseTimeout) {
|
|
401
|
-
/**
|
|
402
|
-
* Imagine that you have 4 hosts, if timeouts will increase
|
|
403
|
-
* on the following way: 1 (timed out) > 4 (timed out) > 5 (200).
|
|
404
|
-
*
|
|
405
|
-
* Note that, the very next request, we start from the previous timeout.
|
|
406
|
-
*
|
|
407
|
-
* 5 (timed out) > 6 (timed out) > 7 ...
|
|
408
|
-
*
|
|
409
|
-
* This strategy may need to be reviewed, but is the strategy on the our
|
|
410
|
-
* current v3 version.
|
|
406
|
+
/**
|
|
407
|
+
* Imagine that you have 4 hosts, if timeouts will increase
|
|
408
|
+
* on the following way: 1 (timed out) > 4 (timed out) > 5 (200).
|
|
409
|
+
*
|
|
410
|
+
* Note that, the very next request, we start from the previous timeout.
|
|
411
|
+
*
|
|
412
|
+
* 5 (timed out) > 6 (timed out) > 7 ...
|
|
413
|
+
*
|
|
414
|
+
* This strategy may need to be reviewed, but is the strategy on the our
|
|
415
|
+
* current v3 version.
|
|
411
416
|
*/
|
|
412
417
|
const timeoutMultiplier = hostsTimedOut.length === 0 && timeoutsCount === 0 ? 1 : hostsTimedOut.length + 3 + timeoutsCount;
|
|
413
418
|
return timeoutMultiplier * baseTimeout;
|
|
414
419
|
}
|
|
415
|
-
|
|
416
420
|
};
|
|
417
421
|
}
|
|
418
|
-
|
|
419
422
|
async function retryableRequest(request, requestOptions, isRead = true) {
|
|
420
423
|
const stackTrace = [];
|
|
421
|
-
/**
|
|
422
|
-
* First we prepare the payload that do not depend from hosts.
|
|
424
|
+
/**
|
|
425
|
+
* First we prepare the payload that do not depend from hosts.
|
|
423
426
|
*/
|
|
424
|
-
|
|
425
427
|
const data = serializeData(request, requestOptions);
|
|
426
|
-
const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);
|
|
427
|
-
|
|
428
|
-
const dataQueryParameters = request.method === 'GET' ? {
|
|
428
|
+
const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);
|
|
429
|
+
// On `GET`, the data is proxied to query parameters.
|
|
430
|
+
const dataQueryParameters = request.method === 'GET' ? {
|
|
431
|
+
...request.data,
|
|
429
432
|
...requestOptions.data
|
|
430
433
|
} : {};
|
|
431
|
-
const queryParameters = {
|
|
434
|
+
const queryParameters = {
|
|
435
|
+
...baseQueryParameters,
|
|
432
436
|
...request.queryParameters,
|
|
433
437
|
...dataQueryParameters
|
|
434
438
|
};
|
|
435
|
-
|
|
436
439
|
if (algoliaAgent.value) {
|
|
437
440
|
queryParameters['x-algolia-agent'] = algoliaAgent.value;
|
|
438
441
|
}
|
|
439
|
-
|
|
440
442
|
if (requestOptions && requestOptions.queryParameters) {
|
|
441
443
|
for (const key of Object.keys(requestOptions.queryParameters)) {
|
|
442
444
|
// We want to keep `undefined` and `null` values,
|
|
@@ -449,25 +451,19 @@ function createTransporter({
|
|
|
449
451
|
}
|
|
450
452
|
}
|
|
451
453
|
}
|
|
452
|
-
|
|
453
454
|
let timeoutsCount = 0;
|
|
454
|
-
|
|
455
455
|
const retry = async (retryableHosts, getTimeout) => {
|
|
456
|
-
/**
|
|
457
|
-
* We iterate on each host, until there is no host left.
|
|
456
|
+
/**
|
|
457
|
+
* We iterate on each host, until there is no host left.
|
|
458
458
|
*/
|
|
459
459
|
const host = retryableHosts.pop();
|
|
460
|
-
|
|
461
460
|
if (host === undefined) {
|
|
462
461
|
throw new RetryError(stackTraceWithoutCredentials(stackTrace));
|
|
463
462
|
}
|
|
464
|
-
|
|
465
463
|
let responseTimeout = requestOptions.timeout;
|
|
466
|
-
|
|
467
464
|
if (responseTimeout === undefined) {
|
|
468
465
|
responseTimeout = isRead ? timeouts.read : timeouts.write;
|
|
469
466
|
}
|
|
470
|
-
|
|
471
467
|
const payload = {
|
|
472
468
|
data,
|
|
473
469
|
headers,
|
|
@@ -476,12 +472,11 @@ function createTransporter({
|
|
|
476
472
|
connectTimeout: getTimeout(timeoutsCount, timeouts.connect),
|
|
477
473
|
responseTimeout: getTimeout(timeoutsCount, responseTimeout)
|
|
478
474
|
};
|
|
479
|
-
/**
|
|
480
|
-
* The stackFrame is pushed to the stackTrace so we
|
|
481
|
-
* can have information about onRetry and onFailure
|
|
482
|
-
* decisions.
|
|
475
|
+
/**
|
|
476
|
+
* The stackFrame is pushed to the stackTrace so we
|
|
477
|
+
* can have information about onRetry and onFailure
|
|
478
|
+
* decisions.
|
|
483
479
|
*/
|
|
484
|
-
|
|
485
480
|
const pushToStackTrace = response => {
|
|
486
481
|
const stackFrame = {
|
|
487
482
|
request: payload,
|
|
@@ -492,102 +487,85 @@ function createTransporter({
|
|
|
492
487
|
stackTrace.push(stackFrame);
|
|
493
488
|
return stackFrame;
|
|
494
489
|
};
|
|
495
|
-
|
|
496
490
|
const response = await requester.send(payload);
|
|
497
|
-
|
|
498
491
|
if (isRetryable(response)) {
|
|
499
|
-
const stackFrame = pushToStackTrace(response);
|
|
500
|
-
|
|
492
|
+
const stackFrame = pushToStackTrace(response);
|
|
493
|
+
// If response is a timeout, we increase the number of timeouts so we can increase the timeout later.
|
|
501
494
|
if (response.isTimedOut) {
|
|
502
495
|
timeoutsCount++;
|
|
503
496
|
}
|
|
504
|
-
/**
|
|
505
|
-
* Failures are individually sent to the logger, allowing
|
|
506
|
-
* the end user to debug / store stack frames even
|
|
507
|
-
* when a retry error does not happen.
|
|
497
|
+
/**
|
|
498
|
+
* Failures are individually sent to the logger, allowing
|
|
499
|
+
* the end user to debug / store stack frames even
|
|
500
|
+
* when a retry error does not happen.
|
|
508
501
|
*/
|
|
509
502
|
// eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
|
|
510
|
-
|
|
511
|
-
|
|
512
503
|
console.log('Retryable failure', stackFrameWithoutCredentials(stackFrame));
|
|
513
|
-
/**
|
|
514
|
-
* We also store the state of the host in failure cases. If the host, is
|
|
515
|
-
* down it will remain down for the next 2 minutes. In a timeout situation,
|
|
516
|
-
* this host will be added end of the list of hosts on the next request.
|
|
504
|
+
/**
|
|
505
|
+
* We also store the state of the host in failure cases. If the host, is
|
|
506
|
+
* down it will remain down for the next 2 minutes. In a timeout situation,
|
|
507
|
+
* this host will be added end of the list of hosts on the next request.
|
|
517
508
|
*/
|
|
518
|
-
|
|
519
509
|
await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));
|
|
520
510
|
return retry(retryableHosts, getTimeout);
|
|
521
511
|
}
|
|
522
|
-
|
|
523
512
|
if (isSuccess(response)) {
|
|
524
513
|
return deserializeSuccess(response);
|
|
525
514
|
}
|
|
526
|
-
|
|
527
515
|
pushToStackTrace(response);
|
|
528
516
|
throw deserializeFailure(response, stackTrace);
|
|
529
517
|
};
|
|
530
|
-
/**
|
|
531
|
-
* Finally, for each retryable host perform request until we got a non
|
|
532
|
-
* retryable response. Some notes here:
|
|
533
|
-
*
|
|
534
|
-
* 1. The reverse here is applied so we can apply a `pop` later on => more performant.
|
|
535
|
-
* 2. We also get from the retryable options a timeout multiplier that is tailored
|
|
536
|
-
* for the current context.
|
|
518
|
+
/**
|
|
519
|
+
* Finally, for each retryable host perform request until we got a non
|
|
520
|
+
* retryable response. Some notes here:
|
|
521
|
+
*
|
|
522
|
+
* 1. The reverse here is applied so we can apply a `pop` later on => more performant.
|
|
523
|
+
* 2. We also get from the retryable options a timeout multiplier that is tailored
|
|
524
|
+
* for the current context.
|
|
537
525
|
*/
|
|
538
|
-
|
|
539
|
-
|
|
540
526
|
const compatibleHosts = hosts.filter(host => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'));
|
|
541
527
|
const options = await createRetryableOptions(compatibleHosts);
|
|
542
528
|
return retry([...options.hosts].reverse(), options.getTimeout);
|
|
543
529
|
}
|
|
544
|
-
|
|
545
530
|
function createRequest(request, requestOptions = {}) {
|
|
546
|
-
/**
|
|
547
|
-
* A read request is either a `GET` request, or a request that we make
|
|
548
|
-
* via the `read` transporter (e.g. `search`).
|
|
531
|
+
/**
|
|
532
|
+
* A read request is either a `GET` request, or a request that we make
|
|
533
|
+
* via the `read` transporter (e.g. `search`).
|
|
549
534
|
*/
|
|
550
535
|
const isRead = request.useReadTransporter || request.method === 'GET';
|
|
551
|
-
|
|
552
536
|
if (!isRead) {
|
|
553
|
-
/**
|
|
554
|
-
* On write requests, no cache mechanisms are applied, and we
|
|
555
|
-
* proxy the request immediately to the requester.
|
|
537
|
+
/**
|
|
538
|
+
* On write requests, no cache mechanisms are applied, and we
|
|
539
|
+
* proxy the request immediately to the requester.
|
|
556
540
|
*/
|
|
557
541
|
return retryableRequest(request, requestOptions, isRead);
|
|
558
542
|
}
|
|
559
|
-
|
|
560
543
|
const createRetryableRequest = () => {
|
|
561
|
-
/**
|
|
562
|
-
* Then, we prepare a function factory that contains the construction of
|
|
563
|
-
* the retryable request. At this point, we may *not* perform the actual
|
|
564
|
-
* request. But we want to have the function factory ready.
|
|
544
|
+
/**
|
|
545
|
+
* Then, we prepare a function factory that contains the construction of
|
|
546
|
+
* the retryable request. At this point, we may *not* perform the actual
|
|
547
|
+
* request. But we want to have the function factory ready.
|
|
565
548
|
*/
|
|
566
549
|
return retryableRequest(request, requestOptions);
|
|
567
550
|
};
|
|
568
|
-
/**
|
|
569
|
-
* Once we have the function factory ready, we need to determine of the
|
|
570
|
-
* request is "cacheable" - should be cached. Note that, once again,
|
|
571
|
-
* the user can force this option.
|
|
551
|
+
/**
|
|
552
|
+
* Once we have the function factory ready, we need to determine of the
|
|
553
|
+
* request is "cacheable" - should be cached. Note that, once again,
|
|
554
|
+
* the user can force this option.
|
|
572
555
|
*/
|
|
573
|
-
|
|
574
|
-
|
|
575
556
|
const cacheable = requestOptions.cacheable || request.cacheable;
|
|
576
|
-
/**
|
|
577
|
-
* If is not "cacheable", we immediately trigger the retryable request, no
|
|
578
|
-
* need to check cache implementations.
|
|
557
|
+
/**
|
|
558
|
+
* If is not "cacheable", we immediately trigger the retryable request, no
|
|
559
|
+
* need to check cache implementations.
|
|
579
560
|
*/
|
|
580
|
-
|
|
581
561
|
if (cacheable !== true) {
|
|
582
562
|
return createRetryableRequest();
|
|
583
563
|
}
|
|
584
|
-
/**
|
|
585
|
-
* If the request is "cacheable", we need to first compute the key to ask
|
|
586
|
-
* the cache implementations if this request is on progress or if the
|
|
587
|
-
* response already exists on the cache.
|
|
564
|
+
/**
|
|
565
|
+
* If the request is "cacheable", we need to first compute the key to ask
|
|
566
|
+
* the cache implementations if this request is on progress or if the
|
|
567
|
+
* response already exists on the cache.
|
|
588
568
|
*/
|
|
589
|
-
|
|
590
|
-
|
|
591
569
|
const key = {
|
|
592
570
|
request,
|
|
593
571
|
requestOptions,
|
|
@@ -596,33 +574,31 @@ function createTransporter({
|
|
|
596
574
|
headers: baseHeaders
|
|
597
575
|
}
|
|
598
576
|
};
|
|
599
|
-
/**
|
|
600
|
-
* With the computed key, we first ask the responses cache
|
|
601
|
-
* implementation if this request was been resolved before.
|
|
577
|
+
/**
|
|
578
|
+
* With the computed key, we first ask the responses cache
|
|
579
|
+
* implementation if this request was been resolved before.
|
|
602
580
|
*/
|
|
603
|
-
|
|
604
581
|
return responsesCache.get(key, () => {
|
|
605
|
-
/**
|
|
606
|
-
* If the request has never resolved before, we actually ask if there
|
|
607
|
-
* is a current request with the same key on progress.
|
|
582
|
+
/**
|
|
583
|
+
* If the request has never resolved before, we actually ask if there
|
|
584
|
+
* is a current request with the same key on progress.
|
|
608
585
|
*/
|
|
609
586
|
return requestsCache.get(key, () =>
|
|
610
|
-
/**
|
|
611
|
-
* Finally, if there is no request in progress with the same key,
|
|
612
|
-
* this `createRetryableRequest()` will actually trigger the
|
|
613
|
-
* retryable request.
|
|
587
|
+
/**
|
|
588
|
+
* Finally, if there is no request in progress with the same key,
|
|
589
|
+
* this `createRetryableRequest()` will actually trigger the
|
|
590
|
+
* retryable request.
|
|
614
591
|
*/
|
|
615
592
|
requestsCache.set(key, createRetryableRequest()).then(response => Promise.all([requestsCache.delete(key), response]), err => Promise.all([requestsCache.delete(key), Promise.reject(err)])).then(([_, response]) => response));
|
|
616
593
|
}, {
|
|
617
|
-
/**
|
|
618
|
-
* Of course, once we get this response back from the server, we
|
|
619
|
-
* tell response cache to actually store the received response
|
|
620
|
-
* to be used later.
|
|
594
|
+
/**
|
|
595
|
+
* Of course, once we get this response back from the server, we
|
|
596
|
+
* tell response cache to actually store the received response
|
|
597
|
+
* to be used later.
|
|
621
598
|
*/
|
|
622
599
|
miss: response => responsesCache.set(key, response)
|
|
623
600
|
});
|
|
624
601
|
}
|
|
625
|
-
|
|
626
602
|
return {
|
|
627
603
|
hostsCache,
|
|
628
604
|
requester,
|
|
@@ -640,17 +616,13 @@ function createTransporter({
|
|
|
640
616
|
function createAlgoliaAgent(version) {
|
|
641
617
|
const algoliaAgent = {
|
|
642
618
|
value: `Algolia for JavaScript (${version})`,
|
|
643
|
-
|
|
644
619
|
add(options) {
|
|
645
620
|
const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;
|
|
646
|
-
|
|
647
621
|
if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
|
|
648
622
|
algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
|
|
649
623
|
}
|
|
650
|
-
|
|
651
624
|
return algoliaAgent;
|
|
652
625
|
}
|
|
653
|
-
|
|
654
626
|
};
|
|
655
627
|
return algoliaAgent;
|
|
656
628
|
}
|
|
@@ -672,301 +644,443 @@ const DEFAULT_CONNECT_TIMEOUT_BROWSER = 1000;
|
|
|
672
644
|
const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
|
|
673
645
|
const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
|
|
674
646
|
|
|
675
|
-
function createXhrRequester() {
|
|
676
|
-
function send(request) {
|
|
677
|
-
return new Promise((resolve) => {
|
|
678
|
-
const baseRequester = new XMLHttpRequest();
|
|
679
|
-
baseRequester.open(request.method, request.url, true);
|
|
680
|
-
Object.keys(request.headers).forEach((key) => baseRequester.setRequestHeader(key, request.headers[key]));
|
|
681
|
-
const createTimeout = (timeout, content) => {
|
|
682
|
-
return setTimeout(() => {
|
|
683
|
-
baseRequester.abort();
|
|
684
|
-
resolve({
|
|
685
|
-
status: 0,
|
|
686
|
-
content,
|
|
687
|
-
isTimedOut: true,
|
|
688
|
-
});
|
|
689
|
-
}, timeout);
|
|
690
|
-
};
|
|
691
|
-
const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
|
|
692
|
-
let responseTimeout;
|
|
693
|
-
baseRequester.onreadystatechange = () => {
|
|
694
|
-
if (baseRequester.readyState > baseRequester.OPENED &&
|
|
695
|
-
responseTimeout === undefined) {
|
|
696
|
-
clearTimeout(connectTimeout);
|
|
697
|
-
responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
|
|
698
|
-
}
|
|
699
|
-
};
|
|
700
|
-
baseRequester.onerror = () => {
|
|
701
|
-
// istanbul ignore next
|
|
702
|
-
if (baseRequester.status === 0) {
|
|
703
|
-
clearTimeout(connectTimeout);
|
|
704
|
-
clearTimeout(responseTimeout);
|
|
705
|
-
resolve({
|
|
706
|
-
content: baseRequester.responseText || 'Network request failed',
|
|
707
|
-
status: baseRequester.status,
|
|
708
|
-
isTimedOut: false,
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
};
|
|
712
|
-
baseRequester.onload = () => {
|
|
713
|
-
clearTimeout(connectTimeout);
|
|
714
|
-
clearTimeout(responseTimeout);
|
|
715
|
-
resolve({
|
|
716
|
-
content: baseRequester.responseText,
|
|
717
|
-
status: baseRequester.status,
|
|
718
|
-
isTimedOut: false,
|
|
719
|
-
});
|
|
720
|
-
};
|
|
721
|
-
baseRequester.send(request.data);
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
return { send };
|
|
647
|
+
function createXhrRequester() {
|
|
648
|
+
function send(request) {
|
|
649
|
+
return new Promise((resolve) => {
|
|
650
|
+
const baseRequester = new XMLHttpRequest();
|
|
651
|
+
baseRequester.open(request.method, request.url, true);
|
|
652
|
+
Object.keys(request.headers).forEach((key) => baseRequester.setRequestHeader(key, request.headers[key]));
|
|
653
|
+
const createTimeout = (timeout, content) => {
|
|
654
|
+
return setTimeout(() => {
|
|
655
|
+
baseRequester.abort();
|
|
656
|
+
resolve({
|
|
657
|
+
status: 0,
|
|
658
|
+
content,
|
|
659
|
+
isTimedOut: true,
|
|
660
|
+
});
|
|
661
|
+
}, timeout);
|
|
662
|
+
};
|
|
663
|
+
const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
|
|
664
|
+
let responseTimeout;
|
|
665
|
+
baseRequester.onreadystatechange = () => {
|
|
666
|
+
if (baseRequester.readyState > baseRequester.OPENED &&
|
|
667
|
+
responseTimeout === undefined) {
|
|
668
|
+
clearTimeout(connectTimeout);
|
|
669
|
+
responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
baseRequester.onerror = () => {
|
|
673
|
+
// istanbul ignore next
|
|
674
|
+
if (baseRequester.status === 0) {
|
|
675
|
+
clearTimeout(connectTimeout);
|
|
676
|
+
clearTimeout(responseTimeout);
|
|
677
|
+
resolve({
|
|
678
|
+
content: baseRequester.responseText || 'Network request failed',
|
|
679
|
+
status: baseRequester.status,
|
|
680
|
+
isTimedOut: false,
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
baseRequester.onload = () => {
|
|
685
|
+
clearTimeout(connectTimeout);
|
|
686
|
+
clearTimeout(responseTimeout);
|
|
687
|
+
resolve({
|
|
688
|
+
content: baseRequester.responseText,
|
|
689
|
+
status: baseRequester.status,
|
|
690
|
+
isTimedOut: false,
|
|
691
|
+
});
|
|
692
|
+
};
|
|
693
|
+
baseRequester.send(request.data);
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
return { send };
|
|
725
697
|
}
|
|
726
698
|
|
|
727
|
-
//
|
|
728
|
-
const apiClientVersion = '5.0.0-alpha.
|
|
729
|
-
function getDefaultHosts(appId) {
|
|
730
|
-
return [
|
|
731
|
-
{
|
|
732
|
-
url: `${appId}-dsn.algolia.net`,
|
|
733
|
-
accept: 'read',
|
|
734
|
-
protocol: 'https',
|
|
735
|
-
},
|
|
736
|
-
{
|
|
737
|
-
url: `${appId}.algolia.net`,
|
|
738
|
-
accept: 'write',
|
|
739
|
-
protocol: 'https',
|
|
740
|
-
},
|
|
741
|
-
].concat(shuffle([
|
|
742
|
-
{
|
|
743
|
-
url: `${appId}-1.algolianet.com`,
|
|
744
|
-
accept: 'readWrite',
|
|
745
|
-
protocol: 'https',
|
|
746
|
-
},
|
|
747
|
-
{
|
|
748
|
-
url: `${appId}-2.algolianet.com`,
|
|
749
|
-
accept: 'readWrite',
|
|
750
|
-
protocol: 'https',
|
|
751
|
-
},
|
|
752
|
-
{
|
|
753
|
-
url: `${appId}-3.algolianet.com`,
|
|
754
|
-
accept: 'readWrite',
|
|
755
|
-
protocol: 'https',
|
|
756
|
-
},
|
|
757
|
-
]));
|
|
758
|
-
}
|
|
759
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
760
|
-
function createRecommendClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, ...options }) {
|
|
761
|
-
const auth = createAuth(appIdOption, apiKeyOption, authMode);
|
|
762
|
-
const transporter = createTransporter({
|
|
763
|
-
hosts: getDefaultHosts(appIdOption),
|
|
764
|
-
...options,
|
|
765
|
-
algoliaAgent: getAlgoliaAgent({
|
|
766
|
-
algoliaAgents,
|
|
767
|
-
client: 'Recommend',
|
|
768
|
-
version: apiClientVersion,
|
|
769
|
-
}),
|
|
770
|
-
baseHeaders: {
|
|
771
|
-
'content-type': 'text/plain',
|
|
772
|
-
...auth.headers(),
|
|
773
|
-
...options.baseHeaders,
|
|
774
|
-
},
|
|
775
|
-
baseQueryParameters: {
|
|
776
|
-
...auth.queryParameters(),
|
|
777
|
-
...options.baseQueryParameters,
|
|
778
|
-
},
|
|
779
|
-
});
|
|
780
|
-
return {
|
|
781
|
-
transporter,
|
|
782
|
-
/**
|
|
783
|
-
* The `appId` currently in use.
|
|
784
|
-
*/
|
|
785
|
-
appId: appIdOption,
|
|
786
|
-
/**
|
|
787
|
-
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
|
|
788
|
-
*/
|
|
789
|
-
clearCache() {
|
|
790
|
-
return Promise.all([
|
|
791
|
-
transporter.requestsCache.clear(),
|
|
792
|
-
transporter.responsesCache.clear(),
|
|
793
|
-
]).then(() => undefined);
|
|
794
|
-
},
|
|
795
|
-
/**
|
|
796
|
-
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
|
|
797
|
-
*/
|
|
798
|
-
get _ua() {
|
|
799
|
-
return transporter.algoliaAgent.value;
|
|
800
|
-
},
|
|
801
|
-
/**
|
|
802
|
-
* Adds a `segment` to the `x-algolia-agent` sent with every requests.
|
|
803
|
-
*
|
|
804
|
-
* @param segment - The algolia agent (user-agent) segment to add.
|
|
805
|
-
* @param version - The version of the agent.
|
|
806
|
-
*/
|
|
807
|
-
addAlgoliaAgent(segment, version) {
|
|
808
|
-
transporter.algoliaAgent.add({ segment, version });
|
|
809
|
-
},
|
|
810
|
-
/**
|
|
811
|
-
* This method allow you to send requests to the Algolia REST API.
|
|
812
|
-
*
|
|
813
|
-
* @
|
|
814
|
-
* @param
|
|
815
|
-
* @param
|
|
816
|
-
* @param
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
}
|
|
823
|
-
const
|
|
824
|
-
const
|
|
825
|
-
const
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
* @
|
|
838
|
-
* @param
|
|
839
|
-
* @param
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
}
|
|
847
|
-
const
|
|
848
|
-
const
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
*
|
|
860
|
-
*
|
|
861
|
-
* @
|
|
862
|
-
* @param
|
|
863
|
-
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
864
|
-
*/
|
|
865
|
-
|
|
866
|
-
if (!
|
|
867
|
-
throw new Error('Parameter `
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
}
|
|
872
|
-
const
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
*
|
|
888
|
-
*
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
*
|
|
914
|
-
*
|
|
915
|
-
* @
|
|
916
|
-
* @param
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
699
|
+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
|
|
700
|
+
const apiClientVersion = '5.0.0-alpha.110';
|
|
701
|
+
function getDefaultHosts(appId) {
|
|
702
|
+
return [
|
|
703
|
+
{
|
|
704
|
+
url: `${appId}-dsn.algolia.net`,
|
|
705
|
+
accept: 'read',
|
|
706
|
+
protocol: 'https',
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
url: `${appId}.algolia.net`,
|
|
710
|
+
accept: 'write',
|
|
711
|
+
protocol: 'https',
|
|
712
|
+
},
|
|
713
|
+
].concat(shuffle([
|
|
714
|
+
{
|
|
715
|
+
url: `${appId}-1.algolianet.com`,
|
|
716
|
+
accept: 'readWrite',
|
|
717
|
+
protocol: 'https',
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
url: `${appId}-2.algolianet.com`,
|
|
721
|
+
accept: 'readWrite',
|
|
722
|
+
protocol: 'https',
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
url: `${appId}-3.algolianet.com`,
|
|
726
|
+
accept: 'readWrite',
|
|
727
|
+
protocol: 'https',
|
|
728
|
+
},
|
|
729
|
+
]));
|
|
730
|
+
}
|
|
731
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
732
|
+
function createRecommendClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, ...options }) {
|
|
733
|
+
const auth = createAuth(appIdOption, apiKeyOption, authMode);
|
|
734
|
+
const transporter = createTransporter({
|
|
735
|
+
hosts: getDefaultHosts(appIdOption),
|
|
736
|
+
...options,
|
|
737
|
+
algoliaAgent: getAlgoliaAgent({
|
|
738
|
+
algoliaAgents,
|
|
739
|
+
client: 'Recommend',
|
|
740
|
+
version: apiClientVersion,
|
|
741
|
+
}),
|
|
742
|
+
baseHeaders: {
|
|
743
|
+
'content-type': 'text/plain',
|
|
744
|
+
...auth.headers(),
|
|
745
|
+
...options.baseHeaders,
|
|
746
|
+
},
|
|
747
|
+
baseQueryParameters: {
|
|
748
|
+
...auth.queryParameters(),
|
|
749
|
+
...options.baseQueryParameters,
|
|
750
|
+
},
|
|
751
|
+
});
|
|
752
|
+
return {
|
|
753
|
+
transporter,
|
|
754
|
+
/**
|
|
755
|
+
* The `appId` currently in use.
|
|
756
|
+
*/
|
|
757
|
+
appId: appIdOption,
|
|
758
|
+
/**
|
|
759
|
+
* Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
|
|
760
|
+
*/
|
|
761
|
+
clearCache() {
|
|
762
|
+
return Promise.all([
|
|
763
|
+
transporter.requestsCache.clear(),
|
|
764
|
+
transporter.responsesCache.clear(),
|
|
765
|
+
]).then(() => undefined);
|
|
766
|
+
},
|
|
767
|
+
/**
|
|
768
|
+
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
|
|
769
|
+
*/
|
|
770
|
+
get _ua() {
|
|
771
|
+
return transporter.algoliaAgent.value;
|
|
772
|
+
},
|
|
773
|
+
/**
|
|
774
|
+
* Adds a `segment` to the `x-algolia-agent` sent with every requests.
|
|
775
|
+
*
|
|
776
|
+
* @param segment - The algolia agent (user-agent) segment to add.
|
|
777
|
+
* @param version - The version of the agent.
|
|
778
|
+
*/
|
|
779
|
+
addAlgoliaAgent(segment, version) {
|
|
780
|
+
transporter.algoliaAgent.add({ segment, version });
|
|
781
|
+
},
|
|
782
|
+
/**
|
|
783
|
+
* This method allow you to send requests to the Algolia REST API.
|
|
784
|
+
*
|
|
785
|
+
* @param customDelete - The customDelete object.
|
|
786
|
+
* @param customDelete.path - Path of the endpoint, anything after \"/1\" must be specified.
|
|
787
|
+
* @param customDelete.parameters - Query parameters to apply to the current query.
|
|
788
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
789
|
+
*/
|
|
790
|
+
customDelete({ path, parameters }, requestOptions) {
|
|
791
|
+
if (!path) {
|
|
792
|
+
throw new Error('Parameter `path` is required when calling `customDelete`.');
|
|
793
|
+
}
|
|
794
|
+
const requestPath = '/{path}'.replace('{path}', path);
|
|
795
|
+
const headers = {};
|
|
796
|
+
const queryParameters = parameters ? parameters : {};
|
|
797
|
+
const request = {
|
|
798
|
+
method: 'DELETE',
|
|
799
|
+
path: requestPath,
|
|
800
|
+
queryParameters,
|
|
801
|
+
headers,
|
|
802
|
+
};
|
|
803
|
+
return transporter.request(request, requestOptions);
|
|
804
|
+
},
|
|
805
|
+
/**
|
|
806
|
+
* This method allow you to send requests to the Algolia REST API.
|
|
807
|
+
*
|
|
808
|
+
* @param customGet - The customGet object.
|
|
809
|
+
* @param customGet.path - Path of the endpoint, anything after \"/1\" must be specified.
|
|
810
|
+
* @param customGet.parameters - Query parameters to apply to the current query.
|
|
811
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
812
|
+
*/
|
|
813
|
+
customGet({ path, parameters }, requestOptions) {
|
|
814
|
+
if (!path) {
|
|
815
|
+
throw new Error('Parameter `path` is required when calling `customGet`.');
|
|
816
|
+
}
|
|
817
|
+
const requestPath = '/{path}'.replace('{path}', path);
|
|
818
|
+
const headers = {};
|
|
819
|
+
const queryParameters = parameters ? parameters : {};
|
|
820
|
+
const request = {
|
|
821
|
+
method: 'GET',
|
|
822
|
+
path: requestPath,
|
|
823
|
+
queryParameters,
|
|
824
|
+
headers,
|
|
825
|
+
};
|
|
826
|
+
return transporter.request(request, requestOptions);
|
|
827
|
+
},
|
|
828
|
+
/**
|
|
829
|
+
* This method allow you to send requests to the Algolia REST API.
|
|
830
|
+
*
|
|
831
|
+
* @param customPost - The customPost object.
|
|
832
|
+
* @param customPost.path - Path of the endpoint, anything after \"/1\" must be specified.
|
|
833
|
+
* @param customPost.parameters - Query parameters to apply to the current query.
|
|
834
|
+
* @param customPost.body - Parameters to send with the custom request.
|
|
835
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
836
|
+
*/
|
|
837
|
+
customPost({ path, parameters, body }, requestOptions) {
|
|
838
|
+
if (!path) {
|
|
839
|
+
throw new Error('Parameter `path` is required when calling `customPost`.');
|
|
840
|
+
}
|
|
841
|
+
const requestPath = '/{path}'.replace('{path}', path);
|
|
842
|
+
const headers = {};
|
|
843
|
+
const queryParameters = parameters ? parameters : {};
|
|
844
|
+
const request = {
|
|
845
|
+
method: 'POST',
|
|
846
|
+
path: requestPath,
|
|
847
|
+
queryParameters,
|
|
848
|
+
headers,
|
|
849
|
+
data: body ? body : {},
|
|
850
|
+
};
|
|
851
|
+
return transporter.request(request, requestOptions);
|
|
852
|
+
},
|
|
853
|
+
/**
|
|
854
|
+
* This method allow you to send requests to the Algolia REST API.
|
|
855
|
+
*
|
|
856
|
+
* @param customPut - The customPut object.
|
|
857
|
+
* @param customPut.path - Path of the endpoint, anything after \"/1\" must be specified.
|
|
858
|
+
* @param customPut.parameters - Query parameters to apply to the current query.
|
|
859
|
+
* @param customPut.body - Parameters to send with the custom request.
|
|
860
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
861
|
+
*/
|
|
862
|
+
customPut({ path, parameters, body }, requestOptions) {
|
|
863
|
+
if (!path) {
|
|
864
|
+
throw new Error('Parameter `path` is required when calling `customPut`.');
|
|
865
|
+
}
|
|
866
|
+
const requestPath = '/{path}'.replace('{path}', path);
|
|
867
|
+
const headers = {};
|
|
868
|
+
const queryParameters = parameters ? parameters : {};
|
|
869
|
+
const request = {
|
|
870
|
+
method: 'PUT',
|
|
871
|
+
path: requestPath,
|
|
872
|
+
queryParameters,
|
|
873
|
+
headers,
|
|
874
|
+
data: body ? body : {},
|
|
875
|
+
};
|
|
876
|
+
return transporter.request(request, requestOptions);
|
|
877
|
+
},
|
|
878
|
+
/**
|
|
879
|
+
* Delete a [Recommend rule](https://www.algolia.com/doc/guides/algolia-recommend/how-to/rules/).
|
|
880
|
+
*
|
|
881
|
+
* Required API Key ACLs:
|
|
882
|
+
* - editSettings.
|
|
883
|
+
*
|
|
884
|
+
* @param deleteRecommendRule - The deleteRecommendRule object.
|
|
885
|
+
* @param deleteRecommendRule.indexName - Name of the index on which to perform the operation.
|
|
886
|
+
* @param deleteRecommendRule.model - [Recommend models](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
|
|
887
|
+
* @param deleteRecommendRule.objectID - Unique record identifier.
|
|
888
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
889
|
+
*/
|
|
890
|
+
deleteRecommendRule({ indexName, model, objectID }, requestOptions) {
|
|
891
|
+
if (!indexName) {
|
|
892
|
+
throw new Error('Parameter `indexName` is required when calling `deleteRecommendRule`.');
|
|
893
|
+
}
|
|
894
|
+
if (!model) {
|
|
895
|
+
throw new Error('Parameter `model` is required when calling `deleteRecommendRule`.');
|
|
896
|
+
}
|
|
897
|
+
if (!objectID) {
|
|
898
|
+
throw new Error('Parameter `objectID` is required when calling `deleteRecommendRule`.');
|
|
899
|
+
}
|
|
900
|
+
const requestPath = '/1/indexes/{indexName}/{model}/recommend/rules/{objectID}'
|
|
901
|
+
.replace('{indexName}', encodeURIComponent(indexName))
|
|
902
|
+
.replace('{model}', encodeURIComponent(model))
|
|
903
|
+
.replace('{objectID}', encodeURIComponent(objectID));
|
|
904
|
+
const headers = {};
|
|
905
|
+
const queryParameters = {};
|
|
906
|
+
const request = {
|
|
907
|
+
method: 'DELETE',
|
|
908
|
+
path: requestPath,
|
|
909
|
+
queryParameters,
|
|
910
|
+
headers,
|
|
911
|
+
};
|
|
912
|
+
return transporter.request(request, requestOptions);
|
|
913
|
+
},
|
|
914
|
+
/**
|
|
915
|
+
* Return a [Recommend rule](https://www.algolia.com/doc/guides/algolia-recommend/how-to/rules/).
|
|
916
|
+
*
|
|
917
|
+
* Required API Key ACLs:
|
|
918
|
+
* - settings.
|
|
919
|
+
*
|
|
920
|
+
* @param getRecommendRule - The getRecommendRule object.
|
|
921
|
+
* @param getRecommendRule.indexName - Name of the index on which to perform the operation.
|
|
922
|
+
* @param getRecommendRule.model - [Recommend models](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
|
|
923
|
+
* @param getRecommendRule.objectID - Unique record identifier.
|
|
924
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
925
|
+
*/
|
|
926
|
+
getRecommendRule({ indexName, model, objectID }, requestOptions) {
|
|
927
|
+
if (!indexName) {
|
|
928
|
+
throw new Error('Parameter `indexName` is required when calling `getRecommendRule`.');
|
|
929
|
+
}
|
|
930
|
+
if (!model) {
|
|
931
|
+
throw new Error('Parameter `model` is required when calling `getRecommendRule`.');
|
|
932
|
+
}
|
|
933
|
+
if (!objectID) {
|
|
934
|
+
throw new Error('Parameter `objectID` is required when calling `getRecommendRule`.');
|
|
935
|
+
}
|
|
936
|
+
const requestPath = '/1/indexes/{indexName}/{model}/recommend/rules/{objectID}'
|
|
937
|
+
.replace('{indexName}', encodeURIComponent(indexName))
|
|
938
|
+
.replace('{model}', encodeURIComponent(model))
|
|
939
|
+
.replace('{objectID}', encodeURIComponent(objectID));
|
|
940
|
+
const headers = {};
|
|
941
|
+
const queryParameters = {};
|
|
942
|
+
const request = {
|
|
943
|
+
method: 'GET',
|
|
944
|
+
path: requestPath,
|
|
945
|
+
queryParameters,
|
|
946
|
+
headers,
|
|
947
|
+
};
|
|
948
|
+
return transporter.request(request, requestOptions);
|
|
949
|
+
},
|
|
950
|
+
/**
|
|
951
|
+
* Some operations, such as deleting a Recommend rule, will respond with a `taskID` value. Use this value here to check the status of that task.
|
|
952
|
+
*
|
|
953
|
+
* Required API Key ACLs:
|
|
954
|
+
* - editSettings.
|
|
955
|
+
*
|
|
956
|
+
* @param getRecommendStatus - The getRecommendStatus object.
|
|
957
|
+
* @param getRecommendStatus.indexName - Name of the index on which to perform the operation.
|
|
958
|
+
* @param getRecommendStatus.model - [Recommend models](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
|
|
959
|
+
* @param getRecommendStatus.taskID - Unique identifier of a task. Numeric value (up to 64bits).
|
|
960
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
961
|
+
*/
|
|
962
|
+
getRecommendStatus({ indexName, model, taskID }, requestOptions) {
|
|
963
|
+
if (!indexName) {
|
|
964
|
+
throw new Error('Parameter `indexName` is required when calling `getRecommendStatus`.');
|
|
965
|
+
}
|
|
966
|
+
if (!model) {
|
|
967
|
+
throw new Error('Parameter `model` is required when calling `getRecommendStatus`.');
|
|
968
|
+
}
|
|
969
|
+
if (!taskID) {
|
|
970
|
+
throw new Error('Parameter `taskID` is required when calling `getRecommendStatus`.');
|
|
971
|
+
}
|
|
972
|
+
const requestPath = '/1/indexes/{indexName}/{model}/task/{taskID}'
|
|
973
|
+
.replace('{indexName}', encodeURIComponent(indexName))
|
|
974
|
+
.replace('{model}', encodeURIComponent(model))
|
|
975
|
+
.replace('{taskID}', encodeURIComponent(taskID));
|
|
976
|
+
const headers = {};
|
|
977
|
+
const queryParameters = {};
|
|
978
|
+
const request = {
|
|
979
|
+
method: 'GET',
|
|
980
|
+
path: requestPath,
|
|
981
|
+
queryParameters,
|
|
982
|
+
headers,
|
|
983
|
+
};
|
|
984
|
+
return transporter.request(request, requestOptions);
|
|
985
|
+
},
|
|
986
|
+
/**
|
|
987
|
+
* Returns results from either recommendation or trending models: - **Recommendations** are provided by the [Related Products](https://www.algolia.com/doc/guides/algolia-recommend/overview/#related-products-and-related-content) and [Frequently Bought Together](https://www.algolia.com/doc/guides/algolia-recommend/overview/#frequently-bought-together) models - **Trending** models are [Trending Items and Trending Facet Values](https://www.algolia.com/doc/guides/algolia-recommend/overview/#trending-items-and-trending-facet-values).
|
|
988
|
+
*
|
|
989
|
+
* Required API Key ACLs:
|
|
990
|
+
* - search.
|
|
991
|
+
*
|
|
992
|
+
* @param getRecommendationsParams - The getRecommendationsParams object.
|
|
993
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
994
|
+
*/
|
|
995
|
+
getRecommendations(getRecommendationsParams, requestOptions) {
|
|
996
|
+
if (!getRecommendationsParams) {
|
|
997
|
+
throw new Error('Parameter `getRecommendationsParams` is required when calling `getRecommendations`.');
|
|
998
|
+
}
|
|
999
|
+
if (!getRecommendationsParams.requests) {
|
|
1000
|
+
throw new Error('Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.');
|
|
1001
|
+
}
|
|
1002
|
+
const requestPath = '/1/indexes/*/recommendations';
|
|
1003
|
+
const headers = {};
|
|
1004
|
+
const queryParameters = {};
|
|
1005
|
+
const request = {
|
|
1006
|
+
method: 'POST',
|
|
1007
|
+
path: requestPath,
|
|
1008
|
+
queryParameters,
|
|
1009
|
+
headers,
|
|
1010
|
+
data: getRecommendationsParams,
|
|
1011
|
+
useReadTransporter: true,
|
|
1012
|
+
cacheable: true,
|
|
1013
|
+
};
|
|
1014
|
+
return transporter.request(request, requestOptions);
|
|
1015
|
+
},
|
|
1016
|
+
/**
|
|
1017
|
+
* List [Recommend rules](https://www.algolia.com/doc/guides/algolia-recommend/how-to/rules/).
|
|
1018
|
+
*
|
|
1019
|
+
* Required API Key ACLs:
|
|
1020
|
+
* - settings.
|
|
1021
|
+
*
|
|
1022
|
+
* @param searchRecommendRules - The searchRecommendRules object.
|
|
1023
|
+
* @param searchRecommendRules.indexName - Name of the index on which to perform the operation.
|
|
1024
|
+
* @param searchRecommendRules.model - [Recommend models](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
|
|
1025
|
+
* @param searchRecommendRules.searchRecommendRulesParams - The searchRecommendRulesParams object.
|
|
1026
|
+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
|
|
1027
|
+
*/
|
|
1028
|
+
searchRecommendRules({ indexName, model, searchRecommendRulesParams, }, requestOptions) {
|
|
1029
|
+
if (!indexName) {
|
|
1030
|
+
throw new Error('Parameter `indexName` is required when calling `searchRecommendRules`.');
|
|
1031
|
+
}
|
|
1032
|
+
if (!model) {
|
|
1033
|
+
throw new Error('Parameter `model` is required when calling `searchRecommendRules`.');
|
|
1034
|
+
}
|
|
1035
|
+
const requestPath = '/1/indexes/{indexName}/{model}/recommend/rules/search'
|
|
1036
|
+
.replace('{indexName}', encodeURIComponent(indexName))
|
|
1037
|
+
.replace('{model}', encodeURIComponent(model));
|
|
1038
|
+
const headers = {};
|
|
1039
|
+
const queryParameters = {};
|
|
1040
|
+
const request = {
|
|
1041
|
+
method: 'POST',
|
|
1042
|
+
path: requestPath,
|
|
1043
|
+
queryParameters,
|
|
1044
|
+
headers,
|
|
1045
|
+
data: searchRecommendRulesParams ? searchRecommendRulesParams : {},
|
|
1046
|
+
useReadTransporter: true,
|
|
1047
|
+
cacheable: true,
|
|
1048
|
+
};
|
|
1049
|
+
return transporter.request(request, requestOptions);
|
|
1050
|
+
},
|
|
1051
|
+
};
|
|
939
1052
|
}
|
|
940
1053
|
|
|
941
|
-
//
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1054
|
+
// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
|
|
1055
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1056
|
+
function recommendClient(appId, apiKey, options) {
|
|
1057
|
+
if (!appId || typeof appId !== 'string') {
|
|
1058
|
+
throw new Error('`appId` is missing.');
|
|
1059
|
+
}
|
|
1060
|
+
if (!apiKey || typeof apiKey !== 'string') {
|
|
1061
|
+
throw new Error('`apiKey` is missing.');
|
|
1062
|
+
}
|
|
1063
|
+
return createRecommendClient({
|
|
1064
|
+
appId,
|
|
1065
|
+
apiKey,
|
|
1066
|
+
timeouts: {
|
|
1067
|
+
connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
|
|
1068
|
+
read: DEFAULT_READ_TIMEOUT_BROWSER,
|
|
1069
|
+
write: DEFAULT_WRITE_TIMEOUT_BROWSER,
|
|
1070
|
+
},
|
|
1071
|
+
requester: createXhrRequester(),
|
|
1072
|
+
algoliaAgents: [{ segment: 'Browser' }],
|
|
1073
|
+
authMode: 'WithinQueryParameters',
|
|
1074
|
+
responsesCache: createMemoryCache(),
|
|
1075
|
+
requestsCache: createMemoryCache({ serializable: false }),
|
|
1076
|
+
hostsCache: createFallbackableCache({
|
|
1077
|
+
caches: [
|
|
1078
|
+
createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }),
|
|
1079
|
+
createMemoryCache(),
|
|
1080
|
+
],
|
|
1081
|
+
}),
|
|
1082
|
+
...options,
|
|
1083
|
+
});
|
|
970
1084
|
}
|
|
971
1085
|
|
|
972
1086
|
export { apiClientVersion, recommendClient };
|