@nanoporetech-digital/components 5.2.1 → 5.3.0

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 (259) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/{_commonjsHelpers-9f2314fc.js → _commonjsHelpers-29614748.js} +1 -17
  3. package/dist/cjs/_commonjsHelpers-29614748.js.map +1 -0
  4. package/dist/cjs/algoliasearch-lite.esm.browser-992a2eff.js +922 -0
  5. package/dist/cjs/algoliasearch-lite.esm.browser-992a2eff.js.map +1 -0
  6. package/dist/cjs/component-store-21cb4901.js +328 -0
  7. package/dist/cjs/component-store-21cb4901.js.map +1 -0
  8. package/dist/cjs/events-db0a42ee.js +39 -0
  9. package/dist/cjs/events-db0a42ee.js.map +1 -0
  10. package/dist/cjs/loader.cjs.js +1 -1
  11. package/dist/cjs/nano-alert.cjs.entry.js +9 -2
  12. package/dist/cjs/nano-alert.cjs.entry.js.map +1 -1
  13. package/dist/cjs/nano-algolia-filter.cjs.entry.js +1 -2
  14. package/dist/cjs/nano-algolia-filter.cjs.entry.js.map +1 -1
  15. package/dist/cjs/nano-algolia-input.cjs.entry.js +8 -4
  16. package/dist/cjs/nano-algolia-input.cjs.entry.js.map +1 -1
  17. package/dist/cjs/nano-algolia.cjs.entry.js +4 -4
  18. package/dist/cjs/nano-algolia.cjs.entry.js.map +1 -1
  19. package/dist/cjs/nano-components.cjs.js +1 -1
  20. package/dist/cjs/nano-datalist_3.cjs.entry.js +1 -1
  21. package/dist/cjs/nano-dialog.cjs.entry.js +23 -22
  22. package/dist/cjs/nano-dialog.cjs.entry.js.map +1 -1
  23. package/dist/cjs/nano-drawer.cjs.entry.js +169 -111
  24. package/dist/cjs/nano-drawer.cjs.entry.js.map +1 -1
  25. package/dist/cjs/nano-dropdown.cjs.entry.js +16 -2
  26. package/dist/cjs/nano-dropdown.cjs.entry.js.map +1 -1
  27. package/dist/cjs/nano-global-nav.cjs.entry.js +5 -6
  28. package/dist/cjs/nano-global-nav.cjs.entry.js.map +1 -1
  29. package/dist/cjs/nano-global-search-results.cjs.entry.js +2 -1
  30. package/dist/cjs/nano-global-search-results.cjs.entry.js.map +1 -1
  31. package/dist/cjs/nano-slides.cjs.entry.js +1 -1
  32. package/dist/cjs/nano-sortable.cjs.entry.js +3 -15
  33. package/dist/cjs/nano-sortable.cjs.entry.js.map +1 -1
  34. package/dist/cjs/nano-sticker.cjs.entry.js +16 -9
  35. package/dist/cjs/nano-sticker.cjs.entry.js.map +1 -1
  36. package/dist/cjs/nano-tab-group.cjs.entry.js +1 -2
  37. package/dist/cjs/nano-tab-group.cjs.entry.js.map +1 -1
  38. package/dist/cjs/{nano-table-10a40ab3.js → nano-table-e15cc6b0.js} +6 -6
  39. package/dist/cjs/nano-table-e15cc6b0.js.map +1 -0
  40. package/dist/cjs/nano-table.cjs.entry.js +1 -1
  41. package/dist/cjs/{slot-a448c1a7.js → slot-2dd6ed1d.js} +20 -15
  42. package/dist/cjs/slot-2dd6ed1d.js.map +1 -0
  43. package/dist/cjs/{table.worker-f04588c1.js → table.worker-8759e6ea.js} +2 -2
  44. package/dist/cjs/table.worker-8759e6ea.js.map +1 -0
  45. package/dist/collection/components/alert/alert.css +15 -0
  46. package/dist/collection/components/alert/alert.js +10 -2
  47. package/dist/collection/components/alert/alert.js.map +1 -1
  48. package/dist/collection/components/algolia/algolia-interface.js.map +1 -1
  49. package/dist/collection/components/algolia/algolia.js +1 -1
  50. package/dist/collection/components/algolia/algolia.js.map +1 -1
  51. package/dist/collection/components/dialog/dialog.css +1 -17
  52. package/dist/collection/components/dialog/dialog.js +31 -20
  53. package/dist/collection/components/dialog/dialog.js.map +1 -1
  54. package/dist/collection/components/drawer/drawer.css +136 -67
  55. package/dist/collection/components/drawer/drawer.js +282 -154
  56. package/dist/collection/components/drawer/drawer.js.map +1 -1
  57. package/dist/collection/components/dropdown/dropdown.css +10 -0
  58. package/dist/collection/components/dropdown/dropdown.js +15 -1
  59. package/dist/collection/components/dropdown/dropdown.js.map +1 -1
  60. package/dist/collection/components/global-nav/global-nav.js +2 -2
  61. package/dist/collection/components/global-nav/global-nav.js.map +1 -1
  62. package/dist/collection/components/global-nav/style/global-nav.css +5 -1
  63. package/dist/collection/components/global-search-results/global-search-results.js +2 -1
  64. package/dist/collection/components/global-search-results/global-search-results.js.map +1 -1
  65. package/dist/collection/components/sticker/sticker.js +16 -9
  66. package/dist/collection/components/sticker/sticker.js.map +1 -1
  67. package/dist/collection/components/table/table.pin-service.js +4 -4
  68. package/dist/collection/components/table/table.pin-service.js.map +1 -1
  69. package/dist/collection/utils/events.js +17 -0
  70. package/dist/collection/utils/events.js.map +1 -1
  71. package/dist/collection/utils/slot.js +19 -14
  72. package/dist/collection/utils/slot.js.map +1 -1
  73. package/dist/collection/utils/store/get-set.js +6 -12
  74. package/dist/collection/utils/store/get-set.js.map +1 -1
  75. package/dist/components/_commonjsHelpers.js +1 -16
  76. package/dist/components/_commonjsHelpers.js.map +1 -1
  77. package/dist/components/algolia.js +2 -2
  78. package/dist/components/algolia.js.map +1 -1
  79. package/dist/components/algoliasearch-lite.esm.browser.js +920 -0
  80. package/dist/components/algoliasearch-lite.esm.browser.js.map +1 -0
  81. package/dist/components/component-store.js +68 -2001
  82. package/dist/components/component-store.js.map +1 -1
  83. package/dist/components/dropdown.js +16 -2
  84. package/dist/components/dropdown.js.map +1 -1
  85. package/dist/components/events.js +36 -0
  86. package/dist/components/events.js.map +1 -0
  87. package/dist/components/nano-alert.js +10 -2
  88. package/dist/components/nano-alert.js.map +1 -1
  89. package/dist/components/nano-algolia-input.js +6 -1
  90. package/dist/components/nano-algolia-input.js.map +1 -1
  91. package/dist/components/nano-dialog.js +21 -20
  92. package/dist/components/nano-dialog.js.map +1 -1
  93. package/dist/components/nano-drawer.js +205 -122
  94. package/dist/components/nano-drawer.js.map +1 -1
  95. package/dist/components/nano-global-nav.js +4 -4
  96. package/dist/components/nano-global-nav.js.map +1 -1
  97. package/dist/components/nano-global-search-results.js +2 -1
  98. package/dist/components/nano-global-search-results.js.map +1 -1
  99. package/dist/components/nano-sortable.js +1 -13
  100. package/dist/components/nano-sortable.js.map +1 -1
  101. package/dist/components/slot.js +19 -14
  102. package/dist/components/slot.js.map +1 -1
  103. package/dist/components/sticker.js +16 -9
  104. package/dist/components/sticker.js.map +1 -1
  105. package/dist/components/table.js +4 -4
  106. package/dist/components/table.js.map +1 -1
  107. package/dist/esm/{_commonjsHelpers-e401b2a2.js → _commonjsHelpers-04a0e019.js} +2 -17
  108. package/dist/esm/_commonjsHelpers-04a0e019.js.map +1 -0
  109. package/dist/esm/algoliasearch-lite.esm.browser-04891fdc.js +920 -0
  110. package/dist/esm/algoliasearch-lite.esm.browser-04891fdc.js.map +1 -0
  111. package/dist/esm/component-store-65d7e36a.js +326 -0
  112. package/dist/esm/component-store-65d7e36a.js.map +1 -0
  113. package/dist/esm/events-6a805b42.js +36 -0
  114. package/dist/esm/events-6a805b42.js.map +1 -0
  115. package/dist/esm/loader.js +1 -1
  116. package/dist/esm/nano-alert.entry.js +9 -2
  117. package/dist/esm/nano-alert.entry.js.map +1 -1
  118. package/dist/esm/nano-algolia-filter.entry.js +1 -2
  119. package/dist/esm/nano-algolia-filter.entry.js.map +1 -1
  120. package/dist/esm/nano-algolia-input.entry.js +7 -3
  121. package/dist/esm/nano-algolia-input.entry.js.map +1 -1
  122. package/dist/esm/nano-algolia.entry.js +4 -4
  123. package/dist/esm/nano-algolia.entry.js.map +1 -1
  124. package/dist/esm/nano-components.js +1 -1
  125. package/dist/esm/nano-datalist_3.entry.js +1 -1
  126. package/dist/esm/nano-dialog.entry.js +23 -22
  127. package/dist/esm/nano-dialog.entry.js.map +1 -1
  128. package/dist/esm/nano-drawer.entry.js +171 -113
  129. package/dist/esm/nano-drawer.entry.js.map +1 -1
  130. package/dist/esm/nano-dropdown.entry.js +16 -2
  131. package/dist/esm/nano-dropdown.entry.js.map +1 -1
  132. package/dist/esm/nano-global-nav.entry.js +5 -6
  133. package/dist/esm/nano-global-nav.entry.js.map +1 -1
  134. package/dist/esm/nano-global-search-results.entry.js +2 -1
  135. package/dist/esm/nano-global-search-results.entry.js.map +1 -1
  136. package/dist/esm/nano-slides.entry.js +1 -1
  137. package/dist/esm/nano-sortable.entry.js +1 -13
  138. package/dist/esm/nano-sortable.entry.js.map +1 -1
  139. package/dist/esm/nano-sticker.entry.js +16 -9
  140. package/dist/esm/nano-sticker.entry.js.map +1 -1
  141. package/dist/esm/nano-tab-group.entry.js +1 -2
  142. package/dist/esm/nano-tab-group.entry.js.map +1 -1
  143. package/dist/esm/{nano-table-2bbcaa8d.js → nano-table-5c5bd3f2.js} +6 -6
  144. package/dist/esm/nano-table-5c5bd3f2.js.map +1 -0
  145. package/dist/esm/nano-table.entry.js +1 -1
  146. package/dist/esm/{slot-a4f6e2af.js → slot-8126e238.js} +20 -15
  147. package/dist/esm/slot-8126e238.js.map +1 -0
  148. package/dist/esm/{table.worker-7324ad73.js → table.worker-e7f4f50c.js} +2 -2
  149. package/dist/esm/table.worker-e7f4f50c.js.map +1 -0
  150. package/dist/nano-components/nano-components.css +1 -1
  151. package/dist/nano-components/nano-components.esm.js +1 -1
  152. package/dist/nano-components/nano-components.esm.js.map +1 -1
  153. package/dist/nano-components/p-0301e8f7.entry.js +5 -0
  154. package/dist/nano-components/p-0301e8f7.entry.js.map +1 -0
  155. package/dist/nano-components/p-27422aa9.entry.js +5 -0
  156. package/dist/nano-components/{p-6920ad69.entry.js.map → p-27422aa9.entry.js.map} +1 -1
  157. package/dist/nano-components/{p-52ae36ec.js → p-2d79f5b3.js} +2 -2
  158. package/dist/nano-components/{p-0697795a.entry.js → p-31c23d6e.entry.js} +2 -2
  159. package/dist/nano-components/p-31c23d6e.entry.js.map +1 -0
  160. package/dist/nano-components/p-487de04d.entry.js.map +1 -1
  161. package/dist/nano-components/p-570d2e50.entry.js +5 -0
  162. package/dist/nano-components/p-570d2e50.entry.js.map +1 -0
  163. package/dist/nano-components/{p-3eb6d833.entry.js → p-5a4b3fa9.entry.js} +2 -2
  164. package/dist/nano-components/p-653ae985.js +5 -0
  165. package/dist/nano-components/p-653ae985.js.map +1 -0
  166. package/dist/nano-components/p-676a4744.entry.js +5 -0
  167. package/dist/nano-components/{p-d0eefd52.entry.js.map → p-676a4744.entry.js.map} +1 -1
  168. package/dist/nano-components/p-8fe51abf.js +5 -0
  169. package/dist/nano-components/{p-4884b65a.entry.js → p-90cd4f56.entry.js} +2 -2
  170. package/dist/nano-components/p-90cd4f56.entry.js.map +1 -0
  171. package/dist/nano-components/p-9ba81ed2.js +5 -0
  172. package/dist/nano-components/p-9ba81ed2.js.map +1 -0
  173. package/dist/nano-components/p-9bfdee71.js +5 -0
  174. package/dist/nano-components/p-9bfdee71.js.map +1 -0
  175. package/dist/nano-components/p-a8d6ca38.entry.js +5 -0
  176. package/dist/nano-components/p-a8d6ca38.entry.js.map +1 -0
  177. package/dist/nano-components/p-ace7743c.entry.js +5 -0
  178. package/dist/nano-components/p-ace7743c.entry.js.map +1 -0
  179. package/dist/nano-components/{p-39aec880.entry.js → p-bab2888b.entry.js} +2 -2
  180. package/dist/nano-components/p-bdb5b6fc.entry.js +5 -0
  181. package/dist/nano-components/p-bdb5b6fc.entry.js.map +1 -0
  182. package/dist/nano-components/p-cad86fb8.js +5 -0
  183. package/dist/nano-components/p-cad86fb8.js.map +1 -0
  184. package/dist/nano-components/p-dc565459.js +5 -0
  185. package/dist/nano-components/p-dc565459.js.map +1 -0
  186. package/dist/nano-components/p-ede12d35.entry.js +5 -0
  187. package/dist/nano-components/p-ede12d35.entry.js.map +1 -0
  188. package/dist/nano-components/p-f504b1df.entry.js +7 -0
  189. package/dist/nano-components/p-f504b1df.entry.js.map +1 -0
  190. package/dist/nano-components/{p-db370094.entry.js → p-f7a4c62b.entry.js} +2 -2
  191. package/dist/themes/london-calling.css.map +1 -1
  192. package/dist/themes/nanopore.cn.css.map +1 -1
  193. package/dist/themes/nanopore.css.map +1 -1
  194. package/dist/types/components/alert/alert.d.ts +1 -0
  195. package/dist/types/components/algolia/algolia-interface.d.ts +1 -1
  196. package/dist/types/components/algolia/algolia.d.ts +1 -1
  197. package/dist/types/components/dialog/dialog.d.ts +15 -4
  198. package/dist/types/components/drawer/drawer.d.ts +69 -50
  199. package/dist/types/components/sticker/sticker.d.ts +4 -4
  200. package/dist/types/components.d.ts +50 -28
  201. package/dist/types/types/algolia.d.ts +4 -0
  202. package/dist/types/types/scss.vars.d.ts +4 -0
  203. package/dist/types/utils/events.d.ts +7 -0
  204. package/dist/types/utils/slot.d.ts +3 -3
  205. package/docs-json.json +268 -61
  206. package/docs-vscode.json +28 -11
  207. package/hydrate/index.js +1335 -2236
  208. package/package.json +4 -4
  209. package/dist/cjs/_commonjsHelpers-9f2314fc.js.map +0 -1
  210. package/dist/cjs/algoliasearch.umd-689c1560.js +0 -15
  211. package/dist/cjs/algoliasearch.umd-689c1560.js.map +0 -1
  212. package/dist/cjs/component-store-f1dc1276.js +0 -2261
  213. package/dist/cjs/component-store-f1dc1276.js.map +0 -1
  214. package/dist/cjs/nano-table-10a40ab3.js.map +0 -1
  215. package/dist/cjs/slot-a448c1a7.js.map +0 -1
  216. package/dist/cjs/table.worker-f04588c1.js.map +0 -1
  217. package/dist/components/algoliasearch.umd.js +0 -13
  218. package/dist/components/algoliasearch.umd.js.map +0 -1
  219. package/dist/esm/_commonjsHelpers-e401b2a2.js.map +0 -1
  220. package/dist/esm/algoliasearch.umd-4f7efa84.js +0 -13
  221. package/dist/esm/algoliasearch.umd-4f7efa84.js.map +0 -1
  222. package/dist/esm/component-store-c23ebc9c.js +0 -2259
  223. package/dist/esm/component-store-c23ebc9c.js.map +0 -1
  224. package/dist/esm/nano-table-2bbcaa8d.js.map +0 -1
  225. package/dist/esm/slot-a4f6e2af.js.map +0 -1
  226. package/dist/esm/table.worker-7324ad73.js.map +0 -1
  227. package/dist/nano-components/p-0697795a.entry.js.map +0 -1
  228. package/dist/nano-components/p-17b099cc.entry.js +0 -5
  229. package/dist/nano-components/p-17b099cc.entry.js.map +0 -1
  230. package/dist/nano-components/p-1a0b5bc3.js +0 -5
  231. package/dist/nano-components/p-1a0b5bc3.js.map +0 -1
  232. package/dist/nano-components/p-4884b65a.entry.js.map +0 -1
  233. package/dist/nano-components/p-58cf5446.js +0 -5
  234. package/dist/nano-components/p-58cf5446.js.map +0 -1
  235. package/dist/nano-components/p-6920ad69.entry.js +0 -5
  236. package/dist/nano-components/p-69a3e911.js +0 -5
  237. package/dist/nano-components/p-7baa9e14.entry.js +0 -5
  238. package/dist/nano-components/p-7baa9e14.entry.js.map +0 -1
  239. package/dist/nano-components/p-9b533dc3.js +0 -5
  240. package/dist/nano-components/p-9b533dc3.js.map +0 -1
  241. package/dist/nano-components/p-a362bd23.entry.js +0 -5
  242. package/dist/nano-components/p-a362bd23.entry.js.map +0 -1
  243. package/dist/nano-components/p-b04fd7ca.entry.js +0 -5
  244. package/dist/nano-components/p-b04fd7ca.entry.js.map +0 -1
  245. package/dist/nano-components/p-b72df1aa.entry.js +0 -5
  246. package/dist/nano-components/p-b72df1aa.entry.js.map +0 -1
  247. package/dist/nano-components/p-ce5efc3f.entry.js +0 -5
  248. package/dist/nano-components/p-ce5efc3f.entry.js.map +0 -1
  249. package/dist/nano-components/p-d0eefd52.entry.js +0 -5
  250. package/dist/nano-components/p-e2b2b015.entry.js +0 -5
  251. package/dist/nano-components/p-e2b2b015.entry.js.map +0 -1
  252. package/dist/nano-components/p-ed6adde2.js +0 -7
  253. package/dist/nano-components/p-ed6adde2.js.map +0 -1
  254. package/dist/types/dom.ie.d.ts +0 -3
  255. /package/dist/nano-components/{p-39aec880.entry.js.map → p-2d79f5b3.js.map} +0 -0
  256. /package/dist/nano-components/{p-3eb6d833.entry.js.map → p-5a4b3fa9.entry.js.map} +0 -0
  257. /package/dist/nano-components/{p-52ae36ec.js.map → p-8fe51abf.js.map} +0 -0
  258. /package/dist/nano-components/{p-69a3e911.js.map → p-bab2888b.entry.js.map} +0 -0
  259. /package/dist/nano-components/{p-db370094.entry.js.map → p-f7a4c62b.entry.js.map} +0 -0
@@ -0,0 +1,922 @@
1
+ /*!
2
+ * Web Components for Nanopore digital Web Apps
3
+ */
4
+ 'use strict';
5
+
6
+ function createBrowserLocalStorageCache(options) {
7
+ const namespaceKey = `algoliasearch-client-js-${options.key}`;
8
+ // eslint-disable-next-line functional/no-let
9
+ let storage;
10
+ const getStorage = () => {
11
+ if (storage === undefined) {
12
+ storage = options.localStorage || window.localStorage;
13
+ }
14
+ return storage;
15
+ };
16
+ const getNamespace = () => {
17
+ return JSON.parse(getStorage().getItem(namespaceKey) || '{}');
18
+ };
19
+ return {
20
+ get(key, defaultValue, events = {
21
+ miss: () => Promise.resolve(),
22
+ }) {
23
+ return Promise.resolve()
24
+ .then(() => {
25
+ const keyAsString = JSON.stringify(key);
26
+ const value = getNamespace()[keyAsString];
27
+ return Promise.all([value || defaultValue(), value !== undefined]);
28
+ })
29
+ .then(([value, exists]) => {
30
+ return Promise.all([value, exists || events.miss(value)]);
31
+ })
32
+ .then(([value]) => value);
33
+ },
34
+ set(key, value) {
35
+ return Promise.resolve().then(() => {
36
+ const namespace = getNamespace();
37
+ // eslint-disable-next-line functional/immutable-data
38
+ namespace[JSON.stringify(key)] = value;
39
+ getStorage().setItem(namespaceKey, JSON.stringify(namespace));
40
+ return value;
41
+ });
42
+ },
43
+ delete(key) {
44
+ return Promise.resolve().then(() => {
45
+ const namespace = getNamespace();
46
+ // eslint-disable-next-line functional/immutable-data
47
+ delete namespace[JSON.stringify(key)];
48
+ getStorage().setItem(namespaceKey, JSON.stringify(namespace));
49
+ });
50
+ },
51
+ clear() {
52
+ return Promise.resolve().then(() => {
53
+ getStorage().removeItem(namespaceKey);
54
+ });
55
+ },
56
+ };
57
+ }
58
+
59
+ // @todo Add logger on options to debug when caches go wrong.
60
+ function createFallbackableCache(options) {
61
+ const caches = [...options.caches];
62
+ const current = caches.shift(); // eslint-disable-line functional/immutable-data
63
+ if (current === undefined) {
64
+ return createNullCache();
65
+ }
66
+ return {
67
+ get(key, defaultValue, events = {
68
+ miss: () => Promise.resolve(),
69
+ }) {
70
+ return current.get(key, defaultValue, events).catch(() => {
71
+ return createFallbackableCache({ caches }).get(key, defaultValue, events);
72
+ });
73
+ },
74
+ set(key, value) {
75
+ return current.set(key, value).catch(() => {
76
+ return createFallbackableCache({ caches }).set(key, value);
77
+ });
78
+ },
79
+ delete(key) {
80
+ return current.delete(key).catch(() => {
81
+ return createFallbackableCache({ caches }).delete(key);
82
+ });
83
+ },
84
+ clear() {
85
+ return current.clear().catch(() => {
86
+ return createFallbackableCache({ caches }).clear();
87
+ });
88
+ },
89
+ };
90
+ }
91
+
92
+ function createNullCache() {
93
+ return {
94
+ get(_key, defaultValue, events = {
95
+ miss: () => Promise.resolve(),
96
+ }) {
97
+ const value = defaultValue();
98
+ return value
99
+ .then(result => Promise.all([result, events.miss(result)]))
100
+ .then(([result]) => result);
101
+ },
102
+ set(_key, value) {
103
+ return Promise.resolve(value);
104
+ },
105
+ delete(_key) {
106
+ return Promise.resolve();
107
+ },
108
+ clear() {
109
+ return Promise.resolve();
110
+ },
111
+ };
112
+ }
113
+
114
+ function createInMemoryCache(options = { serializable: true }) {
115
+ // eslint-disable-next-line functional/no-let
116
+ let cache = {};
117
+ return {
118
+ get(key, defaultValue, events = {
119
+ miss: () => Promise.resolve(),
120
+ }) {
121
+ const keyAsString = JSON.stringify(key);
122
+ if (keyAsString in cache) {
123
+ return Promise.resolve(options.serializable ? JSON.parse(cache[keyAsString]) : cache[keyAsString]);
124
+ }
125
+ const promise = defaultValue();
126
+ const miss = (events && events.miss) || (() => Promise.resolve());
127
+ return promise.then((value) => miss(value)).then(() => promise);
128
+ },
129
+ set(key, value) {
130
+ // eslint-disable-next-line functional/immutable-data
131
+ cache[JSON.stringify(key)] = options.serializable ? JSON.stringify(value) : value;
132
+ return Promise.resolve(value);
133
+ },
134
+ delete(key) {
135
+ // eslint-disable-next-line functional/immutable-data
136
+ delete cache[JSON.stringify(key)];
137
+ return Promise.resolve();
138
+ },
139
+ clear() {
140
+ cache = {};
141
+ return Promise.resolve();
142
+ },
143
+ };
144
+ }
145
+
146
+ function createAuth(authMode, appId, apiKey) {
147
+ const credentials = {
148
+ 'x-algolia-api-key': apiKey,
149
+ 'x-algolia-application-id': appId,
150
+ };
151
+ return {
152
+ headers() {
153
+ return authMode === AuthMode.WithinHeaders ? credentials : {};
154
+ },
155
+ queryParameters() {
156
+ return authMode === AuthMode.WithinQueryParameters ? credentials : {};
157
+ },
158
+ };
159
+ }
160
+
161
+ // eslint-disable-next-line functional/prefer-readonly-type
162
+ function shuffle(array) {
163
+ let c = array.length - 1; // eslint-disable-line functional/no-let
164
+ // eslint-disable-next-line functional/no-loop-statement
165
+ for (c; c > 0; c--) {
166
+ const b = Math.floor(Math.random() * (c + 1));
167
+ const a = array[c];
168
+ array[c] = array[b]; // eslint-disable-line functional/immutable-data, no-param-reassign
169
+ array[b] = a; // eslint-disable-line functional/immutable-data, no-param-reassign
170
+ }
171
+ return array;
172
+ }
173
+ function addMethods(base, methods) {
174
+ if (!methods) {
175
+ return base;
176
+ }
177
+ Object.keys(methods).forEach(key => {
178
+ // eslint-disable-next-line functional/immutable-data, no-param-reassign
179
+ base[key] = methods[key](base);
180
+ });
181
+ return base;
182
+ }
183
+ function encode(format, ...args) {
184
+ // eslint-disable-next-line functional/no-let
185
+ let i = 0;
186
+ return format.replace(/%s/g, () => encodeURIComponent(args[i++]));
187
+ }
188
+
189
+ const version = '4.14.3';
190
+
191
+ const AuthMode = {
192
+ /**
193
+ * If auth credentials should be in query parameters.
194
+ */
195
+ WithinQueryParameters: 0,
196
+ /**
197
+ * If auth credentials should be in headers.
198
+ */
199
+ WithinHeaders: 1,
200
+ };
201
+
202
+ function createMappedRequestOptions(requestOptions, timeout) {
203
+ const options = requestOptions || {};
204
+ const data = options.data || {};
205
+ Object.keys(options).forEach(key => {
206
+ if (['timeout', 'headers', 'queryParameters', 'data', 'cacheable'].indexOf(key) === -1) {
207
+ data[key] = options[key]; // eslint-disable-line functional/immutable-data
208
+ }
209
+ });
210
+ return {
211
+ data: Object.entries(data).length > 0 ? data : undefined,
212
+ timeout: options.timeout || timeout,
213
+ headers: options.headers || {},
214
+ queryParameters: options.queryParameters || {},
215
+ cacheable: options.cacheable,
216
+ };
217
+ }
218
+
219
+ const CallEnum = {
220
+ /**
221
+ * If the host is read only.
222
+ */
223
+ Read: 1,
224
+ /**
225
+ * If the host is write only.
226
+ */
227
+ Write: 2,
228
+ /**
229
+ * If the host is both read and write.
230
+ */
231
+ Any: 3,
232
+ };
233
+
234
+ const HostStatusEnum = {
235
+ Up: 1,
236
+ Down: 2,
237
+ Timeouted: 3,
238
+ };
239
+
240
+ // By default, API Clients at Algolia have expiration delay
241
+ // of 5 mins. In the JavaScript client, we have 2 mins.
242
+ const EXPIRATION_DELAY = 2 * 60 * 1000;
243
+ function createStatefulHost(host, status = HostStatusEnum.Up) {
244
+ return {
245
+ ...host,
246
+ status,
247
+ lastUpdate: Date.now(),
248
+ };
249
+ }
250
+ function isStatefulHostUp(host) {
251
+ return host.status === HostStatusEnum.Up || Date.now() - host.lastUpdate > EXPIRATION_DELAY;
252
+ }
253
+ function isStatefulHostTimeouted(host) {
254
+ return (host.status === HostStatusEnum.Timeouted && Date.now() - host.lastUpdate <= EXPIRATION_DELAY);
255
+ }
256
+
257
+ function createStatelessHost(options) {
258
+ if (typeof options === 'string') {
259
+ return {
260
+ protocol: 'https',
261
+ url: options,
262
+ accept: CallEnum.Any,
263
+ };
264
+ }
265
+ return {
266
+ protocol: options.protocol || 'https',
267
+ url: options.url,
268
+ accept: options.accept || CallEnum.Any,
269
+ };
270
+ }
271
+
272
+ const MethodEnum = {
273
+ Delete: 'DELETE',
274
+ Get: 'GET',
275
+ Post: 'POST',
276
+ Put: 'PUT',
277
+ };
278
+
279
+ function createRetryableOptions(hostsCache, statelessHosts) {
280
+ return Promise.all(statelessHosts.map(statelessHost => {
281
+ return hostsCache.get(statelessHost, () => {
282
+ return Promise.resolve(createStatefulHost(statelessHost));
283
+ });
284
+ })).then(statefulHosts => {
285
+ const hostsUp = statefulHosts.filter(host => isStatefulHostUp(host));
286
+ const hostsTimeouted = statefulHosts.filter(host => isStatefulHostTimeouted(host));
287
+ /**
288
+ * Note, we put the hosts that previously timeouted on the end of the list.
289
+ */
290
+ const hostsAvailable = [...hostsUp, ...hostsTimeouted];
291
+ const statelessHostsAvailable = hostsAvailable.length > 0
292
+ ? hostsAvailable.map(host => createStatelessHost(host))
293
+ : statelessHosts;
294
+ return {
295
+ getTimeout(timeoutsCount, baseTimeout) {
296
+ /**
297
+ * Imagine that you have 4 hosts, if timeouts will increase
298
+ * on the following way: 1 (timeouted) > 4 (timeouted) > 5 (200)
299
+ *
300
+ * Note that, the very next request, we start from the previous timeout
301
+ *
302
+ * 5 (timeouted) > 6 (timeouted) > 7 ...
303
+ *
304
+ * This strategy may need to be reviewed, but is the strategy on the our
305
+ * current v3 version.
306
+ */
307
+ const timeoutMultiplier = hostsTimeouted.length === 0 && timeoutsCount === 0
308
+ ? 1
309
+ : hostsTimeouted.length + 3 + timeoutsCount;
310
+ return timeoutMultiplier * baseTimeout;
311
+ },
312
+ statelessHosts: statelessHostsAvailable,
313
+ };
314
+ });
315
+ }
316
+
317
+ const isNetworkError = ({ isTimedOut, status }) => {
318
+ return !isTimedOut && ~~status === 0;
319
+ };
320
+ const isRetryable = (response) => {
321
+ const status = response.status;
322
+ const isTimedOut = response.isTimedOut;
323
+ return (isTimedOut || isNetworkError(response) || (~~(status / 100) !== 2 && ~~(status / 100) !== 4));
324
+ };
325
+ const isSuccess = ({ status }) => {
326
+ return ~~(status / 100) === 2;
327
+ };
328
+ const retryDecision = (response, outcomes) => {
329
+ if (isRetryable(response)) {
330
+ return outcomes.onRetry(response);
331
+ }
332
+ if (isSuccess(response)) {
333
+ return outcomes.onSuccess(response);
334
+ }
335
+ return outcomes.onFail(response);
336
+ };
337
+
338
+ function retryableRequest(transporter, statelessHosts, request, requestOptions) {
339
+ const stackTrace = []; // eslint-disable-line functional/prefer-readonly-type
340
+ /**
341
+ * First we prepare the payload that do not depend from hosts.
342
+ */
343
+ const data = serializeData(request, requestOptions);
344
+ const headers = serializeHeaders(transporter, requestOptions);
345
+ const method = request.method;
346
+ // On `GET`, the data is proxied to query parameters.
347
+ const dataQueryParameters = request.method !== MethodEnum.Get
348
+ ? {}
349
+ : {
350
+ ...request.data,
351
+ ...requestOptions.data,
352
+ };
353
+ const queryParameters = {
354
+ 'x-algolia-agent': transporter.userAgent.value,
355
+ ...transporter.queryParameters,
356
+ ...dataQueryParameters,
357
+ ...requestOptions.queryParameters,
358
+ };
359
+ let timeoutsCount = 0; // eslint-disable-line functional/no-let
360
+ const retry = (hosts, // eslint-disable-line functional/prefer-readonly-type
361
+ getTimeout) => {
362
+ /**
363
+ * We iterate on each host, until there is no host left.
364
+ */
365
+ const host = hosts.pop(); // eslint-disable-line functional/immutable-data
366
+ if (host === undefined) {
367
+ throw createRetryError(stackTraceWithoutCredentials(stackTrace));
368
+ }
369
+ const payload = {
370
+ data,
371
+ headers,
372
+ method,
373
+ url: serializeUrl(host, request.path, queryParameters),
374
+ connectTimeout: getTimeout(timeoutsCount, transporter.timeouts.connect),
375
+ responseTimeout: getTimeout(timeoutsCount, requestOptions.timeout),
376
+ };
377
+ /**
378
+ * The stackFrame is pushed to the stackTrace so we
379
+ * can have information about onRetry and onFailure
380
+ * decisions.
381
+ */
382
+ const pushToStackTrace = (response) => {
383
+ const stackFrame = {
384
+ request: payload,
385
+ response,
386
+ host,
387
+ triesLeft: hosts.length,
388
+ };
389
+ // eslint-disable-next-line functional/immutable-data
390
+ stackTrace.push(stackFrame);
391
+ return stackFrame;
392
+ };
393
+ const decisions = {
394
+ onSuccess: response => deserializeSuccess(response),
395
+ onRetry(response) {
396
+ const stackFrame = pushToStackTrace(response);
397
+ /**
398
+ * If response is a timeout, we increaset the number of
399
+ * timeouts so we can increase the timeout later.
400
+ */
401
+ if (response.isTimedOut) {
402
+ timeoutsCount++;
403
+ }
404
+ return Promise.all([
405
+ /**
406
+ * Failures are individually send the logger, allowing
407
+ * the end user to debug / store stack frames even
408
+ * when a retry error does not happen.
409
+ */
410
+ transporter.logger.info('Retryable failure', stackFrameWithoutCredentials(stackFrame)),
411
+ /**
412
+ * We also store the state of the host in failure cases. If the host, is
413
+ * down it will remain down for the next 2 minutes. In a timeout situation,
414
+ * this host will be added end of the list of hosts on the next request.
415
+ */
416
+ transporter.hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? HostStatusEnum.Timeouted : HostStatusEnum.Down)),
417
+ ]).then(() => retry(hosts, getTimeout));
418
+ },
419
+ onFail(response) {
420
+ pushToStackTrace(response);
421
+ throw deserializeFailure(response, stackTraceWithoutCredentials(stackTrace));
422
+ },
423
+ };
424
+ return transporter.requester.send(payload).then(response => {
425
+ return retryDecision(response, decisions);
426
+ });
427
+ };
428
+ /**
429
+ * Finally, for each retryable host perform request until we got a non
430
+ * retryable response. Some notes here:
431
+ *
432
+ * 1. The reverse here is applied so we can apply a `pop` later on => more performant.
433
+ * 2. We also get from the retryable options a timeout multiplier that is tailored
434
+ * for the current context.
435
+ */
436
+ return createRetryableOptions(transporter.hostsCache, statelessHosts).then(options => {
437
+ return retry([...options.statelessHosts].reverse(), options.getTimeout);
438
+ });
439
+ }
440
+
441
+ function createTransporter(options) {
442
+ const { hostsCache, logger, requester, requestsCache, responsesCache, timeouts, userAgent, hosts, queryParameters, headers, } = options;
443
+ const transporter = {
444
+ hostsCache,
445
+ logger,
446
+ requester,
447
+ requestsCache,
448
+ responsesCache,
449
+ timeouts,
450
+ userAgent,
451
+ headers,
452
+ queryParameters,
453
+ hosts: hosts.map(host => createStatelessHost(host)),
454
+ read(request, requestOptions) {
455
+ /**
456
+ * First, we compute the user request options. Now, keep in mind,
457
+ * that using request options the user is able to modified the intire
458
+ * payload of the request. Such as headers, query parameters, and others.
459
+ */
460
+ const mappedRequestOptions = createMappedRequestOptions(requestOptions, transporter.timeouts.read);
461
+ const createRetryableRequest = () => {
462
+ /**
463
+ * Then, we prepare a function factory that contains the construction of
464
+ * the retryable request. At this point, we may *not* perform the actual
465
+ * request. But we want to have the function factory ready.
466
+ */
467
+ return retryableRequest(transporter, transporter.hosts.filter(host => (host.accept & CallEnum.Read) !== 0), request, mappedRequestOptions);
468
+ };
469
+ /**
470
+ * Once we have the function factory ready, we need to determine of the
471
+ * request is "cacheable" - should be cached. Note that, once again,
472
+ * the user can force this option.
473
+ */
474
+ const cacheable = mappedRequestOptions.cacheable !== undefined
475
+ ? mappedRequestOptions.cacheable
476
+ : request.cacheable;
477
+ /**
478
+ * If is not "cacheable", we immediatly trigger the retryable request, no
479
+ * need to check cache implementations.
480
+ */
481
+ if (cacheable !== true) {
482
+ return createRetryableRequest();
483
+ }
484
+ /**
485
+ * If the request is "cacheable", we need to first compute the key to ask
486
+ * the cache implementations if this request is on progress or if the
487
+ * response already exists on the cache.
488
+ */
489
+ const key = {
490
+ request,
491
+ mappedRequestOptions,
492
+ transporter: {
493
+ queryParameters: transporter.queryParameters,
494
+ headers: transporter.headers,
495
+ },
496
+ };
497
+ /**
498
+ * With the computed key, we first ask the responses cache
499
+ * implemention if this request was been resolved before.
500
+ */
501
+ return transporter.responsesCache.get(key, () => {
502
+ /**
503
+ * If the request has never resolved before, we actually ask if there
504
+ * is a current request with the same key on progress.
505
+ */
506
+ return transporter.requestsCache.get(key, () => {
507
+ return (transporter.requestsCache
508
+ /**
509
+ * Finally, if there is no request in progress with the same key,
510
+ * this `createRetryableRequest()` will actually trigger the
511
+ * retryable request.
512
+ */
513
+ .set(key, createRetryableRequest())
514
+ .then(response => Promise.all([transporter.requestsCache.delete(key), response]), err => Promise.all([transporter.requestsCache.delete(key), Promise.reject(err)]))
515
+ .then(([_, response]) => response));
516
+ });
517
+ }, {
518
+ /**
519
+ * Of course, once we get this response back from the server, we
520
+ * tell response cache to actually store the received response
521
+ * to be used later.
522
+ */
523
+ miss: response => transporter.responsesCache.set(key, response),
524
+ });
525
+ },
526
+ write(request, requestOptions) {
527
+ /**
528
+ * On write requests, no cache mechanisms are applied, and we
529
+ * proxy the request immediately to the requester.
530
+ */
531
+ return retryableRequest(transporter, transporter.hosts.filter(host => (host.accept & CallEnum.Write) !== 0), request, createMappedRequestOptions(requestOptions, transporter.timeouts.write));
532
+ },
533
+ };
534
+ return transporter;
535
+ }
536
+
537
+ function createUserAgent(version) {
538
+ const userAgent = {
539
+ value: `Algolia for JavaScript (${version})`,
540
+ add(options) {
541
+ const addedUserAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;
542
+ if (userAgent.value.indexOf(addedUserAgent) === -1) {
543
+ // eslint-disable-next-line functional/immutable-data
544
+ userAgent.value = `${userAgent.value}${addedUserAgent}`;
545
+ }
546
+ return userAgent;
547
+ },
548
+ };
549
+ return userAgent;
550
+ }
551
+
552
+ function deserializeSuccess(response) {
553
+ // eslint-disable-next-line functional/no-try-statement
554
+ try {
555
+ return JSON.parse(response.content);
556
+ }
557
+ catch (e) {
558
+ throw createDeserializationError(e.message, response);
559
+ }
560
+ }
561
+ function deserializeFailure({ content, status }, stackFrame) {
562
+ // eslint-disable-next-line functional/no-let
563
+ let message = content;
564
+ // eslint-disable-next-line functional/no-try-statement
565
+ try {
566
+ message = JSON.parse(content).message;
567
+ }
568
+ catch (e) {
569
+ // ..
570
+ }
571
+ return createApiError(message, status, stackFrame);
572
+ }
573
+
574
+ function serializeUrl(host, path, queryParameters) {
575
+ const queryParametersAsString = serializeQueryParameters(queryParameters);
576
+ // eslint-disable-next-line functional/no-let
577
+ let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`;
578
+ if (queryParametersAsString.length) {
579
+ url += `?${queryParametersAsString}`;
580
+ }
581
+ return url;
582
+ }
583
+ function serializeQueryParameters(parameters) {
584
+ const isObjectOrArray = (value) => Object.prototype.toString.call(value) === '[object Object]' ||
585
+ Object.prototype.toString.call(value) === '[object Array]';
586
+ return Object.keys(parameters)
587
+ .map(key => encode('%s=%s', key, isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]))
588
+ .join('&');
589
+ }
590
+ function serializeData(request, requestOptions) {
591
+ if (request.method === MethodEnum.Get ||
592
+ (request.data === undefined && requestOptions.data === undefined)) {
593
+ return undefined;
594
+ }
595
+ const data = Array.isArray(request.data)
596
+ ? request.data
597
+ : { ...request.data, ...requestOptions.data };
598
+ return JSON.stringify(data);
599
+ }
600
+ function serializeHeaders(transporter, requestOptions) {
601
+ const headers = {
602
+ ...transporter.headers,
603
+ ...requestOptions.headers,
604
+ };
605
+ const serializedHeaders = {};
606
+ Object.keys(headers).forEach(header => {
607
+ const value = headers[header];
608
+ // @ts-ignore
609
+ // eslint-disable-next-line functional/immutable-data
610
+ serializedHeaders[header.toLowerCase()] = value;
611
+ });
612
+ return serializedHeaders;
613
+ }
614
+
615
+ function stackTraceWithoutCredentials(stackTrace) {
616
+ return stackTrace.map(stackFrame => stackFrameWithoutCredentials(stackFrame));
617
+ }
618
+ function stackFrameWithoutCredentials(stackFrame) {
619
+ const modifiedHeaders = stackFrame.request.headers['x-algolia-api-key']
620
+ ? { 'x-algolia-api-key': '*****' }
621
+ : {};
622
+ return {
623
+ ...stackFrame,
624
+ request: {
625
+ ...stackFrame.request,
626
+ headers: {
627
+ ...stackFrame.request.headers,
628
+ ...modifiedHeaders,
629
+ },
630
+ },
631
+ };
632
+ }
633
+
634
+ function createApiError(message, status, transporterStackTrace) {
635
+ return {
636
+ name: 'ApiError',
637
+ message,
638
+ status,
639
+ transporterStackTrace,
640
+ };
641
+ }
642
+
643
+ function createDeserializationError(message, response) {
644
+ return {
645
+ name: 'DeserializationError',
646
+ message,
647
+ response,
648
+ };
649
+ }
650
+
651
+ function createRetryError(transporterStackTrace) {
652
+ return {
653
+ name: 'RetryError',
654
+ message: 'Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.',
655
+ transporterStackTrace,
656
+ };
657
+ }
658
+
659
+ const createSearchClient = options => {
660
+ const appId = options.appId;
661
+ const auth = createAuth(options.authMode !== undefined ? options.authMode : AuthMode.WithinHeaders, appId, options.apiKey);
662
+ const transporter = createTransporter({
663
+ hosts: [
664
+ { url: `${appId}-dsn.algolia.net`, accept: CallEnum.Read },
665
+ { url: `${appId}.algolia.net`, accept: CallEnum.Write },
666
+ ].concat(shuffle([
667
+ { url: `${appId}-1.algolianet.com` },
668
+ { url: `${appId}-2.algolianet.com` },
669
+ { url: `${appId}-3.algolianet.com` },
670
+ ])),
671
+ ...options,
672
+ headers: {
673
+ ...auth.headers(),
674
+ ...{ 'content-type': 'application/x-www-form-urlencoded' },
675
+ ...options.headers,
676
+ },
677
+ queryParameters: {
678
+ ...auth.queryParameters(),
679
+ ...options.queryParameters,
680
+ },
681
+ });
682
+ const base = {
683
+ transporter,
684
+ appId,
685
+ addAlgoliaAgent(segment, version) {
686
+ transporter.userAgent.add({ segment, version });
687
+ },
688
+ clearCache() {
689
+ return Promise.all([
690
+ transporter.requestsCache.clear(),
691
+ transporter.responsesCache.clear(),
692
+ ]).then(() => undefined);
693
+ },
694
+ };
695
+ return addMethods(base, options.methods);
696
+ };
697
+
698
+ const customRequest = (base) => {
699
+ return (request, requestOptions) => {
700
+ if (request.method === MethodEnum.Get) {
701
+ return base.transporter.read(request, requestOptions);
702
+ }
703
+ return base.transporter.write(request, requestOptions);
704
+ };
705
+ };
706
+
707
+ const initIndex = (base) => {
708
+ return (indexName, options = {}) => {
709
+ const searchIndex = {
710
+ transporter: base.transporter,
711
+ appId: base.appId,
712
+ indexName,
713
+ };
714
+ return addMethods(searchIndex, options.methods);
715
+ };
716
+ };
717
+
718
+ const multipleQueries = (base) => {
719
+ return (queries, requestOptions) => {
720
+ const requests = queries.map(query => {
721
+ return {
722
+ ...query,
723
+ params: serializeQueryParameters(query.params || {}),
724
+ };
725
+ });
726
+ return base.transporter.read({
727
+ method: MethodEnum.Post,
728
+ path: '1/indexes/*/queries',
729
+ data: {
730
+ requests,
731
+ },
732
+ cacheable: true,
733
+ }, requestOptions);
734
+ };
735
+ };
736
+
737
+ const multipleSearchForFacetValues = (base) => {
738
+ return (queries, requestOptions) => {
739
+ return Promise.all(queries.map(query => {
740
+ const { facetName, facetQuery, ...params } = query.params;
741
+ return initIndex(base)(query.indexName, {
742
+ methods: { searchForFacetValues },
743
+ }).searchForFacetValues(facetName, facetQuery, {
744
+ ...requestOptions,
745
+ ...params,
746
+ });
747
+ }));
748
+ };
749
+ };
750
+
751
+ const findAnswers = (base) => {
752
+ return (query, queryLanguages, requestOptions) => {
753
+ return base.transporter.read({
754
+ method: MethodEnum.Post,
755
+ path: encode('1/answers/%s/prediction', base.indexName),
756
+ data: {
757
+ query,
758
+ queryLanguages,
759
+ },
760
+ cacheable: true,
761
+ }, requestOptions);
762
+ };
763
+ };
764
+
765
+ const search = (base) => {
766
+ return (query, requestOptions) => {
767
+ return base.transporter.read({
768
+ method: MethodEnum.Post,
769
+ path: encode('1/indexes/%s/query', base.indexName),
770
+ data: {
771
+ query,
772
+ },
773
+ cacheable: true,
774
+ }, requestOptions);
775
+ };
776
+ };
777
+
778
+ const searchForFacetValues = (base) => {
779
+ return (facetName, facetQuery, requestOptions) => {
780
+ return base.transporter.read({
781
+ method: MethodEnum.Post,
782
+ path: encode('1/indexes/%s/facets/%s/query', base.indexName, facetName),
783
+ data: {
784
+ facetQuery,
785
+ },
786
+ cacheable: true,
787
+ }, requestOptions);
788
+ };
789
+ };
790
+
791
+ const LogLevelEnum = {
792
+ Debug: 1,
793
+ Info: 2,
794
+ Error: 3,
795
+ };
796
+
797
+ /* eslint no-console: 0 */
798
+ function createConsoleLogger(logLevel) {
799
+ return {
800
+ debug(message, args) {
801
+ if (LogLevelEnum.Debug >= logLevel) {
802
+ console.debug(message, args);
803
+ }
804
+ return Promise.resolve();
805
+ },
806
+ info(message, args) {
807
+ if (LogLevelEnum.Info >= logLevel) {
808
+ console.info(message, args);
809
+ }
810
+ return Promise.resolve();
811
+ },
812
+ error(message, args) {
813
+ console.error(message, args);
814
+ return Promise.resolve();
815
+ },
816
+ };
817
+ }
818
+
819
+ function createBrowserXhrRequester() {
820
+ return {
821
+ send(request) {
822
+ return new Promise((resolve) => {
823
+ const baseRequester = new XMLHttpRequest();
824
+ baseRequester.open(request.method, request.url, true);
825
+ Object.keys(request.headers).forEach(key => baseRequester.setRequestHeader(key, request.headers[key]));
826
+ const createTimeout = (timeout, content) => {
827
+ return setTimeout(() => {
828
+ baseRequester.abort();
829
+ resolve({
830
+ status: 0,
831
+ content,
832
+ isTimedOut: true,
833
+ });
834
+ }, timeout * 1000);
835
+ };
836
+ const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
837
+ // eslint-disable-next-line functional/no-let
838
+ let responseTimeout;
839
+ // eslint-disable-next-line functional/immutable-data
840
+ baseRequester.onreadystatechange = () => {
841
+ if (baseRequester.readyState > baseRequester.OPENED && responseTimeout === undefined) {
842
+ clearTimeout(connectTimeout);
843
+ responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
844
+ }
845
+ };
846
+ // eslint-disable-next-line functional/immutable-data
847
+ baseRequester.onerror = () => {
848
+ // istanbul ignore next
849
+ if (baseRequester.status === 0) {
850
+ clearTimeout(connectTimeout);
851
+ clearTimeout(responseTimeout);
852
+ resolve({
853
+ content: baseRequester.responseText || 'Network request failed',
854
+ status: baseRequester.status,
855
+ isTimedOut: false,
856
+ });
857
+ }
858
+ };
859
+ // eslint-disable-next-line functional/immutable-data
860
+ baseRequester.onload = () => {
861
+ clearTimeout(connectTimeout);
862
+ clearTimeout(responseTimeout);
863
+ resolve({
864
+ content: baseRequester.responseText,
865
+ status: baseRequester.status,
866
+ isTimedOut: false,
867
+ });
868
+ };
869
+ baseRequester.send(request.data);
870
+ });
871
+ },
872
+ };
873
+ }
874
+
875
+ function algoliasearch(appId, apiKey, options) {
876
+ const commonOptions = {
877
+ appId,
878
+ apiKey,
879
+ timeouts: {
880
+ connect: 1,
881
+ read: 2,
882
+ write: 30,
883
+ },
884
+ requester: createBrowserXhrRequester(),
885
+ logger: createConsoleLogger(LogLevelEnum.Error),
886
+ responsesCache: createInMemoryCache(),
887
+ requestsCache: createInMemoryCache({ serializable: false }),
888
+ hostsCache: createFallbackableCache({
889
+ caches: [
890
+ createBrowserLocalStorageCache({ key: `${version}-${appId}` }),
891
+ createInMemoryCache(),
892
+ ],
893
+ }),
894
+ userAgent: createUserAgent(version).add({
895
+ segment: 'Browser',
896
+ version: 'lite',
897
+ }),
898
+ authMode: AuthMode.WithinQueryParameters,
899
+ };
900
+ return createSearchClient({
901
+ ...commonOptions,
902
+ ...options,
903
+ methods: {
904
+ search: multipleQueries,
905
+ searchForFacetValues: multipleSearchForFacetValues,
906
+ multipleQueries,
907
+ multipleSearchForFacetValues,
908
+ customRequest,
909
+ initIndex: base => (indexName) => {
910
+ return initIndex(base)(indexName, {
911
+ methods: { search, searchForFacetValues, findAnswers },
912
+ });
913
+ },
914
+ },
915
+ });
916
+ }
917
+ // eslint-disable-next-line functional/immutable-data
918
+ algoliasearch.version = version;
919
+
920
+ exports.algoliasearch = algoliasearch;
921
+
922
+ //# sourceMappingURL=algoliasearch-lite.esm.browser-992a2eff.js.map