@jetbrains/ring-ui 4.2.7 → 4.2.10

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