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