@jetbrains/ring-ui 4.1.0-beta.9 → 4.1.1

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