@jetbrains/ring-ui 4.1.12 → 5.0.0-beta.11

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 (1108) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +0 -11
  3. package/babel.config.js +2 -12
  4. package/components/alert/alert.css +4 -14
  5. package/components/alert/alert.d.ts +113 -0
  6. package/components/alert/alert.js +140 -196
  7. package/components/alert/container.css +0 -2
  8. package/components/alert/container.d.ts +15 -0
  9. package/components/alert/container.js +24 -41
  10. package/components/alert-service/alert-service.d.ts +34 -0
  11. package/components/alert-service/alert-service.examples.css +5 -3
  12. package/components/alert-service/alert-service.js +94 -124
  13. package/components/analytics/analytics.d.ts +24 -0
  14. package/components/analytics/analytics.js +75 -89
  15. package/components/analytics/analytics__custom-plugin.d.ts +39 -0
  16. package/components/analytics/analytics__custom-plugin.js +90 -111
  17. package/components/analytics/analytics__fus-plugin.d.ts +62 -0
  18. package/components/analytics/analytics__fus-plugin.js +62 -75
  19. package/components/analytics/analytics__ga-plugin.d.ts +17 -0
  20. package/components/analytics/analytics__ga-plugin.js +40 -43
  21. package/components/analytics/analytics__plugin-utils.d.ts +15 -0
  22. package/components/analytics/analytics__plugin-utils.js +61 -68
  23. package/components/analytics-ng/analytics-ng.examples.js +2 -2
  24. package/components/auth/auth.d.ts +3 -0
  25. package/components/auth/auth.js +3 -6
  26. package/components/auth/auth__core.d.ts +235 -0
  27. package/components/auth/auth__core.js +780 -878
  28. package/components/auth/background-flow.d.ts +31 -0
  29. package/components/auth/background-flow.js +91 -108
  30. package/components/auth/down-notification.css +1 -1
  31. package/components/auth/down-notification.d.ts +15 -0
  32. package/components/auth/down-notification.js +32 -52
  33. package/components/auth/iframe-flow.d.ts +20 -0
  34. package/components/auth/iframe-flow.js +71 -89
  35. package/components/auth/landing-entry.d.ts +3 -0
  36. package/components/auth/landing-entry.js +0 -1
  37. package/components/auth/landing.d.ts +2 -0
  38. package/components/auth/landing.html +1 -1
  39. package/components/auth/landing.js +19 -23
  40. package/components/auth/request-builder.d.ts +47 -0
  41. package/components/auth/request-builder.js +61 -68
  42. package/components/auth/response-parser.d.ts +70 -0
  43. package/components/auth/response-parser.js +84 -94
  44. package/components/auth/storage.d.ts +112 -0
  45. package/components/auth/storage.js +199 -214
  46. package/components/auth/token-validator.d.ts +93 -0
  47. package/components/auth/token-validator.js +160 -172
  48. package/components/auth/window-flow.d.ts +26 -0
  49. package/components/auth/window-flow.js +91 -112
  50. package/components/auth-dialog/auth-dialog.d.ts +60 -0
  51. package/components/auth-dialog/auth-dialog.js +72 -139
  52. package/components/auth-dialog-service/auth-dialog-service.d.ts +5 -0
  53. package/components/auth-dialog-service/auth-dialog-service.js +9 -15
  54. package/components/auth-ng/auth-ng.examples.js +1 -1
  55. package/components/autofocus-ng/autofocus-ng.examples.js +3 -3
  56. package/components/autofocus-ng/autofocus-ng.js +1 -1
  57. package/components/autofocus-ng/autofocus-ng.test.js +1 -1
  58. package/components/avatar/avatar-example-datauri.d.ts +1 -0
  59. package/components/avatar/avatar-example-datauri.js +0 -1
  60. package/components/avatar/avatar.d.ts +51 -0
  61. package/components/avatar/avatar.js +86 -157
  62. package/components/avatar/fallback-avatar.d.ts +17 -0
  63. package/components/avatar/fallback-avatar.js +84 -108
  64. package/components/avatar-editor-ng/avatar-editor-ng.examples.js +1 -1
  65. package/components/avatar-ng/avatar-ng.examples.js +3 -3
  66. package/components/badge/badge.d.ts +24 -0
  67. package/components/badge/badge.js +25 -49
  68. package/components/badge-ng/badge-ng.examples.js +2 -2
  69. package/components/breadcrumb-ng/breadcrumb-ng.examples.js +1 -1
  70. package/components/button/button.css +95 -206
  71. package/components/button/button.d.ts +67 -0
  72. package/components/button/button.js +56 -107
  73. package/components/button/button__classes.d.ts +2 -0
  74. package/components/button/button__classes.js +15 -37
  75. package/components/button-group/button-group.css +136 -19
  76. package/components/button-group/button-group.d.ts +17 -0
  77. package/components/button-group/button-group.js +11 -21
  78. package/components/button-group/caption.d.ts +8 -0
  79. package/components/button-group/caption.js +9 -18
  80. package/components/button-group-ng/button-group-ng.css +1 -0
  81. package/components/button-group-ng/button-group-ng.examples.js +3 -3
  82. package/components/button-ng/button-ng.examples.js +11 -12
  83. package/components/button-ng/button-ng.js +6 -25
  84. package/components/button-set/button-set.css +1 -0
  85. package/components/button-set/button-set.d.ts +12 -0
  86. package/components/button-set/button-set.js +10 -18
  87. package/components/button-set-ng/button-set-ng.examples.js +2 -2
  88. package/components/button-toolbar/button-toolbar.css +2 -0
  89. package/components/button-toolbar/button-toolbar.d.ts +12 -0
  90. package/components/button-toolbar/button-toolbar.js +10 -21
  91. package/components/button-toolbar-ng/button-toolbar-ng.examples.js +3 -3
  92. package/components/caret/caret.d.ts +66 -0
  93. package/components/caret/caret.js +200 -209
  94. package/components/checkbox/checkbox.css +10 -4
  95. package/components/checkbox/checkbox.d.ts +41 -0
  96. package/components/checkbox/checkbox.js +47 -81
  97. package/components/checkbox-ng/checkbox-ng.examples.js +2 -2
  98. package/components/code/code.d.ts +43 -0
  99. package/components/code/code.js +74 -98
  100. package/components/compiler-ng/compiler-ng.examples.js +1 -1
  101. package/components/confirm/confirm.d.ts +48 -0
  102. package/components/confirm/confirm.js +39 -81
  103. package/components/confirm-ng/confirm-ng.examples.js +2 -2
  104. package/components/confirm-service/confirm-service.d.ts +15 -0
  105. package/components/confirm-service/confirm-service.js +35 -51
  106. package/components/content-layout/content-layout.d.ts +26 -0
  107. package/components/content-layout/content-layout.js +33 -52
  108. package/components/content-layout/sidebar.d.ts +31 -0
  109. package/components/content-layout/sidebar.js +62 -91
  110. package/components/contenteditable/contenteditable.d.ts +47 -0
  111. package/components/contenteditable/contenteditable.js +36 -55
  112. package/components/data-list/data-list.d.ts +89 -0
  113. package/components/data-list/data-list.js +95 -146
  114. package/components/data-list/data-list.mock.d.ts +16 -0
  115. package/components/data-list/data-list.mock.js +166 -207
  116. package/components/data-list/item.d.ts +50 -0
  117. package/components/data-list/item.js +87 -187
  118. package/components/data-list/selection.d.ts +16 -0
  119. package/components/data-list/selection.js +75 -90
  120. package/components/data-list/title.d.ts +26 -0
  121. package/components/data-list/title.js +48 -79
  122. package/components/data-list-ng/data-list-ng.examples.js +3 -3
  123. package/components/date-picker/consts.d.ts +99 -0
  124. package/components/date-picker/consts.js +26 -53
  125. package/components/date-picker/date-input.d.ts +57 -0
  126. package/components/date-picker/date-input.js +88 -122
  127. package/components/date-picker/date-picker.css +2 -1
  128. package/components/date-picker/date-picker.d.ts +70 -0
  129. package/components/date-picker/date-picker.js +180 -260
  130. package/components/date-picker/date-popup.d.ts +56 -0
  131. package/components/date-picker/date-popup.js +308 -405
  132. package/components/date-picker/day.d.ts +30 -0
  133. package/components/date-picker/day.js +71 -104
  134. package/components/date-picker/formats.d.ts +2 -0
  135. package/components/date-picker/month-names.d.ts +13 -0
  136. package/components/date-picker/month-names.js +44 -86
  137. package/components/date-picker/month-slider.d.ts +29 -0
  138. package/components/date-picker/month-slider.js +44 -71
  139. package/components/date-picker/month.d.ts +14 -0
  140. package/components/date-picker/month.js +18 -33
  141. package/components/date-picker/months.d.ts +11 -0
  142. package/components/date-picker/months.js +52 -79
  143. package/components/date-picker/weekdays.d.ts +13 -0
  144. package/components/date-picker/weekdays.js +12 -28
  145. package/components/date-picker/years.d.ts +21 -0
  146. package/components/date-picker/years.js +55 -91
  147. package/components/dialog/dialog.css +10 -3
  148. package/components/dialog/dialog.d.ts +73 -0
  149. package/components/dialog/dialog.js +100 -158
  150. package/components/dialog/dialog__body-scroll-preventer.d.ts +9 -0
  151. package/components/dialog/dialog__body-scroll-preventer.js +35 -51
  152. package/components/dialog-ng/dialog-ng.examples.js +5 -5
  153. package/components/dialog-ng/dialog-ng__template.js +1 -0
  154. package/components/docked-panel-ng/docked-panel-ng.examples.js +3 -3
  155. package/components/dropdown/anchor.d.ts +11 -0
  156. package/components/dropdown/anchor.js +6 -22
  157. package/components/dropdown/dropdown.d.ts +77 -0
  158. package/components/dropdown/dropdown.js +131 -168
  159. package/components/dropdown-menu/dropdown-menu.d.ts +26 -0
  160. package/components/dropdown-menu/dropdown-menu.js +43 -104
  161. package/components/error-bubble/error-bubble-legacy.css +1 -1
  162. package/components/error-bubble/error-bubble.css +1 -1
  163. package/components/error-bubble/error-bubble.d.ts +18 -0
  164. package/components/error-bubble/error-bubble.js +17 -39
  165. package/components/error-message/error-message.d.ts +25 -0
  166. package/components/error-message/error-message.js +19 -38
  167. package/components/error-message-ng/error-message-ng.examples.js +1 -1
  168. package/components/error-page-ng/error-page-ng.examples.js +2 -2
  169. package/components/footer/footer.d.ts +28 -0
  170. package/components/footer/footer.js +61 -103
  171. package/components/footer-ng/footer-ng.examples.js +2 -2
  172. package/components/form/form.examples.js +4 -4
  173. package/components/form-ng/form-ng.examples.js +6 -6
  174. package/components/global/compose.d.ts +7 -0
  175. package/components/global/compose.js +3 -3
  176. package/components/global/composeRefs.d.ts +3 -0
  177. package/components/global/composeRefs.js +7 -6
  178. package/components/global/controls-height.d.ts +7 -0
  179. package/components/global/controls-height.js +8 -0
  180. package/components/global/create-stateful-context.d.ts +27 -0
  181. package/components/global/create-stateful-context.js +32 -40
  182. package/components/global/data-tests.d.ts +3 -0
  183. package/components/global/data-tests.js +12 -12
  184. package/components/global/dom.d.ts +37 -0
  185. package/components/global/dom.js +51 -73
  186. package/components/global/focus-sensor-hoc.d.ts +18 -0
  187. package/components/global/focus-sensor-hoc.js +94 -105
  188. package/components/global/fuzzy-highlight.d.ts +5 -0
  189. package/components/global/fuzzy-highlight.js +38 -40
  190. package/components/global/get-event-key.d.ts +2 -0
  191. package/components/global/get-event-key.js +88 -100
  192. package/components/global/get-uid.d.ts +1 -0
  193. package/components/global/get-uid.js +8 -12
  194. package/components/global/inject-styles.d.ts +3 -0
  195. package/components/global/inject-styles.js +7 -9
  196. package/components/global/linear-function.d.ts +6 -0
  197. package/components/global/linear-function.js +9 -12
  198. package/components/global/listeners.d.ts +8 -0
  199. package/components/global/listeners.js +22 -33
  200. package/components/global/memoize.d.ts +1 -0
  201. package/components/global/memoize.js +13 -12
  202. package/components/global/normalize-indent.d.ts +1 -0
  203. package/components/global/normalize-indent.js +26 -30
  204. package/components/global/promise-with-timeout.d.ts +4 -0
  205. package/components/global/promise-with-timeout.js +5 -7
  206. package/components/global/prop-types.d.ts +4 -0
  207. package/components/global/prop-types.js +4 -0
  208. package/components/global/react-dom-renderer.d.ts +16 -0
  209. package/components/global/react-dom-renderer.js +21 -30
  210. package/components/global/rerender-hoc.d.ts +45 -0
  211. package/components/global/rerender-hoc.js +18 -27
  212. package/components/global/schedule-raf.d.ts +1 -0
  213. package/components/global/schedule-raf.js +24 -24
  214. package/components/global/sniffer.d.ts +3 -0
  215. package/components/global/sniffer.js +0 -2
  216. package/components/global/theme.d.ts +13 -0
  217. package/components/global/theme.js +31 -49
  218. package/components/global/trivial-template-tag.d.ts +1 -0
  219. package/components/global/trivial-template-tag.js +6 -8
  220. package/components/global/typescript-utils.d.ts +2 -0
  221. package/components/global/typescript-utils.js +2 -0
  222. package/components/global/url.d.ts +57 -0
  223. package/components/global/url.js +58 -84
  224. package/components/global/variables.css +30 -25
  225. package/components/global/variables.d.ts +90 -0
  226. package/components/global/variables.js +1 -0
  227. package/components/global/variables_dark.css +68 -0
  228. package/components/grid/col.d.ts +31 -0
  229. package/components/grid/col.js +33 -42
  230. package/components/grid/grid.d.ts +14 -0
  231. package/components/grid/grid.js +13 -24
  232. package/components/grid/row.d.ts +40 -0
  233. package/components/grid/row.js +35 -44
  234. package/components/group/group.d.ts +12 -0
  235. package/components/group/group.js +11 -21
  236. package/components/group-ng/group.examples.js +2 -2
  237. package/components/header/header.css +19 -10
  238. package/components/header/header.d.ts +34 -0
  239. package/components/header/header.js +30 -44
  240. package/components/header/logo.d.ts +14 -0
  241. package/components/header/logo.js +16 -25
  242. package/components/header/profile.d.ts +73 -0
  243. package/components/header/profile.js +102 -168
  244. package/components/header/services-link.d.ts +25 -0
  245. package/components/header/services-link.js +20 -37
  246. package/components/header/services.css +3 -3
  247. package/components/header/services.d.ts +33 -0
  248. package/components/header/services.js +49 -102
  249. package/components/header/smart-profile.d.ts +36 -0
  250. package/components/header/smart-profile.js +76 -111
  251. package/components/header/smart-services.d.ts +25 -0
  252. package/components/header/smart-services.js +42 -66
  253. package/components/header/tray-icon.d.ts +32 -0
  254. package/components/header/tray-icon.js +14 -27
  255. package/components/header/tray.d.ts +9 -0
  256. package/components/header/tray.js +12 -24
  257. package/components/heading/heading.css +4 -1
  258. package/components/heading/heading.d.ts +25 -0
  259. package/components/heading/heading.js +33 -63
  260. package/components/http/http.d.ts +49 -0
  261. package/components/http/http.js +144 -174
  262. package/components/http/http.mock.d.ts +20 -0
  263. package/components/http/http.mock.js +46 -56
  264. package/components/hub-source/hub-source.d.ts +42 -0
  265. package/components/hub-source/hub-source.js +89 -105
  266. package/components/hub-source/hub-source__user.d.ts +4 -0
  267. package/components/hub-source/hub-source__user.js +14 -21
  268. package/components/hub-source/hub-source__users-groups.d.ts +24 -0
  269. package/components/hub-source/hub-source__users-groups.js +46 -53
  270. package/components/icon/icon.css +1 -1
  271. package/components/icon/icon.d.ts +43 -0
  272. package/components/icon/icon.js +55 -83
  273. package/components/icon/icon__constants.d.ts +30 -0
  274. package/components/icon/icon__constants.js +25 -24
  275. package/components/icon/icon__svg.d.ts +15 -0
  276. package/components/icon/icon__svg.js +39 -58
  277. package/components/icon/index.d.ts +2 -0
  278. package/components/icon/index.js +1 -1
  279. package/components/icon-ng/icon-ng.examples.js +1 -1
  280. package/components/input/input.css +87 -149
  281. package/components/input/input.d.ts +69 -0
  282. package/components/input/input.js +136 -203
  283. package/components/input-ng/input-ng.examples.js +2 -2
  284. package/components/input-ng/input-ng.js +45 -49
  285. package/components/input-size/input-size.examples.js +5 -5
  286. package/components/island/adaptive-island-hoc.d.ts +65 -0
  287. package/components/island/adaptive-island-hoc.js +21 -31
  288. package/components/island/content.d.ts +12 -0
  289. package/components/island/content.js +81 -123
  290. package/components/island/header.d.ts +8 -0
  291. package/components/island/header.js +60 -84
  292. package/components/island/island.css +8 -5
  293. package/components/island/island.d.ts +82 -0
  294. package/components/island/island.js +19 -41
  295. package/components/island-legacy/content-legacy.d.ts +10 -0
  296. package/components/island-legacy/content-legacy.js +11 -20
  297. package/components/island-legacy/header-legacy.d.ts +10 -0
  298. package/components/island-legacy/header-legacy.js +11 -20
  299. package/components/island-legacy/island-legacy.css +1 -1
  300. package/components/island-legacy/island-legacy.d.ts +12 -0
  301. package/components/island-legacy/island-legacy.js +13 -23
  302. package/components/island-ng/island-ng.examples.js +1 -1
  303. package/components/link/clickableLink.d.ts +20 -0
  304. package/components/link/clickableLink.js +27 -42
  305. package/components/link/link.css +0 -2
  306. package/components/link/link.d.ts +157 -0
  307. package/components/link/link.js +56 -101
  308. package/components/link-ng/link-ng.examples.js +1 -1
  309. package/components/list/consts.d.ts +74 -0
  310. package/components/list/consts.js +22 -22
  311. package/components/list/list.d.ts +191 -0
  312. package/components/list/list.js +505 -691
  313. package/components/list/list__custom.d.ts +6 -0
  314. package/components/list/list__custom.js +37 -75
  315. package/components/list/list__hint.d.ts +15 -0
  316. package/components/list/list__hint.js +7 -15
  317. package/components/list/list__item.d.ts +8 -0
  318. package/components/list/list__item.js +81 -185
  319. package/components/list/list__link.d.ts +9 -0
  320. package/components/list/list__link.js +25 -54
  321. package/components/list/list__separator.d.ts +5 -0
  322. package/components/list/list__separator.js +13 -22
  323. package/components/list/list__title.d.ts +5 -0
  324. package/components/list/list__title.js +18 -34
  325. package/components/list/list__users-groups-source.d.ts +27 -0
  326. package/components/list/list__users-groups-source.js +63 -78
  327. package/components/loader/loader.d.ts +28 -0
  328. package/components/loader/loader.js +31 -51
  329. package/components/loader/loader__core.d.ts +75 -0
  330. package/components/loader/loader__core.js +208 -240
  331. package/components/loader-inline/loader-inline.css +14 -0
  332. package/components/loader-inline/loader-inline.d.ts +18 -0
  333. package/components/loader-inline/loader-inline.js +16 -46
  334. package/components/loader-inline-ng/loader-inline-ng.examples.js +1 -1
  335. package/components/loader-inline-ng/loader-inline-ng.js +1 -17
  336. package/components/loader-inline-ng/loader-inline-ng.test.js +0 -11
  337. package/components/loader-ng/loader-ng.examples.js +1 -1
  338. package/components/loader-screen/loader-screen.d.ts +17 -0
  339. package/components/loader-screen/loader-screen.js +16 -29
  340. package/components/loader-screen-ng/loader-screen-ng.examples.js +1 -1
  341. package/components/login-dialog/login-dialog.d.ts +47 -0
  342. package/components/login-dialog/login-dialog.js +63 -104
  343. package/components/login-dialog/service.d.ts +2 -0
  344. package/components/login-dialog/service.js +11 -15
  345. package/components/markdown/code.d.ts +9 -0
  346. package/components/markdown/code.js +4 -14
  347. package/components/markdown/heading.d.ts +11 -0
  348. package/components/markdown/heading.js +3 -7
  349. package/components/markdown/link.d.ts +12 -0
  350. package/components/markdown/link.js +4 -8
  351. package/components/markdown/markdown.d.ts +14 -0
  352. package/components/markdown/markdown.js +26 -40
  353. package/components/message/message.css +7 -3
  354. package/components/message/message.d.ts +59 -0
  355. package/components/message/message.js +84 -127
  356. package/components/old-browsers-message/old-browsers-message.d.ts +2 -0
  357. package/components/old-browsers-message/old-browsers-message.js +57 -73
  358. package/components/old-browsers-message/old-browsers-message__stop.d.ts +1 -0
  359. package/components/old-browsers-message/old-browsers-message__stop.js +1 -1
  360. package/components/old-browsers-message/white-list.d.ts +2 -0
  361. package/components/old-browsers-message/white-list.js +9 -16
  362. package/components/pager/pager.d.ts +83 -0
  363. package/components/pager/pager.js +184 -291
  364. package/components/pager-ng/pager-ng.examples.js +1 -1
  365. package/components/palette/palette.examples.js +1 -1
  366. package/components/panel/panel.d.ts +12 -0
  367. package/components/panel/panel.js +11 -19
  368. package/components/permissions/permissions.d.ts +111 -0
  369. package/components/permissions/permissions.js +144 -160
  370. package/components/permissions/permissions__cache.d.ts +93 -0
  371. package/components/permissions/permissions__cache.js +200 -231
  372. package/components/permissions-ng/permissions-ng.examples.js +2 -2
  373. package/components/place-under-ng/place-under-ng.examples.js +2 -2
  374. package/components/popup/popup.consts.d.ts +37 -0
  375. package/components/popup/popup.consts.js +36 -36
  376. package/components/popup/popup.css +1 -1
  377. package/components/popup/popup.d.ts +141 -0
  378. package/components/popup/popup.js +262 -346
  379. package/components/popup/popup.target.d.ts +7 -0
  380. package/components/popup/popup.target.js +12 -24
  381. package/components/popup/position.d.ts +30 -0
  382. package/components/popup/position.js +172 -225
  383. package/components/popup-menu/popup-menu.d.ts +59 -0
  384. package/components/popup-menu/popup-menu.js +30 -47
  385. package/components/progress-bar/progress-bar.css +8 -12
  386. package/components/progress-bar/progress-bar.d.ts +58 -0
  387. package/components/progress-bar/progress-bar.js +60 -93
  388. package/components/progress-bar-ng/progress-bar-ng.examples.js +4 -3
  389. package/components/promised-click-ng/promised-click-ng.examples.js +2 -2
  390. package/components/query-assist/query-assist.css +48 -64
  391. package/components/query-assist/query-assist.d.ts +327 -0
  392. package/components/query-assist/query-assist.js +706 -905
  393. package/components/query-assist/query-assist__suggestions.d.ts +29 -0
  394. package/components/query-assist/query-assist__suggestions.js +51 -91
  395. package/components/query-assist-ng/query-assist-ng.examples.js +2 -2
  396. package/components/radio/radio.css +10 -4
  397. package/components/radio/radio.d.ts +18 -0
  398. package/components/radio/radio.js +19 -29
  399. package/components/radio/radio__item.d.ts +28 -0
  400. package/components/radio/radio__item.js +28 -56
  401. package/components/radio-ng/radio-ng.examples.js +1 -1
  402. package/components/save-field-ng/save-field-ng.examples.js +2 -2
  403. package/components/select/select-popup.css +5 -1
  404. package/components/select/select.css +19 -37
  405. package/components/select/select.d.ts +289 -0
  406. package/components/select/select.js +806 -1191
  407. package/components/select/select__filter.d.ts +20 -0
  408. package/components/select/select__filter.js +37 -59
  409. package/components/select/select__popup.d.ts +123 -0
  410. package/components/select/select__popup.js +324 -498
  411. package/components/select-ng/select-ng.examples.js +4 -3
  412. package/components/select-ng/select-ng.js +3 -1
  413. package/components/select-ng/select-ng.test.js +1 -1
  414. package/components/select-ng/select-ng__lazy.js +3 -3
  415. package/components/shortcuts/core.d.ts +74 -0
  416. package/components/shortcuts/core.js +185 -226
  417. package/components/shortcuts/shortcut-title.d.ts +1 -0
  418. package/components/shortcuts/shortcut-title.js +43 -49
  419. package/components/shortcuts/shortcuts-hoc.d.ts +69 -0
  420. package/components/shortcuts/shortcuts-hoc.js +12 -26
  421. package/components/shortcuts/shortcuts.d.ts +28 -0
  422. package/components/shortcuts/shortcuts.js +39 -48
  423. package/components/shortcuts-hint-ng/shortcuts-hint-ng.css +1 -1
  424. package/components/shortcuts-hint-ng/shortcuts-hint-ng.examples.js +2 -2
  425. package/components/sidebar-ng/sidebar-ng.examples.js +3 -3
  426. package/components/storage/storage.d.ts +18 -0
  427. package/components/storage/storage.js +6 -9
  428. package/components/storage/storage__fallback.d.ts +79 -0
  429. package/components/storage/storage__fallback.js +160 -178
  430. package/components/storage/storage__local.d.ts +38 -0
  431. package/components/storage/storage__local.js +108 -104
  432. package/components/tab-trap/tab-trap.d.ts +43 -0
  433. package/components/tab-trap/tab-trap.js +113 -163
  434. package/components/table/cell.d.ts +13 -0
  435. package/components/table/cell.js +10 -20
  436. package/components/table/disable-hover-hoc.d.ts +68 -0
  437. package/components/table/disable-hover-hoc.js +29 -41
  438. package/components/table/header-cell.d.ts +43 -0
  439. package/components/table/header-cell.js +40 -61
  440. package/components/table/header.d.ts +60 -0
  441. package/components/table/header.js +89 -156
  442. package/components/table/multitable.d.ts +25 -0
  443. package/components/table/multitable.js +76 -94
  444. package/components/table/row-with-focus-sensor.d.ts +18 -0
  445. package/components/table/row-with-focus-sensor.js +21 -35
  446. package/components/table/row.d.ts +56 -0
  447. package/components/table/row.js +110 -199
  448. package/components/table/selection-adapter.d.ts +5 -0
  449. package/components/table/selection-adapter.js +8 -8
  450. package/components/table/selection-shortcuts-hoc.d.ts +17 -0
  451. package/components/table/selection-shortcuts-hoc.js +140 -171
  452. package/components/table/selection.d.ts +47 -0
  453. package/components/table/selection.js +148 -183
  454. package/components/table/smart-table.d.ts +60 -0
  455. package/components/table/smart-table.js +29 -48
  456. package/components/table/table.d.ts +160 -0
  457. package/components/table/table.js +170 -256
  458. package/components/table-legacy-ng/table-legacy-ng.examples.js +4 -4
  459. package/components/table-ng/table-ng.examples.js +4 -4
  460. package/components/tabs/collapsible-more.d.ts +29 -0
  461. package/components/tabs/collapsible-more.js +72 -158
  462. package/components/tabs/collapsible-tab.d.ts +16 -0
  463. package/components/tabs/collapsible-tab.js +24 -80
  464. package/components/tabs/collapsible-tabs.d.ts +43 -0
  465. package/components/tabs/collapsible-tabs.js +176 -294
  466. package/components/tabs/custom-item.d.ts +9 -0
  467. package/components/tabs/custom-item.js +2 -3
  468. package/components/tabs/dumb-tabs.d.ts +33 -0
  469. package/components/tabs/dumb-tabs.js +42 -94
  470. package/components/tabs/smart-tabs.d.ts +20 -0
  471. package/components/tabs/smart-tabs.js +14 -27
  472. package/components/tabs/tab-link.d.ts +18 -0
  473. package/components/tabs/tab-link.js +12 -22
  474. package/components/tabs/tab.d.ts +27 -0
  475. package/components/tabs/tab.js +13 -19
  476. package/components/tabs/tabs.css +17 -28
  477. package/components/tabs/tabs.d.ts +7 -0
  478. package/components/tabs/tabs.js +4 -5
  479. package/components/tabs-ng/tabs-ng.examples.js +12 -4
  480. package/components/tabs-ng/tabs-ng.js +1 -4
  481. package/components/tabs-ng/tabs-ng__template.js +1 -1
  482. package/components/tag/tag.css +31 -8
  483. package/components/tag/tag.d.ts +64 -0
  484. package/components/tag/tag.js +103 -155
  485. package/components/tags-input/tags-input.css +10 -4
  486. package/components/tags-input/tags-input.d.ts +154 -0
  487. package/components/tags-input/tags-input.js +233 -315
  488. package/components/tags-input-ng/tags-input-ng.examples.js +1 -1
  489. package/components/tags-list/tags-list.d.ts +46 -0
  490. package/components/tags-list/tags-list.js +35 -83
  491. package/components/template-ng/template-ng.examples.js +1 -1
  492. package/components/text/text.d.ts +17 -0
  493. package/components/text/text.js +13 -21
  494. package/components/title-ng/title-ng.examples.js +1 -1
  495. package/components/toggle/toggle.css +61 -35
  496. package/components/toggle/toggle.d.ts +39 -0
  497. package/components/toggle/toggle.js +31 -62
  498. package/components/toggle-ng/toggle-ng.examples.js +1 -1
  499. package/components/tooltip/tooltip.css +7 -0
  500. package/components/tooltip/tooltip.d.ts +65 -0
  501. package/components/tooltip/tooltip.js +109 -151
  502. package/components/tooltip-ng/tooltip-ng.examples.js +2 -2
  503. package/components/user-agreement/service.d.ts +161 -0
  504. package/components/user-agreement/service.js +216 -270
  505. package/components/user-agreement/toolbox.eula.d.ts +2 -0
  506. package/components/user-agreement/user-agreement.d.ts +69 -0
  507. package/components/user-agreement/user-agreement.js +55 -98
  508. package/components/user-card/card.d.ts +52 -0
  509. package/components/user-card/card.js +42 -78
  510. package/components/user-card/smart-user-card-tooltip.d.ts +20 -0
  511. package/components/user-card/smart-user-card-tooltip.js +39 -58
  512. package/components/user-card/tooltip.d.ts +31 -0
  513. package/components/user-card/tooltip.js +25 -46
  514. package/components/user-card/user-card.d.ts +11 -0
  515. package/components/user-card/user-card.js +3 -5
  516. package/components/user-card-ng/user-card-ng.examples.js +4 -4
  517. package/dist/_helpers/anchor.js +2 -2
  518. package/dist/_helpers/badge.js +1 -1
  519. package/dist/_helpers/button-group.js +1 -1
  520. package/dist/_helpers/button-set.js +1 -1
  521. package/dist/_helpers/button-toolbar.js +1 -1
  522. package/dist/_helpers/button__classes.js +5 -8
  523. package/dist/_helpers/card.js +1 -1
  524. package/dist/_helpers/checkbox.js +1 -1
  525. package/dist/_helpers/date-picker.js +1 -1
  526. package/dist/_helpers/dialog__body-scroll-preventer.js +2 -2
  527. package/dist/_helpers/error-message.js +1 -1
  528. package/dist/_helpers/footer.js +3 -3
  529. package/dist/_helpers/grid.js +1 -1
  530. package/dist/_helpers/group.js +1 -1
  531. package/dist/_helpers/header.js +1 -1
  532. package/dist/_helpers/icon.js +1 -1
  533. package/dist/_helpers/input.js +1 -1
  534. package/dist/_helpers/island.js +1 -1
  535. package/dist/_helpers/link.js +1 -1
  536. package/dist/_helpers/list.js +1 -1
  537. package/dist/_helpers/loader-inline.js +3 -0
  538. package/dist/_helpers/loader-screen.js +1 -1
  539. package/dist/_helpers/panel.js +1 -1
  540. package/dist/_helpers/query-assist__suggestions.js +3 -3
  541. package/dist/_helpers/radio.js +1 -1
  542. package/dist/_helpers/select__filter.js +13 -9
  543. package/dist/_helpers/services-link.js +1 -1
  544. package/dist/_helpers/sidebar.js +7 -4
  545. package/dist/_helpers/table.js +1 -1
  546. package/dist/_helpers/tabs.js +1 -1
  547. package/dist/_helpers/theme.js +50 -0
  548. package/dist/_helpers/title.js +14 -14
  549. package/dist/alert/alert.d.ts +113 -0
  550. package/dist/alert/alert.js +56 -50
  551. package/dist/alert/container.d.ts +15 -0
  552. package/dist/alert/container.js +6 -8
  553. package/dist/alert-service/alert-service.d.ts +34 -0
  554. package/dist/alert-service/alert-service.js +9 -7
  555. package/dist/analytics/analytics.d.ts +24 -0
  556. package/dist/analytics/analytics.js +10 -15
  557. package/dist/analytics/analytics__custom-plugin.d.ts +39 -0
  558. package/dist/analytics/analytics__custom-plugin.js +30 -9
  559. package/dist/analytics/analytics__fus-plugin.d.ts +62 -0
  560. package/dist/analytics/analytics__fus-plugin.js +23 -6
  561. package/dist/analytics/analytics__ga-plugin.d.ts +17 -0
  562. package/dist/analytics/analytics__ga-plugin.js +12 -6
  563. package/dist/analytics/analytics__plugin-utils.d.ts +15 -0
  564. package/dist/analytics/analytics__plugin-utils.js +58 -59
  565. package/dist/analytics-ng/analytics-ng.js +1 -0
  566. package/dist/auth/auth.d.ts +3 -0
  567. package/dist/auth/auth.js +9 -9
  568. package/dist/auth/auth__core.d.ts +235 -0
  569. package/dist/auth/auth__core.js +219 -125
  570. package/dist/auth/background-flow.d.ts +31 -0
  571. package/dist/auth/background-flow.js +9 -1
  572. package/dist/auth/down-notification.d.ts +15 -0
  573. package/dist/auth/down-notification.js +8 -8
  574. package/dist/auth/iframe-flow.d.ts +20 -0
  575. package/dist/auth/iframe-flow.js +20 -6
  576. package/dist/auth/landing-entry.d.ts +3 -0
  577. package/dist/auth/landing.d.ts +2 -0
  578. package/dist/auth/landing.js +22 -16
  579. package/dist/auth/request-builder.d.ts +47 -0
  580. package/dist/auth/request-builder.js +7 -1
  581. package/dist/auth/response-parser.d.ts +70 -0
  582. package/dist/auth/response-parser.js +25 -13
  583. package/dist/auth/storage.d.ts +112 -0
  584. package/dist/auth/storage.js +50 -17
  585. package/dist/auth/token-validator.d.ts +93 -0
  586. package/dist/auth/token-validator.js +32 -12
  587. package/dist/auth/window-flow.d.ts +26 -0
  588. package/dist/auth/window-flow.js +24 -11
  589. package/dist/auth-dialog/auth-dialog.d.ts +60 -0
  590. package/dist/auth-dialog/auth-dialog.js +5 -8
  591. package/dist/auth-dialog-service/auth-dialog-service.d.ts +5 -0
  592. package/dist/auth-dialog-service/auth-dialog-service.js +1 -1
  593. package/dist/auth-ng/auth-ng.js +9 -9
  594. package/dist/autofocus-ng/autofocus-ng.js +1 -1
  595. package/dist/avatar/avatar-example-datauri.d.ts +1 -0
  596. package/dist/avatar/avatar.d.ts +51 -0
  597. package/dist/avatar/avatar.js +14 -11
  598. package/dist/avatar/fallback-avatar.d.ts +17 -0
  599. package/dist/avatar-editor-ng/avatar-editor-ng.js +9 -7
  600. package/dist/badge/badge.d.ts +24 -0
  601. package/dist/breadcrumb-ng/breadcrumb-ng.js +1 -1
  602. package/dist/button/button.d.ts +67 -0
  603. package/dist/button/button.js +17 -18
  604. package/dist/button/button__classes.d.ts +2 -0
  605. package/dist/button/button__classes.js +0 -3
  606. package/dist/button-group/button-group.d.ts +17 -0
  607. package/dist/button-group/button-group.js +5 -3
  608. package/dist/button-group/caption.d.ts +8 -0
  609. package/dist/button-group-ng/button-group-ng.js +1 -1
  610. package/dist/button-ng/button-ng.js +6 -31
  611. package/dist/button-set/button-set.d.ts +12 -0
  612. package/dist/button-toolbar/button-toolbar.d.ts +12 -0
  613. package/dist/caret/caret.d.ts +66 -0
  614. package/dist/caret/caret.js +35 -19
  615. package/dist/checkbox/checkbox.d.ts +41 -0
  616. package/dist/checkbox/checkbox.js +6 -0
  617. package/dist/code/code.d.ts +43 -0
  618. package/dist/code/code.js +13 -9
  619. package/dist/confirm/confirm.d.ts +48 -0
  620. package/dist/confirm/confirm.js +4 -4
  621. package/dist/confirm-ng/confirm-ng.js +1 -1
  622. package/dist/confirm-service/confirm-service.d.ts +15 -0
  623. package/dist/confirm-service/confirm-service.js +1 -1
  624. package/dist/content-layout/content-layout.d.ts +26 -0
  625. package/dist/content-layout/content-layout.js +4 -2
  626. package/dist/content-layout/sidebar.d.ts +31 -0
  627. package/dist/contenteditable/contenteditable.d.ts +47 -0
  628. package/dist/contenteditable/contenteditable.js +6 -4
  629. package/dist/data-list/data-list.d.ts +89 -0
  630. package/dist/data-list/data-list.js +54 -30
  631. package/dist/data-list/data-list.mock.d.ts +16 -0
  632. package/dist/data-list/data-list.mock.js +2 -2
  633. package/dist/data-list/item.d.ts +50 -0
  634. package/dist/data-list/item.js +33 -32
  635. package/dist/data-list/selection.d.ts +16 -0
  636. package/dist/data-list/selection.js +13 -0
  637. package/dist/data-list/title.d.ts +26 -0
  638. package/dist/data-list/title.js +1 -0
  639. package/dist/data-list-ng/data-list-ng.js +6 -9
  640. package/dist/date-picker/consts.d.ts +99 -0
  641. package/dist/date-picker/consts.js +2 -21
  642. package/dist/date-picker/date-input.d.ts +57 -0
  643. package/dist/date-picker/date-input.js +8 -3
  644. package/dist/date-picker/date-picker.d.ts +70 -0
  645. package/dist/date-picker/date-picker.js +39 -39
  646. package/dist/date-picker/date-popup.d.ts +56 -0
  647. package/dist/date-picker/date-popup.js +44 -27
  648. package/dist/date-picker/day.d.ts +30 -0
  649. package/dist/date-picker/day.js +8 -4
  650. package/dist/date-picker/formats.d.ts +2 -0
  651. package/dist/date-picker/month-names.d.ts +13 -0
  652. package/dist/date-picker/month-names.js +6 -5
  653. package/dist/date-picker/month-slider.d.ts +29 -0
  654. package/dist/date-picker/month-slider.js +2 -2
  655. package/dist/date-picker/month.d.ts +14 -0
  656. package/dist/date-picker/months.d.ts +11 -0
  657. package/dist/date-picker/months.js +3 -3
  658. package/dist/date-picker/weekdays.d.ts +13 -0
  659. package/dist/date-picker/weekdays.js +1 -1
  660. package/dist/date-picker/years.d.ts +21 -0
  661. package/dist/date-picker/years.js +8 -6
  662. package/dist/dialog/dialog.d.ts +73 -0
  663. package/dist/dialog/dialog.js +4 -2
  664. package/dist/dialog/dialog__body-scroll-preventer.d.ts +9 -0
  665. package/dist/dialog-ng/dialog-ng.js +3 -3
  666. package/dist/dialog-ng/dialog-ng__template.js +1 -0
  667. package/dist/docked-panel-ng/docked-panel-ng.js +1 -1
  668. package/dist/dropdown/anchor.d.ts +11 -0
  669. package/dist/dropdown/anchor.js +1 -1
  670. package/dist/dropdown/dropdown.d.ts +77 -0
  671. package/dist/dropdown/dropdown.js +14 -7
  672. package/dist/dropdown-menu/dropdown-menu.d.ts +26 -0
  673. package/dist/dropdown-menu/dropdown-menu.js +9 -6
  674. package/dist/error-bubble/error-bubble.d.ts +18 -0
  675. package/dist/error-bubble/error-bubble.js +4 -2
  676. package/dist/error-message/error-message.d.ts +25 -0
  677. package/dist/footer/footer.d.ts +28 -0
  678. package/dist/global/compose.d.ts +7 -0
  679. package/dist/global/compose.js +2 -2
  680. package/dist/global/composeRefs.d.ts +3 -0
  681. package/dist/global/controls-height.d.ts +7 -0
  682. package/dist/global/controls-height.js +13 -0
  683. package/dist/global/create-stateful-context.d.ts +27 -0
  684. package/dist/global/data-tests.d.ts +3 -0
  685. package/dist/global/data-tests.js +5 -1
  686. package/dist/global/dom.d.ts +37 -0
  687. package/dist/global/dom.js +4 -4
  688. package/dist/global/focus-sensor-hoc.d.ts +18 -0
  689. package/dist/global/focus-sensor-hoc.js +58 -20
  690. package/dist/global/fuzzy-highlight.d.ts +5 -0
  691. package/dist/global/get-event-key.d.ts +2 -0
  692. package/dist/global/get-event-key.js +0 -1
  693. package/dist/global/get-uid.d.ts +1 -0
  694. package/dist/global/inject-styles.d.ts +3 -0
  695. package/dist/global/linear-function.d.ts +6 -0
  696. package/dist/global/listeners.d.ts +8 -0
  697. package/dist/global/listeners.js +10 -2
  698. package/dist/global/memoize.d.ts +1 -0
  699. package/dist/global/memoize.js +7 -6
  700. package/dist/global/normalize-indent.d.ts +1 -0
  701. package/dist/global/normalize-indent.js +5 -1
  702. package/dist/global/promise-with-timeout.d.ts +4 -0
  703. package/dist/global/prop-types.d.ts +4 -0
  704. package/dist/global/prop-types.js +7 -0
  705. package/dist/global/react-dom-renderer.d.ts +16 -0
  706. package/dist/global/react-dom-renderer.js +2 -0
  707. package/dist/global/rerender-hoc.d.ts +45 -0
  708. package/dist/global/rerender-hoc.js +5 -14
  709. package/dist/global/schedule-raf.d.ts +1 -0
  710. package/dist/global/schedule-raf.js +3 -1
  711. package/dist/global/sniffer.d.ts +3 -0
  712. package/dist/global/theme.d.ts +13 -0
  713. package/dist/global/theme.js +7 -54
  714. package/dist/global/trivial-template-tag.d.ts +1 -0
  715. package/dist/global/typescript-utils.d.ts +2 -0
  716. package/dist/global/typescript-utils.js +4 -0
  717. package/dist/global/url.d.ts +57 -0
  718. package/dist/global/url.js +1 -1
  719. package/dist/global/variables.d.ts +90 -0
  720. package/dist/global/variables.js +1 -0
  721. package/dist/grid/col.d.ts +31 -0
  722. package/dist/grid/col.js +7 -1
  723. package/dist/grid/grid.d.ts +14 -0
  724. package/dist/grid/row.d.ts +40 -0
  725. package/dist/grid/row.js +1 -4
  726. package/dist/group/group.d.ts +12 -0
  727. package/dist/header/header.d.ts +34 -0
  728. package/dist/header/header.js +14 -19
  729. package/dist/header/logo.d.ts +14 -0
  730. package/dist/header/profile.d.ts +73 -0
  731. package/dist/header/profile.js +4 -4
  732. package/dist/header/services-link.d.ts +25 -0
  733. package/dist/header/services.d.ts +33 -0
  734. package/dist/header/services.js +12 -3
  735. package/dist/header/smart-profile.d.ts +36 -0
  736. package/dist/header/smart-profile.js +11 -14
  737. package/dist/header/smart-services.d.ts +25 -0
  738. package/dist/header/smart-services.js +21 -16
  739. package/dist/header/tray-icon.d.ts +32 -0
  740. package/dist/header/tray-icon.js +2 -5
  741. package/dist/header/tray.d.ts +9 -0
  742. package/dist/heading/heading.d.ts +25 -0
  743. package/dist/heading/heading.js +15 -14
  744. package/dist/http/http.d.ts +49 -0
  745. package/dist/http/http.js +47 -12
  746. package/dist/http/http.mock.d.ts +20 -0
  747. package/dist/http/http.mock.js +12 -5
  748. package/dist/hub-source/hub-source.d.ts +42 -0
  749. package/dist/hub-source/hub-source.js +14 -1
  750. package/dist/hub-source/hub-source__user.d.ts +4 -0
  751. package/dist/hub-source/hub-source__user.js +4 -2
  752. package/dist/hub-source/hub-source__users-groups.d.ts +24 -0
  753. package/dist/hub-source/hub-source__users-groups.js +9 -1
  754. package/dist/icon/icon.d.ts +43 -0
  755. package/dist/icon/icon.js +2 -2
  756. package/dist/icon/icon__constants.d.ts +30 -0
  757. package/dist/icon/icon__constants.js +28 -23
  758. package/dist/icon/icon__svg.d.ts +15 -0
  759. package/dist/icon/index.d.ts +2 -0
  760. package/dist/icon/index.js +1 -1
  761. package/dist/input/input.d.ts +69 -0
  762. package/dist/input/input.js +93 -87
  763. package/dist/input-ng/input-ng.js +46 -49
  764. package/dist/island/adaptive-island-hoc.d.ts +65 -0
  765. package/dist/island/adaptive-island-hoc.js +6 -4
  766. package/dist/island/content.d.ts +12 -0
  767. package/dist/island/content.js +8 -6
  768. package/dist/island/header.d.ts +8 -0
  769. package/dist/island/header.js +16 -8
  770. package/dist/island/island.d.ts +82 -0
  771. package/dist/island-legacy/content-legacy.d.ts +10 -0
  772. package/dist/island-legacy/header-legacy.d.ts +10 -0
  773. package/dist/island-legacy/island-legacy.d.ts +12 -0
  774. package/dist/link/clickableLink.d.ts +20 -0
  775. package/dist/link/link.d.ts +157 -0
  776. package/dist/link/link.js +9 -5
  777. package/dist/list/consts.d.ts +74 -0
  778. package/dist/list/consts.js +26 -20
  779. package/dist/list/list.d.ts +191 -0
  780. package/dist/list/list.js +32 -26
  781. package/dist/list/list__custom.d.ts +6 -0
  782. package/dist/list/list__custom.js +8 -13
  783. package/dist/list/list__hint.d.ts +15 -0
  784. package/dist/list/list__item.d.ts +8 -0
  785. package/dist/list/list__item.js +3 -4
  786. package/dist/list/list__link.d.ts +9 -0
  787. package/dist/list/list__link.js +5 -6
  788. package/dist/list/list__separator.d.ts +5 -0
  789. package/dist/list/list__separator.js +2 -4
  790. package/dist/list/list__title.d.ts +5 -0
  791. package/dist/list/list__title.js +2 -4
  792. package/dist/list/list__users-groups-source.d.ts +27 -0
  793. package/dist/list/list__users-groups-source.js +22 -12
  794. package/dist/loader/loader.d.ts +28 -0
  795. package/dist/loader/loader.js +5 -1
  796. package/dist/loader/loader__core.d.ts +75 -0
  797. package/dist/loader/loader__core.js +90 -48
  798. package/dist/loader-inline/loader-inline.d.ts +18 -0
  799. package/dist/loader-inline/loader-inline.js +3 -21
  800. package/dist/loader-inline-ng/loader-inline-ng.js +2 -30
  801. package/dist/loader-screen/loader-screen.d.ts +17 -0
  802. package/dist/login-dialog/login-dialog.d.ts +47 -0
  803. package/dist/login-dialog/login-dialog.js +5 -3
  804. package/dist/login-dialog/service.d.ts +2 -0
  805. package/dist/login-dialog/service.js +6 -2
  806. package/dist/markdown/code.d.ts +9 -0
  807. package/dist/markdown/code.js +3 -3
  808. package/dist/markdown/heading.d.ts +11 -0
  809. package/dist/markdown/heading.js +2 -2
  810. package/dist/markdown/link.d.ts +12 -0
  811. package/dist/markdown/link.js +3 -3
  812. package/dist/markdown/markdown.d.ts +14 -0
  813. package/dist/markdown/markdown.js +19 -21
  814. package/dist/message/message.d.ts +59 -0
  815. package/dist/message/message.js +36 -27
  816. package/dist/old-browsers-message/old-browsers-message.d.ts +2 -0
  817. package/dist/old-browsers-message/old-browsers-message.js +10 -6
  818. package/dist/old-browsers-message/old-browsers-message__stop.d.ts +1 -0
  819. package/dist/old-browsers-message/white-list.d.ts +2 -0
  820. package/dist/old-browsers-message/white-list.js +3 -3
  821. package/dist/pager/pager.d.ts +83 -0
  822. package/dist/pager/pager.js +44 -37
  823. package/dist/pager-ng/pager-ng.js +6 -7
  824. package/dist/panel/panel.d.ts +12 -0
  825. package/dist/permissions/permissions.d.ts +111 -0
  826. package/dist/permissions/permissions.js +23 -4
  827. package/dist/permissions/permissions__cache.d.ts +93 -0
  828. package/dist/permissions/permissions__cache.js +10 -3
  829. package/dist/permissions-ng/permissions-ng.js +9 -9
  830. package/dist/popup/popup.consts.d.ts +37 -0
  831. package/dist/popup/popup.consts.js +43 -29
  832. package/dist/popup/popup.d.ts +141 -0
  833. package/dist/popup/popup.js +84 -54
  834. package/dist/popup/popup.target.d.ts +7 -0
  835. package/dist/popup/popup.target.js +3 -4
  836. package/dist/popup/position.d.ts +30 -0
  837. package/dist/popup/position.js +11 -6
  838. package/dist/popup-menu/popup-menu.d.ts +59 -0
  839. package/dist/popup-menu/popup-menu.js +7 -6
  840. package/dist/progress-bar/progress-bar.d.ts +58 -0
  841. package/dist/progress-bar/progress-bar.js +6 -8
  842. package/dist/progress-bar-ng/progress-bar-ng.js +0 -1
  843. package/dist/promised-click-ng/promised-click-ng.js +2 -2
  844. package/dist/query-assist/query-assist.d.ts +327 -0
  845. package/dist/query-assist/query-assist.js +136 -88
  846. package/dist/query-assist/query-assist__suggestions.d.ts +29 -0
  847. package/dist/query-assist-ng/query-assist-ng.js +2 -7
  848. package/dist/radio/radio.d.ts +18 -0
  849. package/dist/radio/radio__item.d.ts +28 -0
  850. package/dist/radio/radio__item.js +5 -2
  851. package/dist/save-field-ng/save-field-ng.js +2 -9
  852. package/dist/select/select.d.ts +289 -0
  853. package/dist/select/select.js +191 -218
  854. package/dist/select/select__filter.d.ts +20 -0
  855. package/dist/select/select__filter.js +3 -1
  856. package/dist/select/select__popup.d.ts +123 -0
  857. package/dist/select/select__popup.js +96 -77
  858. package/dist/select-ng/select-ng.js +8 -9
  859. package/dist/select-ng/select-ng__lazy.js +11 -16
  860. package/dist/shortcuts/core.d.ts +74 -0
  861. package/dist/shortcuts/core.js +16 -10
  862. package/dist/shortcuts/shortcut-title.d.ts +1 -0
  863. package/dist/shortcuts/shortcuts-hoc.d.ts +69 -0
  864. package/dist/shortcuts/shortcuts.d.ts +28 -0
  865. package/dist/shortcuts-hint-ng/shortcuts-hint-ng.js +2 -2
  866. package/dist/sidebar-ng/sidebar-ng.js +2 -2
  867. package/dist/storage/storage.d.ts +18 -0
  868. package/dist/storage/storage.js +10 -8
  869. package/dist/storage/storage__fallback.d.ts +79 -0
  870. package/dist/storage/storage__fallback.js +31 -19
  871. package/dist/storage/storage__local.d.ts +38 -0
  872. package/dist/storage/storage__local.js +43 -26
  873. package/dist/style.css +1 -1
  874. package/dist/tab-trap/tab-trap.d.ts +43 -0
  875. package/dist/tab-trap/tab-trap.js +17 -5
  876. package/dist/table/cell.d.ts +13 -0
  877. package/dist/table/disable-hover-hoc.d.ts +68 -0
  878. package/dist/table/disable-hover-hoc.js +1 -1
  879. package/dist/table/header-cell.d.ts +43 -0
  880. package/dist/table/header-cell.js +4 -0
  881. package/dist/table/header.d.ts +60 -0
  882. package/dist/table/header.js +9 -5
  883. package/dist/table/multitable.d.ts +25 -0
  884. package/dist/table/multitable.js +21 -7
  885. package/dist/table/row-with-focus-sensor.d.ts +18 -0
  886. package/dist/table/row-with-focus-sensor.js +8 -5
  887. package/dist/table/row.d.ts +56 -0
  888. package/dist/table/row.js +27 -25
  889. package/dist/table/selection-adapter.d.ts +5 -0
  890. package/dist/table/selection-shortcuts-hoc.d.ts +17 -0
  891. package/dist/table/selection-shortcuts-hoc.js +44 -19
  892. package/dist/table/selection.d.ts +47 -0
  893. package/dist/table/selection.js +18 -1
  894. package/dist/table/smart-table.d.ts +60 -0
  895. package/dist/table/smart-table.js +6 -4
  896. package/dist/table/table.d.ts +160 -0
  897. package/dist/table/table.js +59 -39
  898. package/dist/table-legacy-ng/table-legacy-ng.js +6 -7
  899. package/dist/table-legacy-ng/table-legacy-ng__pager.js +6 -7
  900. package/dist/table-ng/smart-table-ng.js +2 -1
  901. package/dist/table-ng/table-ng.js +4 -3
  902. package/dist/tabs/collapsible-more.d.ts +29 -0
  903. package/dist/tabs/collapsible-more.js +2 -1
  904. package/dist/tabs/collapsible-tab.d.ts +16 -0
  905. package/dist/tabs/collapsible-tab.js +9 -10
  906. package/dist/tabs/collapsible-tabs.d.ts +43 -0
  907. package/dist/tabs/collapsible-tabs.js +58 -107
  908. package/dist/tabs/custom-item.d.ts +9 -0
  909. package/dist/tabs/dumb-tabs.d.ts +33 -0
  910. package/dist/tabs/dumb-tabs.js +7 -12
  911. package/dist/tabs/smart-tabs.d.ts +20 -0
  912. package/dist/tabs/smart-tabs.js +2 -1
  913. package/dist/tabs/tab-link.d.ts +18 -0
  914. package/dist/tabs/tab.d.ts +27 -0
  915. package/dist/tabs/tabs.d.ts +7 -0
  916. package/dist/tabs/tabs.js +2 -1
  917. package/dist/tabs-ng/tabs-ng.js +1 -6
  918. package/dist/tabs-ng/tabs-ng__template.js +1 -1
  919. package/dist/tag/tag.d.ts +64 -0
  920. package/dist/tag/tag.js +9 -4
  921. package/dist/tags-input/tags-input.d.ts +154 -0
  922. package/dist/tags-input/tags-input.js +68 -39
  923. package/dist/tags-input-ng/tags-input-ng.js +7 -8
  924. package/dist/tags-list/tags-list.d.ts +46 -0
  925. package/dist/tags-list/tags-list.js +2 -8
  926. package/dist/text/text.d.ts +17 -0
  927. package/dist/text/text.js +1 -1
  928. package/dist/toggle/toggle.d.ts +39 -0
  929. package/dist/toggle/toggle.js +7 -10
  930. package/dist/toggle-ng/toggle-ng.js +0 -1
  931. package/dist/tooltip/tooltip.d.ts +65 -0
  932. package/dist/tooltip/tooltip.js +19 -7
  933. package/dist/user-agreement/service.d.ts +161 -0
  934. package/dist/user-agreement/service.js +29 -26
  935. package/dist/user-agreement/toolbox.eula.d.ts +2 -0
  936. package/dist/user-agreement/user-agreement.d.ts +69 -0
  937. package/dist/user-agreement/user-agreement.js +4 -7
  938. package/dist/user-card/card.d.ts +52 -0
  939. package/dist/user-card/smart-user-card-tooltip.d.ts +20 -0
  940. package/dist/user-card/smart-user-card-tooltip.js +5 -9
  941. package/dist/user-card/tooltip.d.ts +31 -0
  942. package/dist/user-card/tooltip.js +6 -2
  943. package/dist/user-card/user-card.d.ts +11 -0
  944. package/dist/user-card/user-card.js +3 -7
  945. package/dist/user-card-ng/user-card-ng.js +5 -9
  946. package/package.json +77 -52
  947. package/typings.d.ts +97 -0
  948. package/webpack.config.js +4 -12
  949. package/components/alert/alert.examples.js +0 -143
  950. package/components/alert/alert.test.js +0 -61
  951. package/components/alert/container.test.js +0 -12
  952. package/components/alert-service/alert-service.examples.js +0 -91
  953. package/components/alert-service/alert-service.test.js +0 -88
  954. package/components/analytics/analytics.examples.js +0 -47
  955. package/components/analytics/analytics.test.js +0 -419
  956. package/components/auth/auth.examples.js +0 -122
  957. package/components/auth/auth.test.js +0 -772
  958. package/components/auth/request-builder.test.js +0 -64
  959. package/components/auth/response-parser.test.js +0 -89
  960. package/components/auth/storage.test.js +0 -178
  961. package/components/auth/token-validator.test.js +0 -199
  962. package/components/auth-dialog/auth-dialog.examples.js +0 -75
  963. package/components/auth-dialog/auth-dialog.test.js +0 -11
  964. package/components/auth-dialog-service/auth-dialog-service.examples.js +0 -66
  965. package/components/auth-dialog-service/auth-dialog-service.test.js +0 -75
  966. package/components/avatar/avatar.examples.js +0 -46
  967. package/components/avatar/avatar.test.js +0 -59
  968. package/components/badge/badge.examples.js +0 -26
  969. package/components/badge/badge.test.js +0 -34
  970. package/components/button/button.examples.js +0 -219
  971. package/components/button/button.test.js +0 -64
  972. package/components/button-group/button-group.examples.js +0 -58
  973. package/components/button-group/button-group.test.js +0 -10
  974. package/components/button-set/button-set.examples.js +0 -24
  975. package/components/button-set/button-set.test.js +0 -10
  976. package/components/button-toolbar/button-toolbar.examples.js +0 -31
  977. package/components/button-toolbar/button-toolbar.test.js +0 -21
  978. package/components/caret/caret.examples.js +0 -39
  979. package/components/caret/caret.test.js +0 -137
  980. package/components/checkbox/checkbox.examples.js +0 -67
  981. package/components/checkbox/checkbox.test.js +0 -78
  982. package/components/code/code.examples.js +0 -92
  983. package/components/code/code.test.js +0 -100
  984. package/components/confirm/confirm.examples.js +0 -93
  985. package/components/confirm/confirm.test.js +0 -28
  986. package/components/confirm-service/confirm-service.examples.js +0 -61
  987. package/components/confirm-service/confirm-service.test.js +0 -59
  988. package/components/content-layout/content-layout.examples.js +0 -188
  989. package/components/content-layout/content-layout.test.js +0 -41
  990. package/components/contenteditable/contenteditable.examples.js +0 -45
  991. package/components/contenteditable/contenteditable.test.js +0 -73
  992. package/components/data-list/data-list.examples.js +0 -116
  993. package/components/data-list/data-list.test.js +0 -40
  994. package/components/date-picker/date-picker.examples.js +0 -345
  995. package/components/date-picker/date-picker.test.js +0 -89
  996. package/components/dialog/dialog.examples.js +0 -209
  997. package/components/dialog/dialog.test.js +0 -62
  998. package/components/dropdown/dropdown.examples.js +0 -151
  999. package/components/dropdown/dropdown.test.js +0 -175
  1000. package/components/dropdown-menu/dropdown-menu.examples.js +0 -47
  1001. package/components/dropdown-menu/dropdown-menu.test.js +0 -76
  1002. package/components/error-bubble/error-bubble.examples.js +0 -96
  1003. package/components/error-bubble/error-bubble.test.js +0 -41
  1004. package/components/error-message/error-message.examples.js +0 -33
  1005. package/components/error-message/error-message.test.js +0 -21
  1006. package/components/footer/footer.examples.js +0 -56
  1007. package/components/footer/footer.test.js +0 -78
  1008. package/components/global/conic-gradient.js +0 -31
  1009. package/components/global/data-tests.test.js +0 -18
  1010. package/components/global/dom.examples.js +0 -39
  1011. package/components/global/dom.test.js +0 -99
  1012. package/components/global/fuzzy-highlight.test.js +0 -52
  1013. package/components/global/get-uid.test.js +0 -21
  1014. package/components/global/listeners.test.js +0 -78
  1015. package/components/global/radial-gradient-mask.js +0 -43
  1016. package/components/global/supports-css.js +0 -17
  1017. package/components/global/url.test.js +0 -138
  1018. package/components/global/variables.examples.js +0 -160
  1019. package/components/global/variables_dark.js +0 -55
  1020. package/components/grid/grid.examples.js +0 -291
  1021. package/components/grid/grid.test.js +0 -72
  1022. package/components/group/group.examples.js +0 -27
  1023. package/components/group/group.test.js +0 -21
  1024. package/components/header/header.examples.js +0 -118
  1025. package/components/header/header.test.js +0 -21
  1026. package/components/heading/heading.examples.js +0 -64
  1027. package/components/heading/heading.test.js +0 -29
  1028. package/components/http/http.examples.js +0 -34
  1029. package/components/http/http.test.js +0 -187
  1030. package/components/hub-source/hub-source.test.js +0 -200
  1031. package/components/hub-source/hub-source__users-groups.test.js +0 -91
  1032. package/components/icon/icon.examples.js +0 -146
  1033. package/components/icon/icon.test.js +0 -51
  1034. package/components/input/input.examples.js +0 -140
  1035. package/components/input/input.test.js +0 -40
  1036. package/components/island/island.examples.js +0 -74
  1037. package/components/island/island.test.js +0 -59
  1038. package/components/island-legacy/island-legacy.examples.js +0 -33
  1039. package/components/island-legacy/island-legacy.test.js +0 -21
  1040. package/components/link/link.examples.js +0 -86
  1041. package/components/link/link.test.js +0 -182
  1042. package/components/list/list.examples.js +0 -271
  1043. package/components/list/list.test.js +0 -428
  1044. package/components/list/list__item.test.js +0 -60
  1045. package/components/list/list__users-groups-source.test.js +0 -125
  1046. package/components/loader/loader.examples.js +0 -22
  1047. package/components/loader/loader__core.test.js +0 -232
  1048. package/components/loader-inline/inject-styles.js +0 -28
  1049. package/components/loader-inline/loader-inline.examples.js +0 -106
  1050. package/components/loader-inline/loader-inline.test.js +0 -21
  1051. package/components/loader-screen/loader-screen.examples.js +0 -40
  1052. package/components/markdown/markdown.examples.js +0 -110
  1053. package/components/markdown/markdown.test.js +0 -60
  1054. package/components/message/message.examples.js +0 -78
  1055. package/components/message/message.test.js +0 -26
  1056. package/components/old-browsers-message/old-browsers-message.examples.js +0 -37
  1057. package/components/pager/pager.examples.js +0 -291
  1058. package/components/pager/pager.test.js +0 -56
  1059. package/components/panel/panel.examples.js +0 -33
  1060. package/components/panel/panel.test.js +0 -20
  1061. package/components/permissions/permissions.test.js +0 -435
  1062. package/components/permissions/permissions__cache.test.js +0 -75
  1063. package/components/popup/popup.examples.js +0 -340
  1064. package/components/popup/popup.test.js +0 -242
  1065. package/components/popup/position.test.js +0 -192
  1066. package/components/popup-menu/popup-menu.examples.js +0 -38
  1067. package/components/popup-menu/popup-menu.test.js +0 -29
  1068. package/components/progress-bar/progress-bar.examples.js +0 -56
  1069. package/components/progress-bar/progress-bar.test.js +0 -114
  1070. package/components/query-assist/query-assist.examples.js +0 -305
  1071. package/components/query-assist/query-assist.test.js +0 -690
  1072. package/components/radio/radio.examples.js +0 -58
  1073. package/components/radio/radio.test.js +0 -90
  1074. package/components/radio/radio__item.test.js +0 -98
  1075. package/components/select/select.examples.js +0 -1023
  1076. package/components/select/select.test.js +0 -1201
  1077. package/components/select/select__popup.test.js +0 -156
  1078. package/components/shortcuts/core.test.js +0 -282
  1079. package/components/shortcuts/shortcuts-hoc.test.js +0 -53
  1080. package/components/shortcuts/shortcuts.test.js +0 -45
  1081. package/components/storage/storage.examples.js +0 -37
  1082. package/components/storage/storage.test.js +0 -248
  1083. package/components/tab-trap/tab-trap.examples.js +0 -49
  1084. package/components/table/table.examples.js +0 -346
  1085. package/components/tabs/tabs.examples.js +0 -275
  1086. package/components/tabs/tabs.test.js +0 -26
  1087. package/components/tag/tag.examples.js +0 -50
  1088. package/components/tag/tag.test.js +0 -21
  1089. package/components/tags-input/tag-input.examples.js +0 -133
  1090. package/components/tags-input/tags-input.test.js +0 -234
  1091. package/components/tags-list/tags-list.examples.js +0 -41
  1092. package/components/tags-list/tags-list.test.js +0 -43
  1093. package/components/text/text.examples.js +0 -25
  1094. package/components/text/text.test.js +0 -25
  1095. package/components/toggle/toggle.examples.js +0 -79
  1096. package/components/toggle/toggle.test.js +0 -34
  1097. package/components/tooltip/tooltip.examples.js +0 -118
  1098. package/components/tooltip/tooltip.test.js +0 -128
  1099. package/components/user-agreement/user-agreement.examples.js +0 -112
  1100. package/components/user-card/user-card.examples.js +0 -88
  1101. package/components/user-card/user-card.test.js +0 -102
  1102. package/components/welcome.examples.js +0 -25
  1103. package/dist/_helpers/inject-styles.js +0 -22
  1104. package/dist/global/conic-gradient.js +0 -35
  1105. package/dist/global/radial-gradient-mask.js +0 -49
  1106. package/dist/global/supports-css.js +0 -20
  1107. package/dist/global/variables_dark.js +0 -57
  1108. package/dist/loader-inline/inject-styles.js +0 -11
@@ -1,905 +1,807 @@
1
- import {fixUrl, getAbsoluteBaseURL} from '../global/url';
1
+ import { fixUrl, getAbsoluteBaseURL } from '../global/url';
2
2
  import Listeners from '../global/listeners';
3
3
  import HTTP from '../http/http';
4
4
  import promiseWithTimeout from '../global/promise-with-timeout';
5
-
6
5
  import AuthStorage from './storage';
7
6
  import AuthResponseParser from './response-parser';
8
7
  import AuthRequestBuilder from './request-builder';
9
8
  import BackgroundFlow from './background-flow';
10
9
  import TokenValidator from './token-validator';
11
-
12
- /* eslint-disable no-magic-numbers */
10
+ /* eslint-disable @typescript-eslint/no-magic-numbers */
13
11
  export const DEFAULT_EXPIRES_TIMEOUT = 40 * 60;
14
12
  export const DEFAULT_BACKGROUND_TIMEOUT = 10 * 1000;
15
13
  const DEFAULT_BACKEND_CHECK_TIMEOUT = 10 * 1000;
16
14
  const BACKGROUND_REDIRECT_TIMEOUT = 20 * 1000;
17
15
  const DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT = 5 * 1000;
18
- /* eslint-enable no-magic-numbers */
19
-
16
+ /* eslint-enable @typescript-eslint/no-magic-numbers */
20
17
  export const USER_CHANGED_EVENT = 'userChange';
21
18
  export const DOMAIN_USER_CHANGED_EVENT = 'domainUser';
22
19
  export const LOGOUT_EVENT = 'logout';
23
20
  export const LOGOUT_POSTPONED_EVENT = 'logoutPostponed';
24
21
  export const USER_CHANGE_POSTPONED_EVENT = 'changePostponed';
25
-
26
- function noop() {}
27
-
22
+ function noop() { }
28
23
  const DEFAULT_CONFIG = {
29
- cacheCurrentUser: false,
30
- reloadOnUserChange: true,
31
- embeddedLogin: false,
32
- EmbeddedLoginFlow: null,
33
- clientId: '0-0-0-0-0',
34
- redirectUri: getAbsoluteBaseURL(),
35
- redirect: false,
36
- requestCredentials: 'default',
37
- backgroundRefreshTimeout: null,
38
- scope: [],
39
- userFields: ['guest', 'id', 'name', 'login', 'profile/avatar/url'],
40
- cleanHash: true,
41
- onLogout: noop,
42
- onPostponeChangedUser: () => {},
43
- onPostponeLogout: () => {},
44
- enableBackendStatusCheck: true,
45
- backendCheckTimeout: DEFAULT_BACKEND_CHECK_TIMEOUT,
46
- checkBackendIsUp: () => Promise.resolve(null),
47
- onBackendDown: () => {},
48
-
49
- defaultExpiresIn: DEFAULT_EXPIRES_TIMEOUT,
50
- waitForRedirectTimeout: DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT,
51
- translations: {
52
- login: 'Log in',
53
- loginTo: 'Log in to %serviceName%',
54
- cancel: 'Cancel',
55
- tryAgainLabel: 'Try again',
56
- postpone: 'Postpone',
57
- youHaveLoggedInAs: 'You have logged in as another user: %userName%',
58
- applyChange: 'Apply change',
59
- backendIsNotAvailable: 'Connection lost',
60
- checkAgain: 'try again',
61
- nothingHappensLink: 'Click here if nothing happens',
62
- errorMessage: 'There may be a problem with your network connection. Make sure that you are online and'
63
- }
24
+ cacheCurrentUser: false,
25
+ reloadOnUserChange: true,
26
+ embeddedLogin: false,
27
+ EmbeddedLoginFlow: null,
28
+ clientId: '0-0-0-0-0',
29
+ redirectUri: getAbsoluteBaseURL(),
30
+ redirect: false,
31
+ requestCredentials: 'default',
32
+ backgroundRefreshTimeout: null,
33
+ scope: [],
34
+ userFields: ['guest', 'id', 'name', 'login', 'profile/avatar/url'],
35
+ cleanHash: true,
36
+ onLogout: noop,
37
+ onPostponeChangedUser: () => { },
38
+ onPostponeLogout: () => { },
39
+ enableBackendStatusCheck: true,
40
+ backendCheckTimeout: DEFAULT_BACKEND_CHECK_TIMEOUT,
41
+ checkBackendIsUp: () => Promise.resolve(null),
42
+ onBackendDown: () => () => { },
43
+ defaultExpiresIn: DEFAULT_EXPIRES_TIMEOUT,
44
+ waitForRedirectTimeout: DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT,
45
+ translations: {
46
+ login: 'Log in',
47
+ loginTo: 'Log in to %serviceName%',
48
+ cancel: 'Cancel',
49
+ tryAgainLabel: 'Try again',
50
+ postpone: 'Postpone',
51
+ youHaveLoggedInAs: 'You have logged in as another user: %userName%',
52
+ applyChange: 'Apply change',
53
+ backendIsNotAvailable: 'Connection lost',
54
+ checkAgain: 'try again',
55
+ nothingHappensLink: 'Click here if nothing happens',
56
+ errorMessage: 'There may be a problem with your network connection. Make sure that you are online and'
57
+ }
64
58
  };
65
-
66
59
  export default class Auth {
67
- static DEFAULT_CONFIG = DEFAULT_CONFIG;
68
- static API_PATH = 'api/rest/';
69
- static API_AUTH_PATH = 'oauth2/auth';
70
- static API_PROFILE_PATH = 'users/me';
71
- static CLOSE_BACKEND_DOWN_MESSAGE = 'backend-check-succeeded';
72
- static CLOSE_WINDOW_MESSAGE = 'close-login-window';
73
- static shouldRefreshToken = TokenValidator.shouldRefreshToken;
74
- static storageIsUnavailable = !navigator.cookieEnabled;
75
-
76
- config = {};
77
- listeners = new Listeners();
78
- http = null;
79
- _service = {};
80
- _storage = null;
81
- _responseParser = new AuthResponseParser();
82
- _requestBuilder = null;
83
- _backgroundFlow = null;
84
- _embeddedFlow = null;
85
- _tokenValidator = null;
86
- _postponed = false;
87
- _backendCheckPromise = null;
88
- _authDialogService = undefined;
89
-
90
- constructor(config) {
91
- if (!config) {
92
- throw new Error('Config is required');
93
- }
94
-
95
- if (config.serverUri == null) {
96
- throw new Error('\"serverUri\" property is required');
97
- }
98
-
99
- const unsupportedParams = ['redirect_uri', 'request_credentials', 'client_id'].filter(param => config.hasOwnProperty(param));
100
- if (unsupportedParams.length !== 0) {
101
- throw new Error(`The following parameters are no longer supported: ${unsupportedParams.join(', ')}. Please change them from snake_case to camelCase.`);
102
- }
103
-
104
- config.userFields = config.userFields || [];
105
-
106
- this.config = {...Auth.DEFAULT_CONFIG, ...config};
107
-
108
- const {clientId, redirect, redirectUri, requestCredentials, scope} = this.config;
109
- const serverUriLength = this.config.serverUri.length;
110
-
111
- if (serverUriLength > 0 && this.config.serverUri.charAt(serverUriLength - 1) !== '/') {
112
- this.config.serverUri += '/';
113
- }
114
-
115
- this.config.userParams = {
116
- query: {
117
- fields: [...new Set(Auth.DEFAULT_CONFIG.userFields.concat(config.userFields))].join()
118
- }
119
- };
120
-
121
- if (!scope.includes(Auth.DEFAULT_CONFIG.clientId)) {
122
- scope.push(Auth.DEFAULT_CONFIG.clientId);
123
- }
124
-
125
- this._storage = new AuthStorage({
126
- messagePrefix: `${clientId}-message-`,
127
- stateKeyPrefix: `${clientId}-states-`,
128
- tokenKey: `${clientId}-token`,
129
- userKey: `${clientId}-user-`
130
- });
131
-
132
- this._domainStorage = new AuthStorage({messagePrefix: 'domain-message-'});
133
-
134
- this._requestBuilder = new AuthRequestBuilder({
135
- authorization: this.config.serverUri + Auth.API_PATH + Auth.API_AUTH_PATH,
136
- clientId,
137
- redirect,
138
- redirectUri,
139
- requestCredentials,
140
- scopes: scope
141
- }, this._storage);
142
-
143
- let {backgroundRefreshTimeout} = this.config;
144
- if (!backgroundRefreshTimeout) {
145
- backgroundRefreshTimeout = this.config.embeddedLogin
146
- ? DEFAULT_BACKGROUND_TIMEOUT
147
- : BACKGROUND_REDIRECT_TIMEOUT;
148
- }
149
-
150
- this._backgroundFlow = new BackgroundFlow(
151
- this._requestBuilder, this._storage, backgroundRefreshTimeout
152
- );
153
- if (this.config.EmbeddedLoginFlow) {
154
- this._embeddedFlow = new this.config.EmbeddedLoginFlow(
155
- this._requestBuilder,
156
- this._storage,
157
- this.config.translations
158
- );
159
- }
160
-
161
- const API_BASE = this.config.serverUri + Auth.API_PATH;
162
- const fetchConfig = config.fetchCredentials
163
- ? {credentials: config.fetchCredentials}
164
- : undefined;
165
- this.http = new HTTP(this, API_BASE, fetchConfig);
166
-
167
- const getUser = async token => {
168
- const user = await this.getUser(token);
169
- this.user = user;
170
- return user;
171
- };
172
-
173
- this._tokenValidator = new TokenValidator(this.config, getUser, this._storage);
174
-
175
- if (this.config.onLogout) {
176
- this.addListener(LOGOUT_EVENT, this.config.onLogout);
177
- }
178
-
179
- if (this.config.reloadOnUserChange === true) {
180
- this.addListener(USER_CHANGED_EVENT, () => this._reloadCurrentPage());
181
- }
182
-
183
- this.addListener(LOGOUT_POSTPONED_EVENT, () => this._setPostponed(true));
184
- this.addListener(USER_CHANGE_POSTPONED_EVENT, () => this._setPostponed(true));
185
- this.addListener(USER_CHANGED_EVENT, () => this._setPostponed(false));
186
- this.addListener(USER_CHANGED_EVENT, user => user && this._updateDomainUser(user.id));
187
- if (this.config.cacheCurrentUser) {
188
- this.addListener(LOGOUT_EVENT, () => this._storage.wipeCachedCurrentUser());
189
- this.addListener(USER_CHANGED_EVENT, () => this._storage.onUserChanged());
190
- }
191
-
192
- this._createInitDeferred();
193
-
194
- this.setUpPreconnect(config.serverUri);
195
- }
196
-
197
- _setPostponed(postponed = false) {
198
- this._postponed = postponed;
199
- }
200
-
201
- _updateDomainUser(userID) {
202
- this._domainStorage.sendMessage(DOMAIN_USER_CHANGED_EVENT, {
203
- userID,
204
- serviceID: this.config.clientId
205
- });
206
- }
207
-
208
- addListener(event, handler) {
209
- this.listeners.add(event, handler);
210
- }
211
-
212
- removeListener(event, handler) {
213
- this.listeners.remove(event, handler);
214
- }
215
-
216
- setAuthDialogService(authDialogService) {
217
- this._authDialogService = authDialogService;
218
- }
219
-
220
- setCurrentService(service) {
221
- this._service = service;
222
- }
223
-
224
- _createInitDeferred() {
225
- this._initDeferred = {};
226
- this._initDeferred.promise = new Promise((resolve, reject) => {
227
- this._initDeferred.resolve = resolve;
228
- this._initDeferred.reject = reject;
229
- });
230
- }
231
-
232
- /**
233
- * @return {Promise.<string>} absolute URL promise that is resolved to a URL
234
- * that should be restored after returning back from auth server.
235
- */
236
- async init() {
237
- this._storage.onTokenChange(async token => {
238
- const isGuest = this.user ? this.user.guest : false;
239
-
240
- if (isGuest && !token) {
241
- return;
242
- }
243
-
244
- if (!token) {
245
- this.logout();
246
- } else {
60
+ static DEFAULT_CONFIG = DEFAULT_CONFIG;
61
+ static API_PATH = 'api/rest/';
62
+ static API_AUTH_PATH = 'oauth2/auth';
63
+ static API_PROFILE_PATH = 'users/me';
64
+ static CLOSE_BACKEND_DOWN_MESSAGE = 'backend-check-succeeded';
65
+ static CLOSE_WINDOW_MESSAGE = 'close-login-window';
66
+ static shouldRefreshToken = TokenValidator.shouldRefreshToken;
67
+ static storageIsUnavailable = !navigator.cookieEnabled;
68
+ config;
69
+ listeners = new Listeners();
70
+ http;
71
+ _service = {};
72
+ _storage = null;
73
+ _responseParser = new AuthResponseParser();
74
+ _requestBuilder = null;
75
+ _backgroundFlow;
76
+ _embeddedFlow = null;
77
+ _tokenValidator = null;
78
+ _postponed = false;
79
+ _backendCheckPromise = null;
80
+ _authDialogService = undefined;
81
+ _domainStorage;
82
+ user = null;
83
+ _initDeferred;
84
+ _isLoginWindowOpen;
85
+ constructor(config) {
86
+ if (!config) {
87
+ throw new Error('Config is required');
88
+ }
89
+ if (config.serverUri == null) {
90
+ throw new Error('\"serverUri\" property is required');
91
+ }
92
+ const unsupportedParams = ['redirect_uri', 'request_credentials', 'client_id'].filter(param => config.hasOwnProperty(param));
93
+ if (unsupportedParams.length !== 0) {
94
+ throw new Error(`The following parameters are no longer supported: ${unsupportedParams.join(', ')}. Please change them from snake_case to camelCase.`);
95
+ }
96
+ config.userFields = config.userFields || [];
97
+ this.config = { ...Auth.DEFAULT_CONFIG, ...config };
98
+ const { clientId, redirect, redirectUri, requestCredentials, scope } = this.config;
99
+ const serverUriLength = this.config.serverUri.length;
100
+ if (serverUriLength > 0 && this.config.serverUri.charAt(serverUriLength - 1) !== '/') {
101
+ this.config.serverUri += '/';
102
+ }
103
+ this.config.userParams = {
104
+ query: {
105
+ fields: [...new Set(Auth.DEFAULT_CONFIG.userFields.concat(config.userFields))].join()
106
+ }
107
+ };
108
+ if (!scope.includes(Auth.DEFAULT_CONFIG.clientId)) {
109
+ scope.push(Auth.DEFAULT_CONFIG.clientId);
110
+ }
111
+ this._storage = new AuthStorage({
112
+ messagePrefix: `${clientId}-message-`,
113
+ stateKeyPrefix: `${clientId}-states-`,
114
+ tokenKey: `${clientId}-token`,
115
+ userKey: `${clientId}-user-`
116
+ });
117
+ this._domainStorage = new AuthStorage({ messagePrefix: 'domain-message-' });
118
+ this._requestBuilder = new AuthRequestBuilder({
119
+ authorization: this.config.serverUri + Auth.API_PATH + Auth.API_AUTH_PATH,
120
+ clientId,
121
+ redirect,
122
+ redirectUri,
123
+ requestCredentials,
124
+ scopes: scope
125
+ }, this._storage);
126
+ let { backgroundRefreshTimeout } = this.config;
127
+ if (!backgroundRefreshTimeout) {
128
+ backgroundRefreshTimeout = this.config.embeddedLogin
129
+ ? DEFAULT_BACKGROUND_TIMEOUT
130
+ : BACKGROUND_REDIRECT_TIMEOUT;
131
+ }
132
+ this._backgroundFlow = new BackgroundFlow(this._requestBuilder, this._storage, backgroundRefreshTimeout);
133
+ if (this.config.EmbeddedLoginFlow) {
134
+ this._embeddedFlow = new this.config.EmbeddedLoginFlow(this._requestBuilder, this._storage, this.config.translations);
135
+ }
136
+ const API_BASE = this.config.serverUri + Auth.API_PATH;
137
+ const fetchConfig = config.fetchCredentials
138
+ ? { credentials: config.fetchCredentials }
139
+ : undefined;
140
+ this.http = new HTTP(this, API_BASE, fetchConfig);
141
+ const getUser = async (token) => {
142
+ const user = await this.getUser(token);
143
+ this.user = user;
144
+ return user;
145
+ };
146
+ this._tokenValidator = new TokenValidator(this.config, getUser, this._storage);
147
+ if (this.config.onLogout) {
148
+ this.addListener(LOGOUT_EVENT, this.config.onLogout);
149
+ }
150
+ if (this.config.reloadOnUserChange) {
151
+ this.addListener(USER_CHANGED_EVENT, () => this._reloadCurrentPage());
152
+ }
153
+ this.addListener(LOGOUT_POSTPONED_EVENT, () => this._setPostponed(true));
154
+ this.addListener(USER_CHANGE_POSTPONED_EVENT, () => this._setPostponed(true));
155
+ this.addListener(USER_CHANGED_EVENT, () => this._setPostponed(false));
156
+ this.addListener(USER_CHANGED_EVENT, (user) => {
157
+ if (user) {
158
+ this._updateDomainUser(user.id);
159
+ }
160
+ });
161
+ if (this.config.cacheCurrentUser) {
162
+ this.addListener(LOGOUT_EVENT, () => this._storage?.wipeCachedCurrentUser());
163
+ this.addListener(USER_CHANGED_EVENT, () => this._storage?.onUserChanged());
164
+ }
165
+ this._createInitDeferred();
166
+ this.setUpPreconnect(config.serverUri);
167
+ }
168
+ _setPostponed(postponed = false) {
169
+ this._postponed = postponed;
170
+ }
171
+ _updateDomainUser(userID) {
172
+ this._domainStorage.sendMessage(DOMAIN_USER_CHANGED_EVENT, {
173
+ userID,
174
+ serviceID: this.config.clientId
175
+ });
176
+ }
177
+ addListener(event, handler) {
178
+ this.listeners.add(event, handler);
179
+ }
180
+ removeListener(event, handler) {
181
+ this.listeners.remove(event, handler);
182
+ }
183
+ setAuthDialogService(authDialogService) {
184
+ this._authDialogService = authDialogService;
185
+ }
186
+ setCurrentService(service) {
187
+ this._service = service;
188
+ }
189
+ _createInitDeferred() {
190
+ const deferred = {};
191
+ deferred.promise = new Promise((resolve, reject) => {
192
+ deferred.resolve = resolve;
193
+ deferred.reject = reject;
194
+ });
195
+ this._initDeferred = deferred;
196
+ }
197
+ /**
198
+ * @return {Promise.<string>} absolute URL promise that is resolved to a URL
199
+ * that should be restored after returning back from auth server.
200
+ */
201
+ async init() {
202
+ this._storage?.onTokenChange(async (token) => {
203
+ const isGuest = this.user ? this.user.guest : false;
204
+ if (isGuest && !token) {
205
+ return;
206
+ }
207
+ if (!token) {
208
+ this.logout();
209
+ }
210
+ else {
211
+ try {
212
+ await this._detectUserChange(token.accessToken);
213
+ }
214
+ catch (error) {
215
+ if (!(error instanceof Error)) {
216
+ throw error;
217
+ }
218
+ if (this._canShowDialogs()) {
219
+ this._showAuthDialog({ nonInteractive: true, error });
220
+ }
221
+ }
222
+ }
223
+ });
224
+ this._domainStorage.onMessage(DOMAIN_USER_CHANGED_EVENT, (message) => {
225
+ const { userID, serviceID } = message || {};
226
+ if (serviceID === this.config.clientId) {
227
+ return;
228
+ }
229
+ if (this.user && userID === this.user.id) {
230
+ return;
231
+ }
232
+ this.forceTokenUpdate();
233
+ });
234
+ let state;
247
235
  try {
248
- await this._detectUserChange(token.accessToken);
249
- } catch (error) {
250
- if (this._canShowDialogs()) {
251
- this._showAuthDialog({nonInteractive: true, error});
252
- }
253
- }
254
- }
255
- });
256
-
257
- this._domainStorage.onMessage(DOMAIN_USER_CHANGED_EVENT, ({userID, serviceID}) => {
258
- if (serviceID === this.config.clientId) {
259
- return;
260
- }
261
- if (this.user && userID === this.user.id) {
262
- return;
263
- }
264
- this.forceTokenUpdate();
265
- });
266
-
267
- let state;
268
-
269
- try {
270
- // Look for token or error in hash
271
- state = await this._checkForAuthResponse();
272
- } catch (error) {
273
- return this.handleInitError(error);
274
- }
275
-
276
- // Return endless promise in the background to avoid service start
277
- if (state && state.nonRedirect) {
278
- return new Promise(noop);
279
- }
280
-
281
- try {
282
- // Check if there is a valid token
283
- await this._tokenValidator.validateToken();
284
-
285
-
286
- // Checking if there is a message left by another app on this domain
287
- const message = await this._domainStorage._messagesStorage.get(`domain-message-${DOMAIN_USER_CHANGED_EVENT}`);
288
- if (message) {
289
- const {userID, serviceID} = message;
290
- if (serviceID !== this.config.clientId && (!userID || this.user.id !== userID)) {
291
- this.forceTokenUpdate();
292
- }
293
- }
294
-
295
- // Access token appears to be valid.
296
- // We may resolve restoreLocation URL now
297
- if (!state) {
298
- // Check if we have requested to restore state anyway
299
- state = await this._checkForStateRestoration();
300
- }
301
- this._initDeferred.resolve(state && state.restoreLocation);
302
- return state?.restoreLocation;
303
- } catch (error) {
304
- if (Auth.storageIsUnavailable) {
305
- this._initDeferred.resolve(); // No way to handle if cookies are disabled
306
- await this.requestUser(); // Someone may expect user to be loaded as a part of token validation
307
- return null;
308
- }
309
- return this.handleInitValidationError(error);
310
- }
311
- }
312
-
313
- async sendRedirect(error) {
314
- const authRequest = await this._requestBuilder.prepareAuthRequest();
315
- this._redirectCurrentPage(authRequest.url);
316
-
317
- // HUB-10867 Since we already redirecting the page, there is no actual need to throw an error
318
- // and scare user with flashing error
319
- // But let's keep it just in case redirect was not successful
320
- await new Promise(resolve => setTimeout(resolve, this.config.waitForRedirectTimeout));
321
-
322
- throw error;
323
- }
324
-
325
- async handleInitError(error) {
326
- if (error.stateId) {
327
- try {
328
- const state = await this._storage.getState(error.stateId);
329
-
236
+ // Look for token or error in hash
237
+ state = await this._checkForAuthResponse();
238
+ }
239
+ catch (error) {
240
+ return error instanceof Error ? this.handleInitError(error) : undefined;
241
+ }
242
+ // Return endless promise in the background to avoid service start
330
243
  if (state && state.nonRedirect) {
331
- state.error = error;
332
- this._storage.saveState(error.stateId, state);
333
-
334
- // Return endless promise in the background to avoid service start
335
- return new Promise(noop);
336
- }
337
- } catch (e) {
338
- // Throw the orginal error instead below
339
- }
340
- }
341
-
342
- throw error;
343
- }
344
-
345
- async handleInitValidationError(error) {
346
- // Redirect flow
347
- if (error.authRedirect && this.config.redirect) {
348
- return this.sendRedirect(error);
349
- }
350
-
351
- // Background flow
352
- if (error.authRedirect && !this.config.redirect) {
353
- try {
354
- await this._backgroundFlow.authorize();
355
- await this._tokenValidator.validateToken();
356
- this._initDeferred.resolve();
357
- return undefined;
358
- } catch (validationError) {
359
- // Fallback to redirect flow
360
- return this.sendRedirect(validationError);
361
- }
362
- }
363
-
364
- this._initDeferred.reject(error);
365
- throw error;
366
- }
367
-
368
- /**
369
- * Get token from local storage or request it if necessary.
370
- * Can redirect to login page.
371
- * @return {Promise.<string>}
372
- */
373
- async requestToken() {
374
- if (this._postponed) {
375
- throw new Error('You should log in to be able to make requests');
376
- }
377
-
378
- try {
379
- await this._initDeferred.promise;
380
-
381
- if (Auth.storageIsUnavailable) {
382
- return null; // Forever guest if storage is unavailable
383
- }
384
- return await this._tokenValidator.validateTokenLocally();
385
- } catch (e) {
386
- return this.forceTokenUpdate();
387
- }
388
- }
389
-
390
- /**
391
- * Get new token in the background or redirect to the login page.
392
- * @return {Promise.<string>}
393
- */
394
- async forceTokenUpdate() {
395
- try {
396
- if (!this._backendCheckPromise) {
397
- this._backendCheckPromise = this._checkBackendsStatusesIfEnabled();
398
- }
399
- await this._backendCheckPromise;
400
- } catch (e) {
401
- throw new Error('Cannot refresh token: backend is not available. Postponed by user.');
402
- } finally {
403
- this._backendCheckPromise = null;
404
- }
405
-
406
- try {
407
- return await this._backgroundFlow.authorize();
408
- } catch (error) {
409
- if (this._canShowDialogs()) {
410
- return new Promise(resolve => {
411
- const onTryAgain = async () => {
244
+ return new Promise(noop);
245
+ }
246
+ try {
247
+ // Check if there is a valid token
248
+ await this._tokenValidator?.validateToken();
249
+ // Checking if there is a message left by another app on this domain
250
+ const message = await this._domainStorage._messagesStorage.get(`domain-message-${DOMAIN_USER_CHANGED_EVENT}`);
251
+ if (message) {
252
+ const { userID, serviceID } = message;
253
+ if (serviceID !== this.config.clientId && (!userID || this.user?.id !== userID)) {
254
+ this.forceTokenUpdate();
255
+ }
256
+ }
257
+ // Access token appears to be valid.
258
+ // We may resolve restoreLocation URL now
259
+ if (!state) {
260
+ // Check if we have requested to restore state anyway
261
+ state = await this._checkForStateRestoration();
262
+ }
263
+ this._initDeferred?.resolve?.(state && state.restoreLocation);
264
+ return state?.restoreLocation;
265
+ }
266
+ catch (error) {
267
+ if (Auth.storageIsUnavailable) {
268
+ this._initDeferred?.resolve?.(); // No way to handle if cookies are disabled
269
+ await this.requestUser(); // Someone may expect user to be loaded as a part of token validation
270
+ return null;
271
+ }
272
+ return error instanceof Error ? this.handleInitValidationError(error) : undefined;
273
+ }
274
+ }
275
+ async sendRedirect(error) {
276
+ const authRequest = await this._requestBuilder?.prepareAuthRequest();
277
+ if (authRequest != null) {
278
+ this._redirectCurrentPage(authRequest.url);
279
+ }
280
+ // HUB-10867 Since we already redirecting the page, there is no actual need to throw an error
281
+ // and scare user with flashing error
282
+ // But let's keep it just in case redirect was not successful
283
+ await new Promise(resolve => setTimeout(resolve, this.config.waitForRedirectTimeout));
284
+ throw error;
285
+ }
286
+ async handleInitError(error) {
287
+ if ('stateId' in error && error.stateId) {
412
288
  try {
413
- const result = await this._backgroundFlow.authorize();
414
- resolve(result);
415
- } catch (retryError) {
416
- this._showAuthDialog({
417
- nonInteractive: true,
418
- error: retryError,
419
- onTryAgain
420
- });
421
- throw retryError;
422
- }
423
- };
424
- this._showAuthDialog({
425
- nonInteractive: true,
426
- error,
427
- onTryAgain
428
- });
429
- });
430
- } else {
431
- const authRequest = await this._requestBuilder.prepareAuthRequest();
432
- this._redirectCurrentPage(authRequest.url);
433
- }
434
-
435
- throw new TokenValidator.TokenValidationError(error.message);
436
- }
437
- }
438
-
439
- async loadCurrentService() {
440
- if (this._service.serviceName) {
441
- return;
442
- }
443
- try {
444
- const {serviceName, iconUrl: serviceImage} = await this.http.get(`oauth2/interactive/login/settings?client_id=${this.config.clientId}`) || {};
445
- this.setCurrentService({serviceImage, serviceName});
446
- } catch (e) {
447
- // noop
448
- }
449
- }
450
-
451
- getAPIPath() {
452
- return this.config.serverUri + Auth.API_PATH;
453
- }
454
-
455
- /**
456
- * @return {Promise.<object>}
457
- */
458
- getUser(accessToken) {
459
- if (this.config.cacheCurrentUser) {
460
- return this._storage.getCachedUser(
461
- () => this.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, this.config.userParams)
462
- );
463
- } else {
464
- return this.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, this.config.userParams);
465
- }
466
- }
467
-
468
- /**
469
- * @return {Promise.<object>}
470
- */
471
- async requestUser() {
472
- if (this.user) {
473
- return this.user;
474
- }
475
-
476
- const accessToken = await this.requestToken();
477
-
478
- // If user was fetched during token request
479
- if (this.user) {
480
- return this.user;
481
- }
482
-
483
- const user = await this.getUser(accessToken);
484
- this.user = user;
485
-
486
- return user;
487
- }
488
-
489
- async updateUser() {
490
- this._setPostponed(false);
491
- const accessToken = await this.requestToken();
492
- this._storage.wipeCachedCurrentUser();
493
- const user = await this.getUser(accessToken);
494
- this.user = user;
495
- this.listeners.trigger(USER_CHANGED_EVENT, user);
496
- }
497
-
498
- async _detectUserChange(accessToken) {
499
- const windowWasOpen = this._isLoginWindowOpen;
500
-
501
- const user = await this.getUser(accessToken);
502
- const onApply = () => {
503
- this.user = user;
504
- this.listeners.trigger(USER_CHANGED_EVENT, user);
505
- };
506
-
507
- if (user && this.user && this.user.id !== user.id) {
508
- if (!this._canShowDialogs() || this.user.guest || windowWasOpen) {
509
- onApply();
510
- return;
511
- }
512
- if (user.guest) {
513
- this._showAuthDialog({nonInteractive: true});
514
- return;
515
- }
516
-
517
- await this._showUserChangedDialog({
518
- newUser: user,
519
- onApply,
520
- onPostpone: () => {
521
- this.listeners.trigger(USER_CHANGE_POSTPONED_EVENT);
522
- this.config.onPostponeChangedUser(this.user, user);
523
- }
524
- });
525
-
526
- }
527
- }
528
-
529
- _beforeLogout(params) {
530
- if (this._canShowDialogs()) {
531
- this._showAuthDialog(params);
532
- return;
533
- }
534
-
535
- this.logout();
536
- }
537
-
538
- _showAuthDialog({nonInteractive, error, canCancel, onTryAgain} = {}) {
539
- const {embeddedLogin, onPostponeLogout, translations} = this.config;
540
- const cancelable = this.user.guest || canCancel;
541
-
542
- this._createInitDeferred();
543
-
544
- const closeDialog = () => {
545
- /* eslint-disable no-use-before-define */
546
- stopTokenListening();
547
- stopMessageListening();
548
- hide();
549
- /* eslint-enable no-use-before-define */
550
- };
551
-
552
- const onConfirm = () => {
553
- if (embeddedLogin !== true) {
554
- closeDialog();
555
- this.logout();
556
- return;
557
- }
558
- this._runEmbeddedLogin();
559
- };
560
-
561
- const onCancel = () => {
562
- this._embeddedFlow.stop();
563
- this._storage.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
564
- closeDialog();
565
- if (!cancelable) {
566
- this._initDeferred.resolve();
567
- this.listeners.trigger(LOGOUT_POSTPONED_EVENT);
568
- onPostponeLogout();
569
- return;
570
- }
571
-
572
- if (this.user.guest && nonInteractive) {
573
- this.forceTokenUpdate();
574
- } else {
575
- this._initDeferred.resolve();
576
- }
577
- };
578
-
579
- const onTryAgainClick = async () => {
580
- await onTryAgain();
581
- closeDialog();
582
- };
583
-
584
- const hide = this._authDialogService({
585
- ...this._service,
586
- loginCaption: translations.login,
587
- loginToCaption: translations.loginTo,
588
- confirmLabel: translations.login,
589
- tryAgainLabel: translations.tryAgainLabel,
590
- cancelLabel: cancelable ? translations.cancel : translations.postpone,
591
- errorMessage: this._extractErrorMessage(error, true),
592
- onConfirm,
593
- onCancel,
594
- onTryAgain: onTryAgain ? onTryAgainClick : null
595
- });
596
-
597
- const stopTokenListening = this._storage.onTokenChange(token => {
598
- if (token) {
599
- closeDialog();
600
- this._initDeferred.resolve();
601
- }
602
- });
603
-
604
- const stopMessageListening = this._storage.onMessage(
605
- Auth.CLOSE_WINDOW_MESSAGE,
606
- () => this._embeddedFlow.stop()
607
- );
608
- }
609
-
610
- _showUserChangedDialog({newUser, onApply, onPostpone} = {}) {
611
- const {translations} = this.config;
612
-
613
- this._createInitDeferred();
614
-
615
- const done = () => {
616
- this._initDeferred.resolve();
617
- // eslint-disable-next-line no-use-before-define
618
- hide();
619
- };
620
-
621
- const hide = this._authDialogService({
622
- ...this._service,
623
- title: translations.youHaveLoggedInAs.replace('%userName%', newUser.name),
624
- loginCaption: translations.login,
625
- loginToCaption: translations.loginTo,
626
- confirmLabel: translations.applyChange,
627
- cancelLabel: translations.postpone,
628
- onConfirm: () => {
629
- done();
630
- onApply();
631
- },
632
- onCancel: () => {
633
- done();
634
- onPostpone();
635
- }
636
- });
637
- }
638
-
639
- _extractErrorMessage(error, logError = false) {
640
- if (!error) {
641
- return null;
642
- }
643
- if (logError) {
644
- // eslint-disable-next-line no-console
645
- console.error('RingUI Auth error', error);
646
- }
647
-
648
- try {
649
- // We've got some error from this list
650
- // https://www.jetbrains.com/help/youtrack/devportal/OAuth-2.0-Errors.html
651
- if (error.code && typeof error.code.code === 'string') {
652
- const readableCode = error.code.code.split('_').join(' ');
653
- return `Authorization error: ${readableCode}`;
654
- }
655
- } catch {
656
- // noop
657
- }
658
-
659
- return error.toString ? error.toString() : null;
660
- }
661
-
662
- _showBackendDownDialog(backendError) {
663
- const {onBackendDown, translations} = this.config;
664
- const REPEAT_TIMEOUT = 5000;
665
- let timerId = null;
666
-
667
- return new Promise((resolve, reject) => {
668
- const done = () => {
669
- /* eslint-disable no-use-before-define */
670
- hide();
671
- window.removeEventListener('online', onCheckAgain);
672
- stopListeningCloseMessage();
673
- /* eslint-enable no-use-before-define */
674
- this._storage.sendMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, Date.now());
675
- this._awaitingForBackendPromise = null;
676
- clearTimeout(timerId);
677
- };
678
-
679
- const stopListeningCloseMessage = this._storage.onMessage(
680
- Auth.CLOSE_BACKEND_DOWN_MESSAGE,
681
- () => {
682
- stopListeningCloseMessage();
683
- done();
684
- resolve();
685
- }
686
- );
687
-
688
- const onCheckAgain = async () => {
689
- await this._checkBackendsAreUp();
690
- done();
691
- resolve();
692
- };
693
-
694
- const onPostpone = () => {
695
- done();
696
- reject(new Error('Auth(@jetbrains/ring-ui): postponed by user'));
697
- };
698
-
699
- const hide = onBackendDown({onCheckAgain, onPostpone, backendError, translations});
700
-
701
- window.addEventListener('online', onCheckAgain);
702
-
703
- function networkWatchdog() {
704
- if (navigator && navigator.onLine) {
705
- onCheckAgain();
706
- }
707
- timerId = setTimeout(networkWatchdog, REPEAT_TIMEOUT);
708
- }
709
-
710
- timerId = setTimeout(networkWatchdog, REPEAT_TIMEOUT);
711
- });
712
- }
713
-
714
- /**
715
- * Wipe accessToken and redirect to auth page with required authorization
716
- */
717
- async logout(extraParams) {
718
- const requestParams = {
719
- // eslint-disable-next-line camelcase
720
- request_credentials: 'required',
721
- ...extraParams
722
- };
723
-
724
- await this._checkBackendsStatusesIfEnabled();
725
- await this.listeners.trigger(LOGOUT_EVENT);
726
- this._updateDomainUser(null);
727
- await this._storage.wipeToken();
728
-
729
- const authRequest = await this._requestBuilder.prepareAuthRequest(requestParams);
730
- this._redirectCurrentPage(authRequest.url);
731
- }
732
-
733
- async _runEmbeddedLogin() {
734
- this._storage.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
735
- try {
736
- this._isLoginWindowOpen = true;
737
- return await this._embeddedFlow.authorize();
738
- } catch (e) {
739
- throw e;
740
- } finally {
741
- this._isLoginWindowOpen = false;
742
- }
743
- }
744
-
745
- /**
746
- * Wipe accessToken and redirect to auth page to obtain authorization data
747
- * if user is logged in or log her in otherwise
748
- */
749
- async login() {
750
- if (this.config.embeddedLogin) {
751
- await this._runEmbeddedLogin();
752
- return;
753
- }
754
-
755
- await this._checkBackendsStatusesIfEnabled();
756
- try {
757
- const accessToken = await this._backgroundFlow.authorize();
758
- const user = await this.getUser(accessToken);
759
-
760
- if (user.guest) {
761
- this._beforeLogout();
762
- } else {
289
+ const state = await this._storage?.getState(error.stateId);
290
+ if (state && state.nonRedirect) {
291
+ state.error = error;
292
+ this._storage?.saveState(error.stateId, state);
293
+ // Return endless promise in the background to avoid service start
294
+ return new Promise(noop);
295
+ }
296
+ }
297
+ catch (e) {
298
+ // Throw the original error instead below
299
+ }
300
+ }
301
+ throw error;
302
+ }
303
+ async handleInitValidationError(error) {
304
+ // Redirect flow
305
+ if ('authRedirect' in error && error.authRedirect && this.config.redirect) {
306
+ return this.sendRedirect(error);
307
+ }
308
+ // Background flow
309
+ if ('authRedirect' in error && error.authRedirect && !this.config.redirect) {
310
+ try {
311
+ await this._backgroundFlow?.authorize();
312
+ await this._tokenValidator?.validateToken();
313
+ this._initDeferred?.resolve?.();
314
+ return undefined;
315
+ }
316
+ catch (validationError) {
317
+ // Fallback to redirect flow
318
+ return validationError instanceof Error ? this.sendRedirect(validationError) : undefined;
319
+ }
320
+ }
321
+ this._initDeferred?.reject?.(error);
322
+ throw error;
323
+ }
324
+ /**
325
+ * Get token from local storage or request it if necessary.
326
+ * Can redirect to login page.
327
+ * @return {Promise.<string>}
328
+ */
329
+ async requestToken() {
330
+ if (this._postponed) {
331
+ throw new Error('You should log in to be able to make requests');
332
+ }
333
+ try {
334
+ await this._initDeferred?.promise;
335
+ if (Auth.storageIsUnavailable) {
336
+ return null; // Forever guest if storage is unavailable
337
+ }
338
+ return await this._tokenValidator?.validateTokenLocally() ?? null;
339
+ }
340
+ catch (e) {
341
+ return this.forceTokenUpdate();
342
+ }
343
+ }
344
+ /**
345
+ * Get new token in the background or redirect to the login page.
346
+ * @return {Promise.<string>}
347
+ */
348
+ async forceTokenUpdate() {
349
+ try {
350
+ if (!this._backendCheckPromise) {
351
+ this._backendCheckPromise = this._checkBackendsStatusesIfEnabled();
352
+ }
353
+ await this._backendCheckPromise;
354
+ }
355
+ catch (e) {
356
+ throw new Error('Cannot refresh token: backend is not available. Postponed by user.');
357
+ }
358
+ finally {
359
+ this._backendCheckPromise = null;
360
+ }
361
+ try {
362
+ return await this._backgroundFlow?.authorize() ?? null;
363
+ }
364
+ catch (error) {
365
+ if (!(error instanceof Error)) {
366
+ return null;
367
+ }
368
+ if (this._canShowDialogs()) {
369
+ return new Promise(resolve => {
370
+ const onTryAgain = async () => {
371
+ try {
372
+ const result = await this._backgroundFlow?.authorize();
373
+ resolve(result ?? null);
374
+ }
375
+ catch (retryError) {
376
+ if (retryError instanceof Error) {
377
+ this._showAuthDialog({
378
+ nonInteractive: true,
379
+ error: retryError,
380
+ onTryAgain
381
+ });
382
+ }
383
+ throw retryError;
384
+ }
385
+ };
386
+ this._showAuthDialog({
387
+ nonInteractive: true,
388
+ error: error,
389
+ onTryAgain
390
+ });
391
+ });
392
+ }
393
+ else {
394
+ const authRequest = await this._requestBuilder?.prepareAuthRequest();
395
+ if (authRequest != null) {
396
+ this._redirectCurrentPage(authRequest.url);
397
+ }
398
+ }
399
+ throw new TokenValidator.TokenValidationError(error.message);
400
+ }
401
+ }
402
+ async loadCurrentService() {
403
+ if (this._service.serviceName) {
404
+ return;
405
+ }
406
+ try {
407
+ const { serviceName, iconUrl: serviceImage } = await this.http.get(`oauth2/interactive/login/settings?client_id=${this.config.clientId}`) || {};
408
+ this.setCurrentService({ serviceImage, serviceName });
409
+ }
410
+ catch (e) {
411
+ // noop
412
+ }
413
+ }
414
+ getAPIPath() {
415
+ return this.config.serverUri + Auth.API_PATH;
416
+ }
417
+ /**
418
+ * @return {Promise.<object>}
419
+ */
420
+ getUser(accessToken) {
421
+ if (this.config.cacheCurrentUser) {
422
+ return this._storage?.getCachedUser(() => this.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, this.config.userParams));
423
+ }
424
+ else {
425
+ return this.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, this.config.userParams);
426
+ }
427
+ }
428
+ /**
429
+ * @return {Promise.<object>}
430
+ */
431
+ async requestUser() {
432
+ if (this.user) {
433
+ return this.user;
434
+ }
435
+ const accessToken = await this.requestToken();
436
+ // If user was fetched during token request
437
+ if (this.user) {
438
+ return this.user;
439
+ }
440
+ const user = await this.getUser(accessToken);
441
+ this.user = user;
442
+ return user;
443
+ }
444
+ async updateUser() {
445
+ this._setPostponed(false);
446
+ const accessToken = await this.requestToken();
447
+ this._storage?.wipeCachedCurrentUser();
448
+ const user = await this.getUser(accessToken);
763
449
  this.user = user;
764
450
  this.listeners.trigger(USER_CHANGED_EVENT, user);
765
- }
766
- } catch (e) {
767
- this._beforeLogout();
768
- }
769
- }
770
-
771
- async switchUser() {
772
- if (!this.config.embeddedLogin) {
773
- throw new Error('Auth: switchUser only supported for "embeddedLogin" mode');
774
- }
775
- await this._runEmbeddedLogin();
776
- }
777
-
778
- /**
779
- * Check if the hash contains an access token.
780
- * If it does, extract the state, compare with
781
- * config, and store the auth response for later use.
782
- *
783
- * @return {Promise} promise that is resolved to restoreLocation URL, or rejected
784
- * @private
785
- */
786
- async _checkForAuthResponse() {
787
- // getAuthResponseURL may throw an exception
788
- const authResponse = this._responseParser.getAuthResponseFromURL();
789
- const {scope: defaultScope, defaultExpiresIn, cleanHash} = this.config;
790
-
791
- if (authResponse && cleanHash) {
792
- this.setHash('');
793
- }
794
-
795
- if (!authResponse) {
796
- return undefined;
797
- }
798
-
799
- const {state: stateId, scope, expiresIn, accessToken} = authResponse;
800
- const newState = await (stateId && this._storage.getState(stateId)) || {};
801
-
802
- const scopes = scope ? scope.split(' ') : newState.scopes || defaultScope || [];
803
- const effectiveExpiresIn = expiresIn ? parseInt(expiresIn, 10) : defaultExpiresIn;
804
- const expires = TokenValidator._epoch() + effectiveExpiresIn;
805
-
806
- await this._storage.saveToken({accessToken, scopes, expires, lifeTime: effectiveExpiresIn});
807
-
808
- return newState;
809
- }
810
-
811
- async _checkForStateRestoration() {
812
- const authResponse = this._responseParser._authResponse;
813
- if (authResponse && this.config.cleanHash) {
814
- this.setHash('');
815
- }
816
- const stateId = authResponse?.restoreAuthState;
817
- return await (stateId && this._storage.getState(stateId)) || {};
818
- }
819
-
820
- _checkBackendsAreUp() {
821
- const {backendCheckTimeout} = this.config;
822
- return Promise.all([
823
- promiseWithTimeout(
824
- this.http.fetch('settings/public?fields=id'),
825
- backendCheckTimeout,
826
- {error: new Error('The authorization server is taking too long to respond. Please try again later.')}
827
- ),
828
- this.config.checkBackendIsUp()
829
- ]).catch(err => {
830
- if (err instanceof TypeError) {
831
- throw new TypeError('Could not connect to the server due to network error. Please check your connection and try again.');
832
- }
833
- throw err;
834
- });
835
- }
836
-
837
- async _checkBackendsStatusesIfEnabled() {
838
- if (!this.config.enableBackendStatusCheck) {
839
- return;
840
- }
841
- try {
842
- await this._checkBackendsAreUp();
843
- } catch (backendDownErr) {
844
- await this._showBackendDownDialog(backendDownErr);
845
- }
846
- }
847
-
848
- /**
849
- * Adds preconnect tag to help browser to establish connection to URL.
850
- * See https://w3c.github.io/resource-hints/
851
- * @param url Url to preconnect to.
852
- */
853
- setUpPreconnect(url) {
854
- const linkNode = document.createElement('link');
855
- linkNode.rel = 'preconnect';
856
- linkNode.href = url;
857
- linkNode.pr = '1.0';
858
- linkNode.crossorigin = 'use-credentials';
859
- document.head.appendChild(linkNode);
860
- }
861
-
862
- /**
863
- * Redirects current page to the given URL
864
- * @param {string} url
865
- * @private
866
- */
867
- _redirectCurrentPage(url) {
868
-
869
- window.location = fixUrl(url);
870
- }
871
-
872
- /**
873
- * Reloads current page
874
- */
875
- _reloadCurrentPage() {
876
- this._redirectCurrentPage(window.location.href);
877
- }
878
-
879
- _canShowDialogs() {
880
- return this.config.embeddedLogin && this._authDialogService;
881
- }
882
-
883
- /**
884
- * Sets the location hash
885
- * @param {string} hash
886
- */
887
- setHash(hash) {
888
- if (history.replaceState) {
889
- // NB! History.replaceState is used here, because Firefox saves
890
- // a record in history.
891
- // NB! URL to redirect is formed manually because baseURI could be messed up,
892
- // in which case it's not obvious where redirect will lead.
893
- const cleanedUrl = [
894
- window.location.pathname,
895
- window.location.search
896
- ].join('');
897
-
898
- const hashIfExist = hash ? `#${hash}` : '';
899
-
900
- history.replaceState(undefined, undefined, `${cleanedUrl}${hashIfExist}`);
901
- } else {
902
- window.location.hash = hash;
903
- }
904
- }
451
+ }
452
+ async _detectUserChange(accessToken) {
453
+ const windowWasOpen = this._isLoginWindowOpen;
454
+ const user = await this.getUser(accessToken);
455
+ const onApply = () => {
456
+ this.user = user;
457
+ this.listeners.trigger(USER_CHANGED_EVENT, user);
458
+ };
459
+ if (user && this.user && this.user.id !== user.id) {
460
+ if (!this._canShowDialogs() || this.user.guest || windowWasOpen) {
461
+ onApply();
462
+ return;
463
+ }
464
+ if (user.guest) {
465
+ this._showAuthDialog({ nonInteractive: true });
466
+ return;
467
+ }
468
+ await this._showUserChangedDialog({
469
+ newUser: user,
470
+ onApply,
471
+ onPostpone: () => {
472
+ this.listeners.trigger(USER_CHANGE_POSTPONED_EVENT);
473
+ this.config.onPostponeChangedUser(this.user, user);
474
+ }
475
+ });
476
+ }
477
+ }
478
+ _beforeLogout(params) {
479
+ if (this._canShowDialogs()) {
480
+ this._showAuthDialog(params);
481
+ return;
482
+ }
483
+ this.logout();
484
+ }
485
+ _showAuthDialog({ nonInteractive, error, canCancel, onTryAgain } = {}) {
486
+ const { embeddedLogin, onPostponeLogout, translations } = this.config;
487
+ const cancelable = this.user?.guest || canCancel;
488
+ this._createInitDeferred();
489
+ const closeDialog = () => {
490
+ /* eslint-disable @typescript-eslint/no-use-before-define */
491
+ stopTokenListening?.();
492
+ stopMessageListening?.();
493
+ hide?.();
494
+ /* eslint-enable @typescript-eslint/no-use-before-define */
495
+ };
496
+ const onConfirm = () => {
497
+ if (!embeddedLogin) {
498
+ closeDialog();
499
+ this.logout();
500
+ return;
501
+ }
502
+ this._runEmbeddedLogin();
503
+ };
504
+ const onCancel = () => {
505
+ this._embeddedFlow?.stop();
506
+ this._storage?.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
507
+ closeDialog();
508
+ if (!cancelable) {
509
+ this._initDeferred?.resolve?.();
510
+ this.listeners.trigger(LOGOUT_POSTPONED_EVENT);
511
+ onPostponeLogout();
512
+ return;
513
+ }
514
+ if (this.user?.guest && nonInteractive) {
515
+ this.forceTokenUpdate();
516
+ }
517
+ else {
518
+ this._initDeferred?.resolve?.();
519
+ }
520
+ };
521
+ const onTryAgainClick = async () => {
522
+ await onTryAgain?.();
523
+ closeDialog();
524
+ };
525
+ const hide = this._authDialogService?.({
526
+ ...this._service,
527
+ loginCaption: translations.login,
528
+ loginToCaption: translations.loginTo,
529
+ confirmLabel: translations.login,
530
+ tryAgainLabel: translations.tryAgainLabel,
531
+ cancelLabel: cancelable ? translations.cancel : translations.postpone,
532
+ errorMessage: this._extractErrorMessage(error, true),
533
+ onConfirm,
534
+ onCancel,
535
+ onTryAgain: onTryAgain ? onTryAgainClick : undefined
536
+ });
537
+ const stopTokenListening = this._storage?.onTokenChange(token => {
538
+ if (token) {
539
+ closeDialog();
540
+ this._initDeferred?.resolve?.();
541
+ }
542
+ });
543
+ const stopMessageListening = this._storage?.onMessage(Auth.CLOSE_WINDOW_MESSAGE, () => this._embeddedFlow?.stop());
544
+ }
545
+ _showUserChangedDialog({ newUser, onApply, onPostpone }) {
546
+ const { translations } = this.config;
547
+ this._createInitDeferred();
548
+ const done = () => {
549
+ this._initDeferred?.resolve?.();
550
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
551
+ hide?.();
552
+ };
553
+ const hide = this._authDialogService?.({
554
+ ...this._service,
555
+ title: translations.youHaveLoggedInAs.replace('%userName%', newUser.name ?? ''),
556
+ loginCaption: translations.login,
557
+ loginToCaption: translations.loginTo,
558
+ confirmLabel: translations.applyChange,
559
+ tryAgainLabel: translations.tryAgainLabel,
560
+ cancelLabel: translations.postpone,
561
+ onConfirm: () => {
562
+ done();
563
+ onApply();
564
+ },
565
+ onCancel: () => {
566
+ done();
567
+ onPostpone();
568
+ }
569
+ });
570
+ }
571
+ _extractErrorMessage(error, logError = false) {
572
+ if (!error) {
573
+ return null;
574
+ }
575
+ if (logError) {
576
+ // eslint-disable-next-line no-console
577
+ console.error('RingUI Auth error', error);
578
+ }
579
+ try {
580
+ // We've got some error from this list
581
+ // https://www.jetbrains.com/help/youtrack/devportal/OAuth-2.0-Errors.html
582
+ if ('code' in error && error.code && typeof error.code === 'object' && 'code' in error.code && typeof error.code.code === 'string') {
583
+ const readableCode = error.code.code.split('_').join(' ');
584
+ return `Authorization error: ${readableCode}`;
585
+ }
586
+ }
587
+ catch {
588
+ // noop
589
+ }
590
+ return error.toString ? error.toString() : null;
591
+ }
592
+ _showBackendDownDialog(backendError) {
593
+ const { onBackendDown, translations } = this.config;
594
+ const REPEAT_TIMEOUT = 5000;
595
+ let timerId;
596
+ return new Promise((resolve, reject) => {
597
+ const done = () => {
598
+ /* eslint-disable @typescript-eslint/no-use-before-define */
599
+ hide();
600
+ window.removeEventListener('online', onCheckAgain);
601
+ stopListeningCloseMessage?.();
602
+ /* eslint-enable @typescript-eslint/no-use-before-define */
603
+ this._storage?.sendMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, Date.now());
604
+ clearTimeout(timerId);
605
+ };
606
+ const stopListeningCloseMessage = this._storage?.onMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, () => {
607
+ stopListeningCloseMessage?.();
608
+ done();
609
+ resolve();
610
+ });
611
+ const onCheckAgain = async () => {
612
+ await this._checkBackendsAreUp();
613
+ done();
614
+ resolve();
615
+ };
616
+ const onPostpone = () => {
617
+ done();
618
+ reject(new Error('Auth(@jetbrains/ring-ui): postponed by user'));
619
+ };
620
+ const hide = onBackendDown({ onCheckAgain, onPostpone, backendError, translations });
621
+ window.addEventListener('online', onCheckAgain);
622
+ function networkWatchdog() {
623
+ if (navigator && navigator.onLine) {
624
+ onCheckAgain();
625
+ }
626
+ timerId = window.setTimeout(networkWatchdog, REPEAT_TIMEOUT);
627
+ }
628
+ timerId = window.setTimeout(networkWatchdog, REPEAT_TIMEOUT);
629
+ });
630
+ }
631
+ /**
632
+ * Wipe accessToken and redirect to auth page with required authorization
633
+ */
634
+ async logout(extraParams) {
635
+ const requestParams = {
636
+ // eslint-disable-next-line camelcase
637
+ request_credentials: 'required',
638
+ ...extraParams
639
+ };
640
+ await this._checkBackendsStatusesIfEnabled();
641
+ await this.listeners.trigger('logout');
642
+ this._updateDomainUser(null);
643
+ await this._storage?.wipeToken();
644
+ const authRequest = await this._requestBuilder?.prepareAuthRequest(requestParams);
645
+ if (authRequest != null) {
646
+ this._redirectCurrentPage(authRequest.url);
647
+ }
648
+ }
649
+ async _runEmbeddedLogin() {
650
+ this._storage?.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
651
+ try {
652
+ this._isLoginWindowOpen = true;
653
+ return await this._embeddedFlow?.authorize();
654
+ }
655
+ catch (e) {
656
+ throw e;
657
+ }
658
+ finally {
659
+ this._isLoginWindowOpen = false;
660
+ }
661
+ }
662
+ /**
663
+ * Wipe accessToken and redirect to auth page to obtain authorization data
664
+ * if user is logged in or log her in otherwise
665
+ */
666
+ async login() {
667
+ if (this.config.embeddedLogin) {
668
+ await this._runEmbeddedLogin();
669
+ return;
670
+ }
671
+ await this._checkBackendsStatusesIfEnabled();
672
+ try {
673
+ const accessToken = await this._backgroundFlow?.authorize();
674
+ const user = await this.getUser(accessToken);
675
+ if (user.guest) {
676
+ this._beforeLogout();
677
+ }
678
+ else {
679
+ this.user = user;
680
+ this.listeners.trigger(USER_CHANGED_EVENT, user);
681
+ }
682
+ }
683
+ catch (e) {
684
+ this._beforeLogout();
685
+ }
686
+ }
687
+ async switchUser() {
688
+ if (!this.config.embeddedLogin) {
689
+ throw new Error('Auth: switchUser only supported for "embeddedLogin" mode');
690
+ }
691
+ await this._runEmbeddedLogin();
692
+ }
693
+ /**
694
+ * Check if the hash contains an access token.
695
+ * If it does, extract the state, compare with
696
+ * config, and store the auth response for later use.
697
+ *
698
+ * @return {Promise} promise that is resolved to restoreLocation URL, or rejected
699
+ * @private
700
+ */
701
+ async _checkForAuthResponse() {
702
+ // getAuthResponseURL may throw an exception
703
+ const authResponse = this._responseParser.getAuthResponseFromURL();
704
+ const { scope: defaultScope, defaultExpiresIn, cleanHash } = this.config;
705
+ if (authResponse && cleanHash) {
706
+ this.setHash('');
707
+ }
708
+ if (!authResponse) {
709
+ return undefined;
710
+ }
711
+ const { state: stateId, scope, expiresIn, accessToken } = authResponse;
712
+ const newState = await (stateId && this._storage?.getState(stateId)) || {};
713
+ const scopes = scope ? scope.split(' ') : newState.scopes || defaultScope || [];
714
+ const effectiveExpiresIn = expiresIn ? parseInt(expiresIn, 10) : defaultExpiresIn;
715
+ const expires = TokenValidator._epoch() + effectiveExpiresIn;
716
+ if (accessToken != null) {
717
+ await this._storage?.saveToken({ accessToken, scopes, expires, lifeTime: effectiveExpiresIn });
718
+ }
719
+ return newState;
720
+ }
721
+ async _checkForStateRestoration() {
722
+ const authResponse = this._responseParser._authResponse;
723
+ if (authResponse && this.config.cleanHash) {
724
+ this.setHash('');
725
+ }
726
+ const stateId = authResponse?.restoreAuthState;
727
+ return await (stateId && this._storage?.getState(stateId)) || {};
728
+ }
729
+ _checkBackendsAreUp() {
730
+ const { backendCheckTimeout } = this.config;
731
+ return Promise.all([
732
+ promiseWithTimeout(this.http.fetch('settings/public?fields=id'), backendCheckTimeout, { error: new Error('The authorization server is taking too long to respond. Please try again later.') }),
733
+ this.config.checkBackendIsUp()
734
+ ]).catch(err => {
735
+ if (err instanceof TypeError) {
736
+ throw new TypeError('Could not connect to the server due to network error. Please check your connection and try again.');
737
+ }
738
+ throw err;
739
+ });
740
+ }
741
+ async _checkBackendsStatusesIfEnabled() {
742
+ if (!this.config.enableBackendStatusCheck) {
743
+ return;
744
+ }
745
+ try {
746
+ await this._checkBackendsAreUp();
747
+ }
748
+ catch (backendDownErr) {
749
+ if (backendDownErr instanceof Error) {
750
+ await this._showBackendDownDialog(backendDownErr);
751
+ }
752
+ }
753
+ }
754
+ /**
755
+ * Adds preconnect tag to help browser to establish connection to URL.
756
+ * See https://w3c.github.io/resource-hints/
757
+ * @param url Url to preconnect to.
758
+ */
759
+ setUpPreconnect(url) {
760
+ const linkNode = document.createElement('link');
761
+ linkNode.rel = 'preconnect';
762
+ linkNode.href = url;
763
+ linkNode.pr = '1.0';
764
+ linkNode.crossOrigin = 'use-credentials';
765
+ document.head.appendChild(linkNode);
766
+ }
767
+ /**
768
+ * Redirects current page to the given URL
769
+ * @param {string} url
770
+ * @private
771
+ */
772
+ _redirectCurrentPage(url) {
773
+ if (process.env.NODE_ENV !== 'test') {
774
+ window.location.href = fixUrl(url);
775
+ }
776
+ }
777
+ /**
778
+ * Reloads current page
779
+ */
780
+ _reloadCurrentPage() {
781
+ this._redirectCurrentPage(window.location.href);
782
+ }
783
+ _canShowDialogs() {
784
+ return this.config.embeddedLogin && this._authDialogService;
785
+ }
786
+ /**
787
+ * Sets the location hash
788
+ * @param {string} hash
789
+ */
790
+ setHash(hash) {
791
+ if (history.replaceState) {
792
+ // NB! History.replaceState is used here, because Firefox saves
793
+ // a record in history.
794
+ // NB! URL to redirect is formed manually because baseURI could be messed up,
795
+ // in which case it's not obvious where redirect will lead.
796
+ const cleanedUrl = [
797
+ window.location.pathname,
798
+ window.location.search
799
+ ].join('');
800
+ const hashIfExist = hash ? `#${hash}` : '';
801
+ history.replaceState(undefined, '', `${cleanedUrl}${hashIfExist}`);
802
+ }
803
+ else {
804
+ window.location.hash = hash;
805
+ }
806
+ }
905
807
  }