@algolia/recommend 5.0.0-alpha.11 → 5.0.0-alpha.111

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.
Files changed (316) hide show
  1. package/dist/builds/browser.d.ts +23 -5
  2. package/dist/builds/browser.d.ts.map +1 -1
  3. package/dist/builds/node.d.ts +23 -5
  4. package/dist/builds/node.d.ts.map +1 -1
  5. package/dist/model/advancedSyntaxFeatures.d.ts +1 -1
  6. package/dist/model/advancedSyntaxFeatures.d.ts.map +1 -1
  7. package/dist/model/alternativesAsExact.d.ts +1 -1
  8. package/dist/model/alternativesAsExact.d.ts.map +1 -1
  9. package/dist/model/aroundPrecision.d.ts +6 -0
  10. package/dist/model/aroundPrecision.d.ts.map +1 -0
  11. package/dist/model/aroundPrecisionFromValueInner.d.ts +14 -0
  12. package/dist/model/aroundPrecisionFromValueInner.d.ts.map +1 -0
  13. package/dist/model/aroundRadius.d.ts +5 -5
  14. package/dist/model/aroundRadius.d.ts.map +1 -1
  15. package/dist/model/aroundRadiusAll.d.ts +4 -1
  16. package/dist/model/aroundRadiusAll.d.ts.map +1 -1
  17. package/dist/model/autoFacetFilter.d.ts +14 -0
  18. package/dist/model/autoFacetFilter.d.ts.map +1 -0
  19. package/dist/model/baseRecommendRequest.d.ts +16 -17
  20. package/dist/model/baseRecommendRequest.d.ts.map +1 -1
  21. package/dist/model/baseSearchParams.d.ts +3 -3
  22. package/dist/model/baseSearchParams.d.ts.map +1 -1
  23. package/dist/model/baseSearchParamsWithoutQuery.d.ts +114 -122
  24. package/dist/model/baseSearchParamsWithoutQuery.d.ts.map +1 -1
  25. package/dist/model/baseSearchResponse.d.ts +109 -101
  26. package/dist/model/baseSearchResponse.d.ts.map +1 -1
  27. package/dist/model/boughtTogetherQuery.d.ts +4 -0
  28. package/dist/model/boughtTogetherQuery.d.ts.map +1 -0
  29. package/dist/model/clientMethodProps.d.ts +127 -60
  30. package/dist/model/clientMethodProps.d.ts.map +1 -1
  31. package/dist/model/condition.d.ts +14 -0
  32. package/dist/model/condition.d.ts.map +1 -0
  33. package/dist/model/consequence.d.ts +18 -0
  34. package/dist/model/consequence.d.ts.map +1 -0
  35. package/dist/model/deletedAtResponse.d.ts +14 -0
  36. package/dist/model/deletedAtResponse.d.ts.map +1 -0
  37. package/dist/model/distinct.d.ts +4 -4
  38. package/dist/model/distinct.d.ts.map +1 -1
  39. package/dist/model/errorBase.d.ts +6 -6
  40. package/dist/model/errorBase.d.ts.map +1 -1
  41. package/dist/model/exactOnSingleWordQuery.d.ts +4 -4
  42. package/dist/model/exactOnSingleWordQuery.d.ts.map +1 -1
  43. package/dist/model/exhaustive.d.ts +26 -0
  44. package/dist/model/exhaustive.d.ts.map +1 -0
  45. package/dist/model/facetFilters.d.ts +5 -5
  46. package/dist/model/facetFilters.d.ts.map +1 -1
  47. package/dist/model/facetOrdering.d.ts +12 -12
  48. package/dist/model/facetOrdering.d.ts.map +1 -1
  49. package/dist/model/facets.d.ts +9 -9
  50. package/dist/model/facets.d.ts.map +1 -1
  51. package/dist/model/facetsStats.d.ts +18 -18
  52. package/dist/model/facetsStats.d.ts.map +1 -1
  53. package/dist/model/fallbackParams.d.ts +3 -0
  54. package/dist/model/fallbackParams.d.ts.map +1 -0
  55. package/dist/model/fbtModel.d.ts +5 -0
  56. package/dist/model/fbtModel.d.ts.map +1 -0
  57. package/dist/model/frequentlyBoughtTogether.d.ts +9 -0
  58. package/dist/model/frequentlyBoughtTogether.d.ts.map +1 -0
  59. package/dist/model/getRecommendTaskResponse.d.ts +5 -0
  60. package/dist/model/getRecommendTaskResponse.d.ts.map +1 -0
  61. package/dist/model/getRecommendationsParams.d.ts +10 -10
  62. package/dist/model/getRecommendationsParams.d.ts.map +1 -1
  63. package/dist/model/getRecommendationsResponse.d.ts +4 -4
  64. package/dist/model/getRecommendationsResponse.d.ts.map +1 -1
  65. package/dist/model/hideConsequenceObject.d.ts +10 -0
  66. package/dist/model/hideConsequenceObject.d.ts.map +1 -0
  67. package/dist/model/highlightResult.d.ts +2 -2
  68. package/dist/model/highlightResult.d.ts.map +1 -1
  69. package/dist/model/highlightResultOption.d.ts +19 -19
  70. package/dist/model/highlightResultOption.d.ts.map +1 -1
  71. package/dist/model/ignorePlurals.d.ts +5 -4
  72. package/dist/model/ignorePlurals.d.ts.map +1 -1
  73. package/dist/model/index.d.ts +92 -53
  74. package/dist/model/index.d.ts.map +1 -1
  75. package/dist/model/indexSettingsAsSearchParams.d.ts +159 -160
  76. package/dist/model/indexSettingsAsSearchParams.d.ts.map +1 -1
  77. package/dist/model/lookingSimilar.d.ts +11 -0
  78. package/dist/model/lookingSimilar.d.ts.map +1 -0
  79. package/dist/model/lookingSimilarModel.d.ts +5 -0
  80. package/dist/model/lookingSimilarModel.d.ts.map +1 -0
  81. package/dist/model/lookingSimilarQuery.d.ts +4 -0
  82. package/dist/model/lookingSimilarQuery.d.ts.map +1 -0
  83. package/dist/model/matchLevel.d.ts +4 -4
  84. package/dist/model/matchLevel.d.ts.map +1 -1
  85. package/dist/model/matchedGeoLocation.d.ts +14 -14
  86. package/dist/model/matchedGeoLocation.d.ts.map +1 -1
  87. package/dist/model/mixedSearchFilters.d.ts +1 -1
  88. package/dist/model/mixedSearchFilters.d.ts.map +1 -1
  89. package/dist/model/mode.d.ts +5 -0
  90. package/dist/model/mode.d.ts.map +1 -0
  91. package/dist/model/numericFilters.d.ts +5 -5
  92. package/dist/model/numericFilters.d.ts.map +1 -1
  93. package/dist/model/optionalFilters.d.ts +5 -5
  94. package/dist/model/optionalFilters.d.ts.map +1 -1
  95. package/dist/model/paramsConsequence.d.ts +19 -0
  96. package/dist/model/paramsConsequence.d.ts.map +1 -0
  97. package/dist/model/personalization.d.ts +14 -14
  98. package/dist/model/personalization.d.ts.map +1 -1
  99. package/dist/model/promoteConsequenceObject.d.ts +14 -0
  100. package/dist/model/promoteConsequenceObject.d.ts.map +1 -0
  101. package/dist/model/queryType.d.ts +4 -4
  102. package/dist/model/queryType.d.ts.map +1 -1
  103. package/dist/model/rankingInfo.d.ts +53 -50
  104. package/dist/model/rankingInfo.d.ts.map +1 -1
  105. package/dist/model/reRankingApplyFilter.d.ts +5 -5
  106. package/dist/model/reRankingApplyFilter.d.ts.map +1 -1
  107. package/dist/model/recommendHit.d.ts +26 -26
  108. package/dist/model/recommendHit.d.ts.map +1 -1
  109. package/dist/model/recommendModels.d.ts +2 -0
  110. package/dist/model/recommendModels.d.ts.map +1 -0
  111. package/dist/model/recommendRule.d.ts +24 -0
  112. package/dist/model/recommendRule.d.ts.map +1 -0
  113. package/dist/model/recommendRuleMetadata.d.ts +10 -0
  114. package/dist/model/recommendRuleMetadata.d.ts.map +1 -0
  115. package/dist/model/recommendationsHit.d.ts +4 -0
  116. package/dist/model/recommendationsHit.d.ts.map +1 -0
  117. package/dist/model/recommendationsHits.d.ts +5 -0
  118. package/dist/model/recommendationsHits.d.ts.map +1 -0
  119. package/dist/model/recommendationsRequest.d.ts +7 -3
  120. package/dist/model/recommendationsRequest.d.ts.map +1 -1
  121. package/dist/model/recommendationsResults.d.ts +4 -0
  122. package/dist/model/recommendationsResults.d.ts.map +1 -0
  123. package/dist/model/recommendedForYou.d.ts +7 -0
  124. package/dist/model/recommendedForYou.d.ts.map +1 -0
  125. package/dist/model/recommendedForYouModel.d.ts +5 -0
  126. package/dist/model/recommendedForYouModel.d.ts.map +1 -0
  127. package/dist/model/recommendedForYouQuery.d.ts +4 -0
  128. package/dist/model/recommendedForYouQuery.d.ts.map +1 -0
  129. package/dist/model/redirect.d.ts +8 -0
  130. package/dist/model/redirect.d.ts.map +1 -0
  131. package/dist/model/redirectRuleIndexMetadata.d.ts +21 -0
  132. package/dist/model/redirectRuleIndexMetadata.d.ts.map +1 -0
  133. package/dist/model/redirectRuleIndexMetadataData.d.ts +7 -0
  134. package/dist/model/redirectRuleIndexMetadataData.d.ts.map +1 -0
  135. package/dist/model/relatedModel.d.ts +5 -0
  136. package/dist/model/relatedModel.d.ts.map +1 -0
  137. package/dist/model/relatedProducts.d.ts +11 -0
  138. package/dist/model/relatedProducts.d.ts.map +1 -0
  139. package/dist/model/relatedQuery.d.ts +4 -0
  140. package/dist/model/relatedQuery.d.ts.map +1 -0
  141. package/dist/model/removeStopWords.d.ts +5 -4
  142. package/dist/model/removeStopWords.d.ts.map +1 -1
  143. package/dist/model/removeWordsIfNoResults.d.ts +4 -4
  144. package/dist/model/removeWordsIfNoResults.d.ts.map +1 -1
  145. package/dist/model/renderingContent.d.ts +7 -7
  146. package/dist/model/renderingContent.d.ts.map +1 -1
  147. package/dist/model/searchParams.d.ts +3 -0
  148. package/dist/model/searchParams.d.ts.map +1 -0
  149. package/dist/model/searchParamsObject.d.ts +3 -3
  150. package/dist/model/searchParamsObject.d.ts.map +1 -1
  151. package/dist/model/searchParamsQuery.d.ts +6 -6
  152. package/dist/model/searchParamsQuery.d.ts.map +1 -1
  153. package/dist/model/searchRecommendRulesParams.d.ts +38 -0
  154. package/dist/model/searchRecommendRulesParams.d.ts.map +1 -0
  155. package/dist/model/searchRecommendRulesResponse.d.ts +20 -0
  156. package/dist/model/searchRecommendRulesResponse.d.ts.map +1 -0
  157. package/dist/model/semanticSearch.d.ts +10 -0
  158. package/dist/model/semanticSearch.d.ts.map +1 -0
  159. package/dist/model/snippetResult.d.ts +2 -2
  160. package/dist/model/snippetResult.d.ts.map +1 -1
  161. package/dist/model/snippetResultOption.d.ts +11 -11
  162. package/dist/model/snippetResultOption.d.ts.map +1 -1
  163. package/dist/model/sortRemainingBy.d.ts +4 -4
  164. package/dist/model/sortRemainingBy.d.ts.map +1 -1
  165. package/dist/model/supportedLanguage.d.ts +5 -0
  166. package/dist/model/supportedLanguage.d.ts.map +1 -0
  167. package/dist/model/tagFilters.d.ts +5 -5
  168. package/dist/model/tagFilters.d.ts.map +1 -1
  169. package/dist/model/taskStatus.d.ts +5 -0
  170. package/dist/model/taskStatus.d.ts.map +1 -0
  171. package/dist/model/trendingFacetHit.d.ts +18 -0
  172. package/dist/model/trendingFacetHit.d.ts.map +1 -0
  173. package/dist/model/trendingFacets.d.ts +11 -0
  174. package/dist/model/trendingFacets.d.ts.map +1 -0
  175. package/dist/model/trendingFacetsModel.d.ts +5 -0
  176. package/dist/model/trendingFacetsModel.d.ts.map +1 -0
  177. package/dist/model/trendingFacetsQuery.d.ts +4 -0
  178. package/dist/model/trendingFacetsQuery.d.ts.map +1 -0
  179. package/dist/model/trendingItems.d.ts +15 -0
  180. package/dist/model/trendingItems.d.ts.map +1 -0
  181. package/dist/model/trendingItemsModel.d.ts +5 -0
  182. package/dist/model/trendingItemsModel.d.ts.map +1 -0
  183. package/dist/model/trendingItemsQuery.d.ts +4 -0
  184. package/dist/model/trendingItemsQuery.d.ts.map +1 -0
  185. package/dist/model/typoTolerance.d.ts +5 -5
  186. package/dist/model/typoTolerance.d.ts.map +1 -1
  187. package/dist/model/typoToleranceEnum.d.ts +4 -1
  188. package/dist/model/typoToleranceEnum.d.ts.map +1 -1
  189. package/dist/model/value.d.ts +8 -8
  190. package/dist/model/value.d.ts.map +1 -1
  191. package/dist/recommend.cjs +390 -0
  192. package/dist/recommend.esm.browser.js +589 -475
  193. package/dist/recommend.esm.node.js +379 -235
  194. package/dist/recommend.umd.js +2 -2
  195. package/dist/src/recommendClient.d.ts +131 -81
  196. package/dist/src/recommendClient.d.ts.map +1 -1
  197. package/index.js +1 -1
  198. package/model/advancedSyntaxFeatures.ts +1 -1
  199. package/model/alternativesAsExact.ts +1 -1
  200. package/model/aroundPrecision.ts +8 -0
  201. package/model/aroundPrecisionFromValueInner.ts +16 -0
  202. package/model/aroundRadius.ts +2 -2
  203. package/model/aroundRadiusAll.ts +4 -1
  204. package/model/autoFacetFilter.ts +16 -0
  205. package/model/baseRecommendRequest.ts +6 -8
  206. package/model/baseSearchParams.ts +1 -1
  207. package/model/baseSearchParamsWithoutQuery.ts +36 -46
  208. package/model/baseSearchResponse.ts +42 -31
  209. package/model/boughtTogetherQuery.ts +7 -0
  210. package/model/clientMethodProps.ts +91 -19
  211. package/model/condition.ts +16 -0
  212. package/model/consequence.ts +22 -0
  213. package/model/deletedAtResponse.ts +16 -0
  214. package/model/distinct.ts +2 -2
  215. package/model/errorBase.ts +1 -1
  216. package/model/exactOnSingleWordQuery.ts +2 -2
  217. package/model/exhaustive.ts +31 -0
  218. package/model/facetFilters.ts +2 -2
  219. package/model/facetOrdering.ts +3 -3
  220. package/model/facets.ts +3 -3
  221. package/model/facetsStats.ts +5 -5
  222. package/model/fallbackParams.ts +5 -0
  223. package/model/fbtModel.ts +6 -0
  224. package/model/frequentlyBoughtTogether.ts +12 -0
  225. package/model/getRecommendTaskResponse.ts +7 -0
  226. package/model/getRecommendationsParams.ts +3 -3
  227. package/model/getRecommendationsResponse.ts +3 -3
  228. package/model/hideConsequenceObject.ts +11 -0
  229. package/model/highlightResult.ts +5 -2
  230. package/model/highlightResultOption.ts +4 -4
  231. package/model/ignorePlurals.ts +5 -3
  232. package/model/index.ts +48 -9
  233. package/model/indexSettingsAsSearchParams.ts +54 -54
  234. package/model/lookingSimilar.ts +15 -0
  235. package/model/lookingSimilarModel.ts +6 -0
  236. package/model/lookingSimilarQuery.ts +6 -0
  237. package/model/matchLevel.ts +2 -2
  238. package/model/matchedGeoLocation.ts +1 -1
  239. package/model/mixedSearchFilters.ts +1 -1
  240. package/model/mode.ts +6 -0
  241. package/model/numericFilters.ts +2 -2
  242. package/model/optionalFilters.ts +2 -2
  243. package/model/paramsConsequence.ts +23 -0
  244. package/model/personalization.ts +1 -1
  245. package/model/promoteConsequenceObject.ts +16 -0
  246. package/model/queryType.ts +2 -2
  247. package/model/rankingInfo.ts +11 -8
  248. package/model/reRankingApplyFilter.ts +2 -2
  249. package/model/recommendHit.ts +6 -6
  250. package/model/recommendModels.ts +7 -0
  251. package/model/recommendRule.ts +31 -0
  252. package/model/recommendRuleMetadata.ts +11 -0
  253. package/model/recommendationsHit.ts +6 -0
  254. package/model/recommendationsHits.ts +7 -0
  255. package/model/recommendationsRequest.ts +14 -4
  256. package/model/recommendationsResults.ts +6 -0
  257. package/model/recommendedForYou.ts +10 -0
  258. package/model/recommendedForYouModel.ts +6 -0
  259. package/model/recommendedForYouQuery.ts +6 -0
  260. package/model/redirect.ts +10 -0
  261. package/model/redirectRuleIndexMetadata.ts +27 -0
  262. package/model/redirectRuleIndexMetadataData.ts +8 -0
  263. package/model/relatedModel.ts +6 -0
  264. package/model/relatedProducts.ts +15 -0
  265. package/model/relatedQuery.ts +6 -0
  266. package/model/removeStopWords.ts +5 -3
  267. package/model/removeWordsIfNoResults.ts +2 -2
  268. package/model/renderingContent.ts +2 -2
  269. package/model/searchParams.ts +5 -0
  270. package/model/searchParamsObject.ts +1 -1
  271. package/model/searchParamsQuery.ts +2 -2
  272. package/model/searchRecommendRulesParams.ts +46 -0
  273. package/model/searchRecommendRulesResponse.ts +25 -0
  274. package/model/semanticSearch.ts +11 -0
  275. package/model/snippetResult.ts +5 -2
  276. package/model/snippetResultOption.ts +3 -3
  277. package/model/sortRemainingBy.ts +2 -2
  278. package/model/supportedLanguage.ts +74 -0
  279. package/model/tagFilters.ts +2 -2
  280. package/model/taskStatus.ts +6 -0
  281. package/model/trendingFacetHit.ts +21 -0
  282. package/model/trendingFacets.ts +15 -0
  283. package/model/trendingFacetsModel.ts +6 -0
  284. package/model/trendingFacetsQuery.ts +6 -0
  285. package/model/trendingItems.ts +20 -0
  286. package/model/trendingItemsModel.ts +6 -0
  287. package/model/trendingItemsQuery.ts +6 -0
  288. package/model/typoTolerance.ts +2 -2
  289. package/model/typoToleranceEnum.ts +4 -1
  290. package/model/value.ts +2 -2
  291. package/package.json +10 -9
  292. package/dist/model/baseRecommendationRequest.d.ts +0 -9
  293. package/dist/model/baseRecommendationRequest.d.ts.map +0 -1
  294. package/dist/model/baseTrendingRequest.d.ts +0 -13
  295. package/dist/model/baseTrendingRequest.d.ts.map +0 -1
  296. package/dist/model/recommendHits.d.ts +0 -5
  297. package/dist/model/recommendHits.d.ts.map +0 -1
  298. package/dist/model/recommendationModels.d.ts +0 -5
  299. package/dist/model/recommendationModels.d.ts.map +0 -1
  300. package/dist/model/recommendationRequest.d.ts +0 -4
  301. package/dist/model/recommendationRequest.d.ts.map +0 -1
  302. package/dist/model/recommendationsResponse.d.ts +0 -4
  303. package/dist/model/recommendationsResponse.d.ts.map +0 -1
  304. package/dist/model/trendingModels.d.ts +0 -5
  305. package/dist/model/trendingModels.d.ts.map +0 -1
  306. package/dist/model/trendingRequest.d.ts +0 -4
  307. package/dist/model/trendingRequest.d.ts.map +0 -1
  308. package/dist/recommend.cjs.js +0 -248
  309. package/model/baseRecommendationRequest.ts +0 -12
  310. package/model/baseTrendingRequest.ts +0 -17
  311. package/model/recommendHits.ts +0 -7
  312. package/model/recommendationModels.ts +0 -6
  313. package/model/recommendationRequest.ts +0 -7
  314. package/model/recommendationsResponse.ts +0 -6
  315. package/model/trendingModels.ts +0 -6
  316. 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; // We've changed the namespace to avoid conflicts with v4, as this version is a huge breaking change
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
- const keyAsString = JSON.stringify(key);
41
- const value = getNamespace()[keyAsString];
42
- return Promise.all([value || defaultValue(), value !== undefined]);
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)] = value;
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
- return { ...host,
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); // the array and object should be frozen to reflect the stackTrace at the time of the error
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, contact support@algolia.com.', stackTrace, 'RetryError');
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, 'ApiError');
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.substr(1) : 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
- const data = Array.isArray(request.data) ? request.data : { ...request.data,
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
- message = JSON.parse(content).message;
332
- } catch (e) {// ..
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 { ...stackFrame,
367
- request: { ...stackFrame.request,
368
- headers: { ...stackFrame.request.headers,
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()); // Note, we put the hosts that previously timed out on the end of the list.
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); // On `GET`, the data is proxied to query parameters.
427
-
428
- const dataQueryParameters = request.method === 'GET' ? { ...request.data,
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 = { ...baseQueryParameters,
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); // If response is a timeout, we increase the number of timeouts so we can increase the timeout later.
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
- // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
728
- const apiClientVersion = '5.0.0-alpha.11';
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
- * @summary Send requests to the Algolia REST API.
814
- * @param del - The del object.
815
- * @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
816
- * @param del.parameters - Query parameters to be applied to the current query.
817
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
818
- */
819
- del({ path, parameters }, requestOptions) {
820
- if (!path) {
821
- throw new Error('Parameter `path` is required when calling `del`.');
822
- }
823
- const requestPath = '/1{path}'.replace('{path}', path);
824
- const headers = {};
825
- const queryParameters = parameters ? parameters : {};
826
- const request = {
827
- method: 'DELETE',
828
- path: requestPath,
829
- queryParameters,
830
- headers,
831
- };
832
- return transporter.request(request, requestOptions);
833
- },
834
- /**
835
- * This method allow you to send requests to the Algolia REST API.
836
- *
837
- * @summary Send requests to the Algolia REST API.
838
- * @param get - The get object.
839
- * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
840
- * @param get.parameters - Query parameters to be applied to the current query.
841
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
842
- */
843
- get({ path, parameters }, requestOptions) {
844
- if (!path) {
845
- throw new Error('Parameter `path` is required when calling `get`.');
846
- }
847
- const requestPath = '/1{path}'.replace('{path}', path);
848
- const headers = {};
849
- const queryParameters = parameters ? parameters : {};
850
- const request = {
851
- method: 'GET',
852
- path: requestPath,
853
- queryParameters,
854
- headers,
855
- };
856
- return transporter.request(request, requestOptions);
857
- },
858
- /**
859
- * Returns recommendations or trending results, for a specific model and `objectID`.
860
- *
861
- * @summary Get results.
862
- * @param getRecommendationsParams - The getRecommendationsParams object.
863
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
864
- */
865
- getRecommendations(getRecommendationsParams, requestOptions) {
866
- if (!getRecommendationsParams) {
867
- throw new Error('Parameter `getRecommendationsParams` is required when calling `getRecommendations`.');
868
- }
869
- if (!getRecommendationsParams.requests) {
870
- throw new Error('Parameter `getRecommendationsParams.requests` is required when calling `getRecommendations`.');
871
- }
872
- const requestPath = '/1/indexes/*/recommendations';
873
- const headers = {};
874
- const queryParameters = {};
875
- const request = {
876
- method: 'POST',
877
- path: requestPath,
878
- queryParameters,
879
- headers,
880
- data: getRecommendationsParams,
881
- useReadTransporter: true,
882
- cacheable: true,
883
- };
884
- return transporter.request(request, requestOptions);
885
- },
886
- /**
887
- * This method allow you to send requests to the Algolia REST API.
888
- *
889
- * @summary Send requests to the Algolia REST API.
890
- * @param post - The post object.
891
- * @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
892
- * @param post.parameters - Query parameters to be applied to the current query.
893
- * @param post.body - The parameters to send with the custom request.
894
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
895
- */
896
- post({ path, parameters, body }, requestOptions) {
897
- if (!path) {
898
- throw new Error('Parameter `path` is required when calling `post`.');
899
- }
900
- const requestPath = '/1{path}'.replace('{path}', path);
901
- const headers = {};
902
- const queryParameters = parameters ? parameters : {};
903
- const request = {
904
- method: 'POST',
905
- path: requestPath,
906
- queryParameters,
907
- headers,
908
- data: body ? body : {},
909
- };
910
- return transporter.request(request, requestOptions);
911
- },
912
- /**
913
- * This method allow you to send requests to the Algolia REST API.
914
- *
915
- * @summary Send requests to the Algolia REST API.
916
- * @param put - The put object.
917
- * @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified.
918
- * @param put.parameters - Query parameters to be applied to the current query.
919
- * @param put.body - The parameters to send with the custom request.
920
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
921
- */
922
- put({ path, parameters, body }, requestOptions) {
923
- if (!path) {
924
- throw new Error('Parameter `path` is required when calling `put`.');
925
- }
926
- const requestPath = '/1{path}'.replace('{path}', path);
927
- const headers = {};
928
- const queryParameters = parameters ? parameters : {};
929
- const request = {
930
- method: 'PUT',
931
- path: requestPath,
932
- queryParameters,
933
- headers,
934
- data: body ? body : {},
935
- };
936
- return transporter.request(request, requestOptions);
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.111';
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
+ * Deletes a Recommend rule from a recommendation scenario.
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 model](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
+ * Retrieves a Recommend rule that you previously created in the Algolia dashboard.
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 model](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
+ * Checks the status of a given task. Deleting a Recommend rule is asynchronous. When you delete a rule, a task is created on a queue and completed depending on the load on the server. The API response includes a task ID that you can use to check the status.
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 model](https://www.algolia.com/doc/guides/algolia-recommend/overview/#recommend-models).
959
+ * @param getRecommendStatus.taskID - Unique task identifier.
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
+ * Retrieves recommendations from selected AI models.
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
+ * Searches for Recommend rules. Use an empty query to list all rules for this recommendation scenario.
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 model](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
- // This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation.
942
- function recommendClient(appId, apiKey, options) {
943
- if (!appId || typeof appId !== 'string') {
944
- throw new Error('`appId` is missing.');
945
- }
946
- if (!apiKey || typeof apiKey !== 'string') {
947
- throw new Error('`apiKey` is missing.');
948
- }
949
- return createRecommendClient({
950
- appId,
951
- apiKey,
952
- timeouts: {
953
- connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
954
- read: DEFAULT_READ_TIMEOUT_BROWSER,
955
- write: DEFAULT_WRITE_TIMEOUT_BROWSER,
956
- },
957
- requester: createXhrRequester(),
958
- algoliaAgents: [{ segment: 'Browser' }],
959
- authMode: 'WithinQueryParameters',
960
- responsesCache: createMemoryCache(),
961
- requestsCache: createMemoryCache({ serializable: false }),
962
- hostsCache: createFallbackableCache({
963
- caches: [
964
- createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }),
965
- createMemoryCache(),
966
- ],
967
- }),
968
- ...options,
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 };