@jetbrains/ring-ui 5.0.155 → 5.0.157

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 (299) hide show
  1. package/components/checkbox/checkbox.css +1 -1
  2. package/components/global/variables_dark.css +2 -2
  3. package/components/radio/radio.css +1 -1
  4. package/dist/_helpers/_rollupPluginBabelHelpers.js +642 -1
  5. package/dist/_helpers/anchor.js +6 -7
  6. package/dist/_helpers/button__classes.js +16 -28
  7. package/dist/_helpers/card.js +107 -95
  8. package/dist/_helpers/dialog__body-scroll-preventer.js +20 -11
  9. package/dist/_helpers/footer.js +29 -34
  10. package/dist/_helpers/query-assist__suggestions.js +91 -74
  11. package/dist/_helpers/select__filter.js +71 -48
  12. package/dist/_helpers/services-link.js +41 -29
  13. package/dist/_helpers/sidebar.js +103 -99
  14. package/dist/_helpers/theme.js +42 -35
  15. package/dist/_helpers/title.js +71 -57
  16. package/dist/alert/alert.js +199 -158
  17. package/dist/alert/container.js +43 -32
  18. package/dist/alert-service/alert-service.js +172 -104
  19. package/dist/analytics/analytics.js +92 -68
  20. package/dist/analytics/analytics__custom-plugin.js +84 -60
  21. package/dist/analytics/analytics__fus-plugin.js +28 -15
  22. package/dist/analytics/analytics__ga-plugin.js +60 -43
  23. package/dist/analytics/analytics__plugin-utils.js +28 -22
  24. package/dist/auth/auth.js +36 -4
  25. package/dist/auth/auth__core.js +1458 -732
  26. package/dist/auth/background-flow.js +129 -87
  27. package/dist/auth/down-notification.js +75 -30
  28. package/dist/auth/iframe-flow.js +136 -75
  29. package/dist/auth/landing.js +90 -30
  30. package/dist/auth/request-builder.js +82 -46
  31. package/dist/auth/response-parser.js +119 -86
  32. package/dist/auth/storage.js +333 -171
  33. package/dist/auth/token-validator.js +244 -137
  34. package/dist/auth/window-flow.js +136 -92
  35. package/dist/auth-dialog/auth-dialog.js +176 -114
  36. package/dist/auth-dialog-service/auth-dialog-service.js +32 -7
  37. package/dist/auth-ng/auth-ng.js +70 -34
  38. package/dist/auth-ng/auth-ng.mock.js +6 -6
  39. package/dist/autofocus-ng/autofocus-ng.js +23 -8
  40. package/dist/avatar/avatar-example-datauri.js +1 -23
  41. package/dist/avatar/avatar.js +155 -119
  42. package/dist/avatar/fallback-avatar.js +41 -22
  43. package/dist/avatar-editor-ng/avatar-editor-ng.js +56 -23
  44. package/dist/avatar-editor-ng/avatar-editor-ng__template.js +1 -28
  45. package/dist/avatar-ng/avatar-ng.js +23 -1
  46. package/dist/badge/badge.js +43 -35
  47. package/dist/badge-ng/badge-ng.js +13 -1
  48. package/dist/breadcrumb-ng/breadcrumb-ng.js +15 -29
  49. package/dist/button/button.js +111 -87
  50. package/dist/button/button__classes.js +1 -0
  51. package/dist/button-group/button-group.js +35 -19
  52. package/dist/button-group/caption.js +22 -14
  53. package/dist/button-group-ng/button-group-ng.js +13 -7
  54. package/dist/button-ng/button-ng.js +154 -133
  55. package/dist/button-set/button-set.js +34 -20
  56. package/dist/button-set-ng/button-set-ng.js +2 -2
  57. package/dist/button-toolbar/button-toolbar.js +33 -19
  58. package/dist/button-toolbar-ng/button-toolbar-ng.js +5 -3
  59. package/dist/caret/caret.js +225 -188
  60. package/dist/checkbox/checkbox.js +104 -76
  61. package/dist/checkbox-ng/checkbox-ng.js +18 -27
  62. package/dist/clipboard/clipboard-fallback.js +10 -10
  63. package/dist/clipboard/clipboard.js +131 -34
  64. package/dist/code/code.js +168 -92
  65. package/dist/compiler-ng/compiler-ng.js +18 -15
  66. package/dist/confirm/confirm.js +108 -66
  67. package/dist/confirm-ng/confirm-ng.js +33 -4
  68. package/dist/confirm-service/confirm-service.js +66 -42
  69. package/dist/content-layout/content-layout.js +64 -43
  70. package/dist/content-layout/sidebar.js +1 -0
  71. package/dist/contenteditable/contenteditable.js +61 -50
  72. package/dist/control-label/control-label.js +11 -15
  73. package/dist/data-list/data-list.js +184 -128
  74. package/dist/data-list/data-list.mock.js +11 -2
  75. package/dist/data-list/item.js +174 -143
  76. package/dist/data-list/selection.js +139 -76
  77. package/dist/data-list/title.js +13 -1
  78. package/dist/data-list-ng/data-list-ng.js +31 -1
  79. package/dist/date-picker/consts.js +18 -15
  80. package/dist/date-picker/date-input.js +147 -115
  81. package/dist/date-picker/date-picker.js +285 -228
  82. package/dist/date-picker/date-popup.js +397 -356
  83. package/dist/date-picker/day.js +98 -84
  84. package/dist/date-picker/month-names.js +64 -43
  85. package/dist/date-picker/month-slider.js +74 -51
  86. package/dist/date-picker/month.js +21 -15
  87. package/dist/date-picker/months.js +48 -43
  88. package/dist/date-picker/weekdays.js +18 -12
  89. package/dist/date-picker/years.js +109 -84
  90. package/dist/dialog/dialog.js +189 -141
  91. package/dist/dialog/dialog__body-scroll-preventer.js +5 -0
  92. package/dist/dialog-ng/dialog-ng.js +401 -287
  93. package/dist/dialog-ng/dialog-ng__template.js +1 -70
  94. package/dist/docked-panel-ng/docked-panel-ng.js +33 -18
  95. package/dist/dropdown/anchor.js +10 -0
  96. package/dist/dropdown/dropdown.js +214 -182
  97. package/dist/dropdown-menu/dropdown-menu.js +102 -72
  98. package/dist/editable-heading/editable-heading.js +100 -58
  99. package/dist/error-bubble/error-bubble.js +64 -31
  100. package/dist/error-message/error-message.js +61 -38
  101. package/dist/error-message-ng/error-message-ng.js +11 -22
  102. package/dist/footer/footer.js +11 -1
  103. package/dist/footer-ng/footer-ng.js +64 -36
  104. package/dist/form-ng/form-ng.js +66 -56
  105. package/dist/global/angular-component-factory.js +76 -53
  106. package/dist/global/compose.js +10 -1
  107. package/dist/global/composeRefs.js +12 -7
  108. package/dist/global/controls-height.js +2 -2
  109. package/dist/global/create-stateful-context.js +19 -19
  110. package/dist/global/data-tests.js +15 -7
  111. package/dist/global/dom.js +95 -53
  112. package/dist/global/focus-sensor-hoc.js +134 -122
  113. package/dist/global/fuzzy-highlight.js +41 -27
  114. package/dist/global/get-event-key.js +8 -8
  115. package/dist/global/get-uid.js +8 -4
  116. package/dist/global/inject-styles.js +15 -10
  117. package/dist/global/linear-function.js +2 -2
  118. package/dist/global/listeners.js +53 -27
  119. package/dist/global/memoize.js +13 -6
  120. package/dist/global/normalize-indent.js +51 -19
  121. package/dist/global/promise-with-timeout.js +8 -6
  122. package/dist/global/prop-types.js +5 -3
  123. package/dist/global/react-dom-renderer.js +47 -28
  124. package/dist/global/react-render-adapter.js +19 -13
  125. package/dist/global/rerender-hoc.js +41 -16
  126. package/dist/global/ring-angular-component.js +20 -10
  127. package/dist/global/schedule-raf.js +6 -5
  128. package/dist/global/sniffer.js +1 -1
  129. package/dist/global/theme.js +24 -0
  130. package/dist/global/trivial-template-tag.js +10 -3
  131. package/dist/global/typescript-utils.js +6 -2
  132. package/dist/global/url.js +27 -21
  133. package/dist/global/use-event-callback.js +4 -6
  134. package/dist/grid/col.js +55 -35
  135. package/dist/grid/grid.js +36 -17
  136. package/dist/grid/row.js +48 -35
  137. package/dist/group/group.js +27 -17
  138. package/dist/group-ng/group-ng.js +2 -2
  139. package/dist/header/header.js +80 -33
  140. package/dist/header/logo.js +39 -20
  141. package/dist/header/profile.js +188 -150
  142. package/dist/header/services-link.js +9 -0
  143. package/dist/header/services.js +118 -73
  144. package/dist/header/smart-profile.js +207 -111
  145. package/dist/header/smart-services.js +115 -62
  146. package/dist/header/tray-icon.js +38 -21
  147. package/dist/header/tray.js +34 -21
  148. package/dist/heading/heading.js +25 -26
  149. package/dist/heading-ng/heading-ng.js +11 -1
  150. package/dist/http/http.js +368 -215
  151. package/dist/http/http.mock.js +104 -49
  152. package/dist/hub-source/hub-source.js +191 -83
  153. package/dist/hub-source/hub-source__user.js +45 -11
  154. package/dist/hub-source/hub-source__users-groups.js +67 -37
  155. package/dist/i18n/i18n-context.js +14 -10
  156. package/dist/i18n/i18n.js +11 -7
  157. package/dist/icon/icon.js +94 -76
  158. package/dist/icon/icon__svg.js +31 -24
  159. package/dist/icon/index.js +9 -0
  160. package/dist/icon-ng/icon-ng.js +27 -15
  161. package/dist/input/input.js +184 -145
  162. package/dist/input-ng/input-ng.js +96 -118
  163. package/dist/island/adaptive-island-hoc.js +45 -30
  164. package/dist/island/content.js +130 -115
  165. package/dist/island/header.js +69 -56
  166. package/dist/island/island.js +40 -28
  167. package/dist/island-legacy/content-legacy.js +27 -17
  168. package/dist/island-legacy/header-legacy.js +29 -19
  169. package/dist/island-legacy/island-legacy.js +27 -17
  170. package/dist/island-ng/island-content-ng.js +17 -26
  171. package/dist/island-ng/island-header-ng.js +9 -12
  172. package/dist/island-ng/island-ng-class-fixer.js +3 -0
  173. package/dist/island-ng/island-ng.js +6 -10
  174. package/dist/link/clickableLink.js +61 -44
  175. package/dist/link/link.js +85 -74
  176. package/dist/link-ng/link-ng.js +3 -5
  177. package/dist/list/consts.js +1 -1
  178. package/dist/list/list.js +696 -602
  179. package/dist/list/list__custom.js +61 -44
  180. package/dist/list/list__hint.js +21 -10
  181. package/dist/list/list__item.js +167 -129
  182. package/dist/list/list__link.js +54 -37
  183. package/dist/list/list__separator.js +24 -14
  184. package/dist/list/list__title.js +32 -22
  185. package/dist/list/list__users-groups-source.js +131 -54
  186. package/dist/loader/loader.js +78 -43
  187. package/dist/loader/loader__core.js +257 -189
  188. package/dist/loader-inline/loader-inline.js +37 -23
  189. package/dist/loader-inline-ng/loader-inline-ng.js +2 -2
  190. package/dist/loader-ng/loader-ng.js +46 -19
  191. package/dist/loader-screen/loader-screen.js +48 -25
  192. package/dist/loader-screen-ng/loader-screen-ng.js +46 -30
  193. package/dist/login-dialog/login-dialog.js +162 -111
  194. package/dist/login-dialog/service.js +35 -7
  195. package/dist/markdown/code.js +31 -9
  196. package/dist/markdown/heading.js +3 -5
  197. package/dist/markdown/link.js +13 -6
  198. package/dist/markdown/markdown.js +66 -33
  199. package/dist/message/message.js +157 -125
  200. package/dist/message-bundle-ng/message-bundle-ng.js +128 -44
  201. package/dist/old-browsers-message/old-browsers-message.js +19 -11
  202. package/dist/old-browsers-message/old-browsers-message__stop.js +8 -0
  203. package/dist/old-browsers-message/white-list.js +16 -9
  204. package/dist/pager/pager.js +275 -210
  205. package/dist/pager-ng/pager-ng.js +36 -1
  206. package/dist/panel/panel.js +27 -17
  207. package/dist/panel-ng/panel-ng.js +14 -1
  208. package/dist/permissions/permissions.js +173 -127
  209. package/dist/permissions/permissions__cache.js +225 -194
  210. package/dist/permissions-ng/permissions-ng.js +86 -35
  211. package/dist/place-under-ng/place-under-ng.js +68 -45
  212. package/dist/popup/popup.consts.js +1 -1
  213. package/dist/popup/popup.js +342 -280
  214. package/dist/popup/popup.target.js +8 -9
  215. package/dist/popup/position.js +153 -153
  216. package/dist/popup-menu/popup-menu.js +86 -44
  217. package/dist/progress-bar/progress-bar.js +97 -80
  218. package/dist/progress-bar-ng/progress-bar-ng.js +11 -1
  219. package/dist/promised-click-ng/promised-click-ng.js +92 -58
  220. package/dist/proxy-attrs/proxy-attrs.js +18 -9
  221. package/dist/query-assist/query-assist.js +903 -832
  222. package/dist/query-assist/query-assist__suggestions.js +33 -1
  223. package/dist/query-assist-ng/query-assist-ng.js +38 -1
  224. package/dist/radio/radio.js +36 -19
  225. package/dist/radio/radio__item.js +71 -52
  226. package/dist/radio-ng/radio-ng.js +14 -25
  227. package/dist/save-field-ng/save-field-ng.js +86 -52
  228. package/dist/save-field-ng/save-field-ng__template.js +1 -32
  229. package/dist/select/select.js +937 -835
  230. package/dist/select/select__filter.js +33 -0
  231. package/dist/select/select__popup.js +472 -359
  232. package/dist/select-ng/select-ng.js +125 -74
  233. package/dist/select-ng/select-ng__lazy.js +101 -50
  234. package/dist/select-ng/select-ng__options.js +107 -81
  235. package/dist/shortcuts/core.js +218 -166
  236. package/dist/shortcuts/shortcut-title.js +11 -6
  237. package/dist/shortcuts/shortcuts-hoc.js +47 -19
  238. package/dist/shortcuts/shortcuts.js +77 -50
  239. package/dist/shortcuts-hint-ng/shortcuts-hint-ng.js +104 -53
  240. package/dist/shortcuts-hint-ng/shortcuts-hint-ng__template.js +1 -48
  241. package/dist/shortcuts-ng/shortcuts-ng.js +86 -51
  242. package/dist/sidebar-ng/sidebar-ng.js +53 -22
  243. package/dist/sidebar-ng/sidebar-ng__button-template.js +1 -18
  244. package/dist/sidebar-ng/sidebar-ng__template.js +1 -10
  245. package/dist/storage/storage.js +35 -4
  246. package/dist/storage/storage__fallback.js +224 -149
  247. package/dist/storage/storage__local.js +156 -90
  248. package/dist/style.css +1 -1
  249. package/dist/tab-trap/tab-trap.js +157 -122
  250. package/dist/table/cell.js +28 -14
  251. package/dist/table/disable-hover-hoc.js +53 -33
  252. package/dist/table/header-cell.js +87 -64
  253. package/dist/table/header.js +126 -98
  254. package/dist/table/multitable.js +127 -107
  255. package/dist/table/row-with-focus-sensor.js +73 -25
  256. package/dist/table/row.js +208 -170
  257. package/dist/table/selection-adapter.js +3 -1
  258. package/dist/table/selection-shortcuts-hoc.js +184 -181
  259. package/dist/table/selection.js +228 -156
  260. package/dist/table/smart-table.js +93 -51
  261. package/dist/table/table.js +348 -281
  262. package/dist/table-legacy-ng/table-legacy-ng.js +117 -102
  263. package/dist/table-legacy-ng/table-legacy-ng__pager.js +42 -10
  264. package/dist/table-legacy-ng/table-legacy-ng__selection-navigate-actions.js +92 -69
  265. package/dist/table-legacy-ng/table-legacy-ng__selection.js +169 -119
  266. package/dist/table-legacy-ng/table-legacy-ng__toolbar.js +36 -21
  267. package/dist/table-ng/smart-table-ng.js +31 -1
  268. package/dist/table-ng/table-ng.js +31 -1
  269. package/dist/tabs/collapsible-more.js +87 -50
  270. package/dist/tabs/collapsible-tab.js +45 -38
  271. package/dist/tabs/collapsible-tabs.js +161 -94
  272. package/dist/tabs/custom-item.js +2 -4
  273. package/dist/tabs/dumb-tabs.js +122 -75
  274. package/dist/tabs/smart-tabs.js +75 -29
  275. package/dist/tabs/tab-link.js +29 -19
  276. package/dist/tabs/tab.js +33 -19
  277. package/dist/tabs/tabs.js +35 -0
  278. package/dist/tabs-ng/tabs-ng.js +38 -24
  279. package/dist/tabs-ng/tabs-ng__template.js +1 -38
  280. package/dist/tag/tag.js +170 -133
  281. package/dist/tags-input/tags-input.js +428 -327
  282. package/dist/tags-input-ng/tags-input-ng.js +37 -1
  283. package/dist/tags-list/tags-list.js +80 -56
  284. package/dist/template-ng/template-ng.js +50 -39
  285. package/dist/text/text.js +38 -28
  286. package/dist/title-ng/title-ng.js +28 -23
  287. package/dist/toggle/toggle.js +72 -56
  288. package/dist/toggle-ng/toggle-ng.js +14 -1
  289. package/dist/tooltip/tooltip.js +192 -146
  290. package/dist/tooltip-ng/tooltip-ng.js +51 -25
  291. package/dist/user-agreement/service.js +374 -227
  292. package/dist/user-agreement/toolbox.eula.js +1 -160
  293. package/dist/user-agreement/user-agreement.js +128 -86
  294. package/dist/user-card/card.js +32 -0
  295. package/dist/user-card/smart-user-card-tooltip.js +116 -51
  296. package/dist/user-card/tooltip.js +90 -48
  297. package/dist/user-card/user-card.js +32 -0
  298. package/dist/user-card-ng/user-card-ng.js +34 -2
  299. package/package.json +13 -13
@@ -1,23 +1,49 @@
1
+ import { c as _defineProperty, _ as _createClass, a as _objectSpread2, d as _typeof, b as _classCallCheck, g as _toConsumableArray, e as _asyncToGenerator, f as _regeneratorRuntime } from '../_helpers/_rollupPluginBabelHelpers.js';
2
+ import 'core-js/modules/es.object.to-string.js';
3
+ import 'core-js/modules/es.promise.js';
4
+ import 'core-js/modules/es.array.filter.js';
5
+ import 'core-js/modules/es.array.iterator.js';
6
+ import 'core-js/modules/es.set.js';
7
+ import 'core-js/modules/es.string.iterator.js';
8
+ import 'core-js/modules/web.dom-collections.iterator.js';
9
+ import 'core-js/modules/es.array.concat.js';
10
+ import 'core-js/modules/es.array.includes.js';
11
+ import 'core-js/modules/es.string.includes.js';
12
+ import 'core-js/modules/es.regexp.exec.js';
13
+ import 'core-js/modules/es.string.replace.js';
14
+ import 'core-js/modules/es.regexp.to-string.js';
15
+ import 'core-js/modules/es.parse-int.js';
16
+ import 'core-js/modules/es.string.search.js';
1
17
  import { getAbsoluteBaseURL, fixUrl } from '../global/url.js';
2
18
  import Listeners from '../global/listeners.js';
3
19
  import HTTP from '../http/http.js';
4
20
  import promiseWithTimeout from '../global/promise-with-timeout.js';
5
- import { getTranslationsWithFallback, translate, getTranslations } from '../i18n/i18n.js';
21
+ import { translate, getTranslationsWithFallback, getTranslations } from '../i18n/i18n.js';
6
22
  import AuthStorage from './storage.js';
7
23
  import AuthResponseParser from './response-parser.js';
8
24
  import AuthRequestBuilder from './request-builder.js';
9
25
  import BackgroundFlow from './background-flow.js';
10
26
  import TokenValidator from './token-validator.js';
27
+ import 'core-js/modules/es.string.match.js';
28
+ import 'core-js/modules/es.array.index-of.js';
29
+ import 'core-js/modules/es.map.js';
30
+ import 'core-js/modules/es.array.map.js';
31
+ import 'core-js/modules/es.weak-map.js';
32
+ import 'core-js/modules/web.dom-collections.for-each.js';
33
+ import 'core-js/modules/es.object.entries.js';
34
+ import 'core-js/modules/es.reflect.delete-property.js';
11
35
  import 'es6-error';
36
+ import 'core-js/modules/es.array.reduce.js';
37
+ import 'core-js/modules/es.array.sort.js';
12
38
  import '../storage/storage.js';
13
39
  import '../storage/storage__local.js';
14
40
  import '../alert-service/alert-service.js';
15
- import '../_helpers/_rollupPluginBabelHelpers.js';
16
41
  import 'react';
17
42
  import '../global/react-render-adapter.js';
18
43
  import 'react-dom';
19
44
  import '../global/get-uid.js';
20
45
  import '../alert/alert.js';
46
+ import 'core-js/modules/es.object.values.js';
21
47
  import 'classnames';
22
48
  import 'prop-types';
23
49
  import '@jetbrains/icons/exception';
@@ -29,11 +55,15 @@ import 'util-deprecate';
29
55
  import '../icon/icon__constants.js';
30
56
  import '../_helpers/icon.js';
31
57
  import '../icon/icon__svg.js';
58
+ import 'core-js/modules/es.string.starts-with.js';
32
59
  import '../global/memoize.js';
33
60
  import '../loader-inline/loader-inline.js';
34
61
  import '../global/data-tests.js';
35
62
  import '../_helpers/loader-inline.js';
36
63
  import '../global/dom.js';
64
+ import 'core-js/modules/es.object.assign.js';
65
+ import 'core-js/modules/es.string.split.js';
66
+ import 'core-js/modules/es.object.keys.js';
37
67
  import '../button/button.js';
38
68
  import '@jetbrains/icons/chevron-10px';
39
69
  import '../link/clickableLink.js';
@@ -45,6 +75,9 @@ import '../popup/popup.js';
45
75
  import '../global/schedule-raf.js';
46
76
  import '../shortcuts/shortcuts.js';
47
77
  import '../shortcuts/core.js';
78
+ import 'core-js/modules/es.array.slice.js';
79
+ import 'core-js/modules/es.array.splice.js';
80
+ import 'core-js/modules/es.array.find-index.js';
48
81
  import 'combokeys';
49
82
  import '../global/sniffer.js';
50
83
  import 'sniffr';
@@ -57,19 +90,19 @@ import 'deep-equal';
57
90
  import 'simply-uuid';
58
91
 
59
92
  /* eslint-disable @typescript-eslint/no-magic-numbers */
60
- const DEFAULT_EXPIRES_TIMEOUT = 40 * 60;
61
- const DEFAULT_BACKGROUND_TIMEOUT = 10 * 1000;
62
- const DEFAULT_BACKEND_CHECK_TIMEOUT = 10 * 1000;
63
- const BACKGROUND_REDIRECT_TIMEOUT = 20 * 1000;
64
- const DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT = 5 * 1000;
93
+ var DEFAULT_EXPIRES_TIMEOUT = 40 * 60;
94
+ var DEFAULT_BACKGROUND_TIMEOUT = 10 * 1000;
95
+ var DEFAULT_BACKEND_CHECK_TIMEOUT = 10 * 1000;
96
+ var BACKGROUND_REDIRECT_TIMEOUT = 20 * 1000;
97
+ var DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT = 5 * 1000;
65
98
  /* eslint-enable @typescript-eslint/no-magic-numbers */
66
- const USER_CHANGED_EVENT = 'userChange';
67
- const DOMAIN_USER_CHANGED_EVENT = 'domainUser';
68
- const LOGOUT_EVENT = 'logout';
69
- const LOGOUT_POSTPONED_EVENT = 'logoutPostponed';
70
- const USER_CHANGE_POSTPONED_EVENT = 'changePostponed';
99
+ var USER_CHANGED_EVENT = 'userChange';
100
+ var DOMAIN_USER_CHANGED_EVENT = 'domainUser';
101
+ var LOGOUT_EVENT = 'logout';
102
+ var LOGOUT_POSTPONED_EVENT = 'logoutPostponed';
103
+ var USER_CHANGE_POSTPONED_EVENT = 'changePostponed';
71
104
  function noop() {}
72
- const DEFAULT_CONFIG = {
105
+ var DEFAULT_CONFIG = {
73
106
  cacheCurrentUser: false,
74
107
  reloadOnUserChange: true,
75
108
  embeddedLogin: false,
@@ -83,97 +116,91 @@ const DEFAULT_CONFIG = {
83
116
  userFields: ['guest', 'id', 'name', 'login', 'profile/avatar/url'],
84
117
  cleanHash: true,
85
118
  onLogout: noop,
86
- onPostponeChangedUser: () => {},
87
- onPostponeLogout: () => {},
119
+ onPostponeChangedUser: function onPostponeChangedUser() {},
120
+ onPostponeLogout: function onPostponeLogout() {},
88
121
  enableBackendStatusCheck: true,
89
122
  backendCheckTimeout: DEFAULT_BACKEND_CHECK_TIMEOUT,
90
- checkBackendIsUp: () => Promise.resolve(null),
91
- onBackendDown: () => () => {},
123
+ checkBackendIsUp: function checkBackendIsUp() {
124
+ return Promise.resolve(null);
125
+ },
126
+ onBackendDown: function onBackendDown() {
127
+ return function () {};
128
+ },
92
129
  defaultExpiresIn: DEFAULT_EXPIRES_TIMEOUT,
93
130
  waitForRedirectTimeout: DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT,
94
131
  translations: null
95
132
  };
96
- class Auth {
97
- static DEFAULT_CONFIG = DEFAULT_CONFIG;
98
- static API_PATH = 'api/rest/';
99
- static API_AUTH_PATH = 'oauth2/auth';
100
- static API_PROFILE_PATH = 'users/me';
101
- static CLOSE_BACKEND_DOWN_MESSAGE = 'backend-check-succeeded';
102
- static CLOSE_WINDOW_MESSAGE = 'close-login-window';
103
- static shouldRefreshToken = TokenValidator.shouldRefreshToken;
104
- static storageIsUnavailable = !navigator.cookieEnabled;
105
- config;
106
- listeners = new Listeners();
107
- http;
108
- _service = {};
109
- _storage = null;
110
- _responseParser = new AuthResponseParser();
111
- _requestBuilder = null;
112
- _backgroundFlow;
113
- _embeddedFlow = null;
114
- _tokenValidator = null;
115
- _postponed = false;
116
- _backendCheckPromise = null;
117
- _authDialogService = undefined;
118
- _domainStorage;
119
- user = null;
120
- _initDeferred;
121
- _isLoginWindowOpen;
122
- constructor(config) {
133
+ var Auth = /*#__PURE__*/function () {
134
+ function Auth(config) {
135
+ var _this = this;
136
+ _classCallCheck(this, Auth);
137
+ _defineProperty(this, "config", void 0);
138
+ _defineProperty(this, "listeners", new Listeners());
139
+ _defineProperty(this, "http", void 0);
140
+ _defineProperty(this, "_service", {});
141
+ _defineProperty(this, "_storage", null);
142
+ _defineProperty(this, "_responseParser", new AuthResponseParser());
143
+ _defineProperty(this, "_requestBuilder", null);
144
+ _defineProperty(this, "_backgroundFlow", void 0);
145
+ _defineProperty(this, "_embeddedFlow", null);
146
+ _defineProperty(this, "_tokenValidator", null);
147
+ _defineProperty(this, "_postponed", false);
148
+ _defineProperty(this, "_backendCheckPromise", null);
149
+ _defineProperty(this, "_authDialogService", undefined);
150
+ _defineProperty(this, "_domainStorage", void 0);
151
+ _defineProperty(this, "user", null);
152
+ _defineProperty(this, "_initDeferred", void 0);
153
+ _defineProperty(this, "_isLoginWindowOpen", void 0);
123
154
  if (!config) {
124
155
  throw new Error('Config is required');
125
156
  }
126
157
  if (config.serverUri == null) {
127
158
  throw new Error('\"serverUri\" property is required');
128
159
  }
129
- const unsupportedParams = ['redirect_uri', 'request_credentials', 'client_id'].filter(param => config.hasOwnProperty(param));
160
+ var unsupportedParams = ['redirect_uri', 'request_credentials', 'client_id'].filter(function (param) {
161
+ return config.hasOwnProperty(param);
162
+ });
130
163
  if (unsupportedParams.length !== 0) {
131
- throw new Error(`The following parameters are no longer supported: ${unsupportedParams.join(', ')}. Please change them from snake_case to camelCase.`);
164
+ throw new Error("The following parameters are no longer supported: ".concat(unsupportedParams.join(', '), ". Please change them from snake_case to camelCase."));
132
165
  }
133
166
  config.userFields = config.userFields || [];
134
- this.config = {
135
- ...Auth.DEFAULT_CONFIG,
136
- ...config
137
- };
138
- const {
139
- clientId,
140
- redirect,
141
- redirectUri,
142
- requestCredentials,
143
- scope
144
- } = this.config;
145
- const serverUriLength = this.config.serverUri.length;
167
+ this.config = _objectSpread2(_objectSpread2({}, Auth.DEFAULT_CONFIG), config);
168
+ var _this$config = this.config,
169
+ clientId = _this$config.clientId,
170
+ redirect = _this$config.redirect,
171
+ redirectUri = _this$config.redirectUri,
172
+ requestCredentials = _this$config.requestCredentials,
173
+ scope = _this$config.scope;
174
+ var serverUriLength = this.config.serverUri.length;
146
175
  if (serverUriLength > 0 && this.config.serverUri.charAt(serverUriLength - 1) !== '/') {
147
176
  this.config.serverUri += '/';
148
177
  }
149
178
  this.config.userParams = {
150
179
  query: {
151
- fields: [...new Set(Auth.DEFAULT_CONFIG.userFields.concat(config.userFields))].join()
180
+ fields: _toConsumableArray(new Set(Auth.DEFAULT_CONFIG.userFields.concat(config.userFields))).join()
152
181
  }
153
182
  };
154
183
  if (!scope.includes(Auth.DEFAULT_CONFIG.clientId)) {
155
184
  scope.push(Auth.DEFAULT_CONFIG.clientId);
156
185
  }
157
186
  this._storage = new AuthStorage({
158
- messagePrefix: `${clientId}-message-`,
159
- stateKeyPrefix: `${clientId}-states-`,
160
- tokenKey: `${clientId}-token`,
161
- userKey: `${clientId}-user-`
187
+ messagePrefix: "".concat(clientId, "-message-"),
188
+ stateKeyPrefix: "".concat(clientId, "-states-"),
189
+ tokenKey: "".concat(clientId, "-token"),
190
+ userKey: "".concat(clientId, "-user-")
162
191
  });
163
192
  this._domainStorage = new AuthStorage({
164
193
  messagePrefix: 'domain-message-'
165
194
  });
166
195
  this._requestBuilder = new AuthRequestBuilder({
167
196
  authorization: this.config.serverUri + Auth.API_PATH + Auth.API_AUTH_PATH,
168
- clientId,
169
- redirect,
170
- redirectUri,
171
- requestCredentials,
197
+ clientId: clientId,
198
+ redirect: redirect,
199
+ redirectUri: redirectUri,
200
+ requestCredentials: requestCredentials,
172
201
  scopes: scope
173
202
  }, this._storage);
174
- let {
175
- backgroundRefreshTimeout
176
- } = this.config;
203
+ var backgroundRefreshTimeout = this.config.backgroundRefreshTimeout;
177
204
  if (!backgroundRefreshTimeout) {
178
205
  backgroundRefreshTimeout = this.config.embeddedLogin ? DEFAULT_BACKGROUND_TIMEOUT : BACKGROUND_REDIRECT_TIMEOUT;
179
206
  }
@@ -182,727 +209,1426 @@ class Auth {
182
209
  var _this$config$translat;
183
210
  this._embeddedFlow = new this.config.EmbeddedLoginFlow(this._requestBuilder, this._storage, (_this$config$translat = this.config.translations) !== null && _this$config$translat !== void 0 ? _this$config$translat : getTranslationsWithFallback());
184
211
  }
185
- const API_BASE = this.config.serverUri + Auth.API_PATH;
186
- const fetchConfig = config.fetchCredentials ? {
212
+ var API_BASE = this.config.serverUri + Auth.API_PATH;
213
+ var fetchConfig = config.fetchCredentials ? {
187
214
  credentials: config.fetchCredentials
188
215
  } : undefined;
189
216
  this.http = new HTTP(this, API_BASE, fetchConfig);
190
- const getUser = async token => {
191
- const user = await this.getUser(token);
192
- this.user = user;
193
- return user;
194
- };
217
+ var getUser = /*#__PURE__*/function () {
218
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(token) {
219
+ var user;
220
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
221
+ while (1) switch (_context.prev = _context.next) {
222
+ case 0:
223
+ _context.next = 2;
224
+ return _this.getUser(token);
225
+ case 2:
226
+ user = _context.sent;
227
+ _this.user = user;
228
+ return _context.abrupt("return", user);
229
+ case 5:
230
+ case "end":
231
+ return _context.stop();
232
+ }
233
+ }, _callee);
234
+ }));
235
+ return function getUser(_x) {
236
+ return _ref.apply(this, arguments);
237
+ };
238
+ }();
195
239
  this._tokenValidator = new TokenValidator(this.config, getUser, this._storage);
196
240
  if (this.config.onLogout) {
197
241
  this.addListener(LOGOUT_EVENT, this.config.onLogout);
198
242
  }
199
243
  if (this.config.reloadOnUserChange) {
200
- this.addListener(USER_CHANGED_EVENT, () => this._reloadCurrentPage());
244
+ this.addListener(USER_CHANGED_EVENT, function () {
245
+ return _this._reloadCurrentPage();
246
+ });
201
247
  }
202
- this.addListener(LOGOUT_POSTPONED_EVENT, () => this._setPostponed(true));
203
- this.addListener(USER_CHANGE_POSTPONED_EVENT, () => this._setPostponed(true));
204
- this.addListener(USER_CHANGED_EVENT, () => this._setPostponed(false));
205
- this.addListener(USER_CHANGED_EVENT, user => {
248
+ this.addListener(LOGOUT_POSTPONED_EVENT, function () {
249
+ return _this._setPostponed(true);
250
+ });
251
+ this.addListener(USER_CHANGE_POSTPONED_EVENT, function () {
252
+ return _this._setPostponed(true);
253
+ });
254
+ this.addListener(USER_CHANGED_EVENT, function () {
255
+ return _this._setPostponed(false);
256
+ });
257
+ this.addListener(USER_CHANGED_EVENT, function (user) {
206
258
  if (user) {
207
- this._updateDomainUser(user.id);
259
+ _this._updateDomainUser(user.id);
208
260
  }
209
261
  });
210
262
  if (this.config.cacheCurrentUser) {
211
- this.addListener(LOGOUT_EVENT, () => this._storage?.wipeCachedCurrentUser());
212
- this.addListener(USER_CHANGED_EVENT, () => this._storage?.onUserChanged());
263
+ this.addListener(LOGOUT_EVENT, function () {
264
+ var _this$_storage;
265
+ return (_this$_storage = _this._storage) === null || _this$_storage === void 0 ? void 0 : _this$_storage.wipeCachedCurrentUser();
266
+ });
267
+ this.addListener(USER_CHANGED_EVENT, function () {
268
+ var _this$_storage2;
269
+ return (_this$_storage2 = _this._storage) === null || _this$_storage2 === void 0 ? void 0 : _this$_storage2.onUserChanged();
270
+ });
213
271
  }
214
272
  this._createInitDeferred();
215
273
  this.setUpPreconnect(config.serverUri);
216
274
  }
217
- _setPostponed() {
218
- let postponed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
219
- this._postponed = postponed;
220
- }
221
- _updateDomainUser(userID) {
222
- this._domainStorage.sendMessage(DOMAIN_USER_CHANGED_EVENT, {
223
- userID,
224
- serviceID: this.config.clientId
225
- });
226
- }
227
- addListener(event, handler) {
228
- this.listeners.add(event, handler);
229
- }
230
- removeListener(event, handler) {
231
- this.listeners.remove(event, handler);
232
- }
233
- setAuthDialogService(authDialogService) {
234
- this._authDialogService = authDialogService;
235
- }
236
- setCurrentService(service) {
237
- this._service = service;
238
- }
239
- _createInitDeferred() {
240
- const deferred = {};
241
- deferred.promise = new Promise((resolve, reject) => {
242
- deferred.resolve = resolve;
243
- deferred.reject = reject;
244
- });
245
- this._initDeferred = deferred;
246
- }
247
- /**
248
- * @return {Promise.<string>} absolute URL promise that is resolved to a URL
249
- * that should be restored after returning back from auth server.
250
- */
251
- async init() {
252
- this._storage?.onTokenChange(async token => {
253
- const isGuest = this.user ? this.user.guest : false;
254
- if (isGuest && !token) {
255
- return;
256
- }
257
- if (!token) {
258
- this.logout();
259
- } else {
260
- try {
261
- await this._detectUserChange(token.accessToken);
262
- } catch (error) {
263
- if (!(error instanceof Error)) {
264
- throw error;
265
- }
266
- if (this._canShowDialogs()) {
267
- this._showAuthDialog({
268
- nonInteractive: true,
269
- error
270
- });
271
- }
272
- }
273
- }
274
- });
275
- this._domainStorage.onMessage(DOMAIN_USER_CHANGED_EVENT, message => {
276
- const {
277
- userID,
278
- serviceID
279
- } = message || {};
280
- if (serviceID === this.config.clientId) {
281
- return;
282
- }
283
- if (this.user && userID === this.user.id) {
284
- return;
285
- }
286
- this.forceTokenUpdate();
287
- });
288
- let state;
289
- try {
290
- // Look for token or error in hash
291
- state = await this._checkForAuthResponse();
292
- } catch (error) {
293
- return error instanceof Error ? this.handleInitError(error) : undefined;
275
+ _createClass(Auth, [{
276
+ key: "_setPostponed",
277
+ value: function _setPostponed() {
278
+ var postponed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
279
+ this._postponed = postponed;
294
280
  }
295
- // Return endless promise in the background to avoid service start
296
- if (state && state.nonRedirect) {
297
- return new Promise(noop);
281
+ }, {
282
+ key: "_updateDomainUser",
283
+ value: function _updateDomainUser(userID) {
284
+ this._domainStorage.sendMessage(DOMAIN_USER_CHANGED_EVENT, {
285
+ userID: userID,
286
+ serviceID: this.config.clientId
287
+ });
298
288
  }
299
- try {
300
- // Check if there is a valid token
301
- await this._tokenValidator?.validateToken();
302
- // Checking if there is a message left by another app on this domain
303
- const message = await this._domainStorage._messagesStorage.get(`domain-message-${DOMAIN_USER_CHANGED_EVENT}`);
304
- if (message) {
305
- const {
306
- userID,
307
- serviceID
308
- } = message;
309
- if (serviceID !== this.config.clientId && (!userID || this.user?.id !== userID)) {
310
- this.forceTokenUpdate();
311
- }
312
- }
313
- // Access token appears to be valid.
314
- // We may resolve restoreLocation URL now
315
- if (!state) {
316
- // Check if we have requested to restore state anyway
317
- state = await this._checkForStateRestoration();
318
- }
319
- this._initDeferred?.resolve?.(state && state.restoreLocation);
320
- return state?.restoreLocation;
321
- } catch (error) {
322
- if (Auth.storageIsUnavailable) {
323
- this._initDeferred?.resolve?.(); // No way to handle if cookies are disabled
324
- await this.requestUser(); // Someone may expect user to be loaded as a part of token validation
325
- return null;
326
- }
327
- return error instanceof Error ? this.handleInitValidationError(error) : undefined;
289
+ }, {
290
+ key: "addListener",
291
+ value: function addListener(event, handler) {
292
+ this.listeners.add(event, handler);
328
293
  }
329
- }
330
- async sendRedirect(error) {
331
- const authRequest = await this._requestBuilder?.prepareAuthRequest();
332
- if (authRequest != null) {
333
- this._redirectCurrentPage(authRequest.url);
294
+ }, {
295
+ key: "removeListener",
296
+ value: function removeListener(event, handler) {
297
+ this.listeners.remove(event, handler);
334
298
  }
335
- // HUB-10867 Since we already redirecting the page, there is no actual need to throw an error
336
- // and scare user with flashing error
337
- // But let's keep it just in case redirect was not successful
338
- await new Promise(resolve => setTimeout(resolve, this.config.waitForRedirectTimeout));
339
- throw error;
340
- }
341
- async handleInitError(error) {
342
- if ('stateId' in error && error.stateId) {
343
- try {
344
- const state = await this._storage?.getState(error.stateId);
345
- if (state && state.nonRedirect) {
346
- state.error = error;
347
- this._storage?.saveState(error.stateId, state);
348
- // Return endless promise in the background to avoid service start
349
- return new Promise(noop);
350
- }
351
- } catch (e) {
352
- // Throw the original error instead below
353
- }
299
+ }, {
300
+ key: "setAuthDialogService",
301
+ value: function setAuthDialogService(authDialogService) {
302
+ this._authDialogService = authDialogService;
354
303
  }
355
- throw error;
356
- }
357
- async handleInitValidationError(error) {
358
- if ('cause' in error && error.cause instanceof Error && error.cause?.message === 'invalid_client') {
359
- // eslint-disable-next-line no-console
360
- console.error('RingUI Auth: invalid client detected. Logging out', error);
361
- await this.logout();
362
- return undefined;
304
+ }, {
305
+ key: "setCurrentService",
306
+ value: function setCurrentService(service) {
307
+ this._service = service;
363
308
  }
364
- // Redirect flow
365
- if ('authRedirect' in error && error.authRedirect && this.config.redirect) {
366
- return this.sendRedirect(error);
309
+ }, {
310
+ key: "_createInitDeferred",
311
+ value: function _createInitDeferred() {
312
+ var deferred = {};
313
+ deferred.promise = new Promise(function (resolve, reject) {
314
+ deferred.resolve = resolve;
315
+ deferred.reject = reject;
316
+ });
317
+ this._initDeferred = deferred;
367
318
  }
368
- // Background flow
369
- if ('authRedirect' in error && error.authRedirect && !this.config.redirect) {
370
- try {
371
- await this._backgroundFlow?.authorize();
372
- await this._tokenValidator?.validateToken();
373
- this._initDeferred?.resolve?.();
374
- return undefined;
375
- } catch (validationError) {
376
- // Fallback to redirect flow
377
- return validationError instanceof Error ? this.sendRedirect(validationError) : undefined;
319
+ /**
320
+ * @return {Promise.<string>} absolute URL promise that is resolved to a URL
321
+ * that should be restored after returning back from auth server.
322
+ */
323
+ }, {
324
+ key: "init",
325
+ value: function () {
326
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
327
+ var _this$_storage3,
328
+ _this2 = this;
329
+ var state, _this$_tokenValidator, _this$_initDeferred, _this$_initDeferred$r, _state, message, _this$user, userID, serviceID, _this$_initDeferred2, _this$_initDeferred2$;
330
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
331
+ while (1) switch (_context3.prev = _context3.next) {
332
+ case 0:
333
+ (_this$_storage3 = this._storage) === null || _this$_storage3 === void 0 ? void 0 : _this$_storage3.onTokenChange( /*#__PURE__*/function () {
334
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(token) {
335
+ var isGuest;
336
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
337
+ while (1) switch (_context2.prev = _context2.next) {
338
+ case 0:
339
+ isGuest = _this2.user ? _this2.user.guest : false;
340
+ if (!(isGuest && !token)) {
341
+ _context2.next = 3;
342
+ break;
343
+ }
344
+ return _context2.abrupt("return");
345
+ case 3:
346
+ if (token) {
347
+ _context2.next = 7;
348
+ break;
349
+ }
350
+ _this2.logout();
351
+ _context2.next = 17;
352
+ break;
353
+ case 7:
354
+ _context2.prev = 7;
355
+ _context2.next = 10;
356
+ return _this2._detectUserChange(token.accessToken);
357
+ case 10:
358
+ _context2.next = 17;
359
+ break;
360
+ case 12:
361
+ _context2.prev = 12;
362
+ _context2.t0 = _context2["catch"](7);
363
+ if (_context2.t0 instanceof Error) {
364
+ _context2.next = 16;
365
+ break;
366
+ }
367
+ throw _context2.t0;
368
+ case 16:
369
+ if (_this2._canShowDialogs()) {
370
+ _this2._showAuthDialog({
371
+ nonInteractive: true,
372
+ error: _context2.t0
373
+ });
374
+ }
375
+ case 17:
376
+ case "end":
377
+ return _context2.stop();
378
+ }
379
+ }, _callee2, null, [[7, 12]]);
380
+ }));
381
+ return function (_x2) {
382
+ return _ref2.apply(this, arguments);
383
+ };
384
+ }());
385
+ this._domainStorage.onMessage(DOMAIN_USER_CHANGED_EVENT, function (message) {
386
+ var _ref3 = message || {},
387
+ userID = _ref3.userID,
388
+ serviceID = _ref3.serviceID;
389
+ if (serviceID === _this2.config.clientId) {
390
+ return;
391
+ }
392
+ if (_this2.user && userID === _this2.user.id) {
393
+ return;
394
+ }
395
+ _this2.forceTokenUpdate();
396
+ });
397
+ _context3.prev = 2;
398
+ _context3.next = 5;
399
+ return this._checkForAuthResponse();
400
+ case 5:
401
+ state = _context3.sent;
402
+ _context3.next = 11;
403
+ break;
404
+ case 8:
405
+ _context3.prev = 8;
406
+ _context3.t0 = _context3["catch"](2);
407
+ return _context3.abrupt("return", _context3.t0 instanceof Error ? this.handleInitError(_context3.t0) : undefined);
408
+ case 11:
409
+ if (!(state && state.nonRedirect)) {
410
+ _context3.next = 13;
411
+ break;
412
+ }
413
+ return _context3.abrupt("return", new Promise(noop));
414
+ case 13:
415
+ _context3.prev = 13;
416
+ _context3.next = 16;
417
+ return (_this$_tokenValidator = this._tokenValidator) === null || _this$_tokenValidator === void 0 ? void 0 : _this$_tokenValidator.validateToken();
418
+ case 16:
419
+ _context3.next = 18;
420
+ return this._domainStorage._messagesStorage.get("domain-message-".concat(DOMAIN_USER_CHANGED_EVENT));
421
+ case 18:
422
+ message = _context3.sent;
423
+ if (message) {
424
+ userID = message.userID, serviceID = message.serviceID;
425
+ if (serviceID !== this.config.clientId && (!userID || ((_this$user = this.user) === null || _this$user === void 0 ? void 0 : _this$user.id) !== userID)) {
426
+ this.forceTokenUpdate();
427
+ }
428
+ }
429
+ // Access token appears to be valid.
430
+ // We may resolve restoreLocation URL now
431
+ if (state) {
432
+ _context3.next = 24;
433
+ break;
434
+ }
435
+ _context3.next = 23;
436
+ return this._checkForStateRestoration();
437
+ case 23:
438
+ state = _context3.sent;
439
+ case 24:
440
+ (_this$_initDeferred = this._initDeferred) === null || _this$_initDeferred === void 0 ? void 0 : (_this$_initDeferred$r = _this$_initDeferred.resolve) === null || _this$_initDeferred$r === void 0 ? void 0 : _this$_initDeferred$r.call(_this$_initDeferred, state && state.restoreLocation);
441
+ return _context3.abrupt("return", (_state = state) === null || _state === void 0 ? void 0 : _state.restoreLocation);
442
+ case 28:
443
+ _context3.prev = 28;
444
+ _context3.t1 = _context3["catch"](13);
445
+ if (!Auth.storageIsUnavailable) {
446
+ _context3.next = 35;
447
+ break;
448
+ }
449
+ (_this$_initDeferred2 = this._initDeferred) === null || _this$_initDeferred2 === void 0 ? void 0 : (_this$_initDeferred2$ = _this$_initDeferred2.resolve) === null || _this$_initDeferred2$ === void 0 ? void 0 : _this$_initDeferred2$.call(_this$_initDeferred2); // No way to handle if cookies are disabled
450
+ _context3.next = 34;
451
+ return this.requestUser();
452
+ case 34:
453
+ return _context3.abrupt("return", null);
454
+ case 35:
455
+ return _context3.abrupt("return", _context3.t1 instanceof Error ? this.handleInitValidationError(_context3.t1) : undefined);
456
+ case 36:
457
+ case "end":
458
+ return _context3.stop();
459
+ }
460
+ }, _callee3, this, [[2, 8], [13, 28]]);
461
+ }));
462
+ function init() {
463
+ return _init.apply(this, arguments);
378
464
  }
379
- }
380
- this._initDeferred?.reject?.(error);
381
- throw error;
382
- }
383
- /**
384
- * Get token from local storage or request it if necessary.
385
- * Can redirect to login page.
386
- * @return {Promise.<string>}
387
- */
388
- async requestToken() {
389
- if (this._postponed) {
390
- throw new Error('You should log in to be able to make requests');
391
- }
392
- try {
393
- var _await$this$_tokenVal;
394
- await this._initDeferred?.promise;
395
- if (Auth.storageIsUnavailable) {
396
- return null; // Forever guest if storage is unavailable
465
+ return init;
466
+ }()
467
+ }, {
468
+ key: "sendRedirect",
469
+ value: function () {
470
+ var _sendRedirect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(error) {
471
+ var _this$_requestBuilder,
472
+ _this3 = this;
473
+ var authRequest;
474
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
475
+ while (1) switch (_context4.prev = _context4.next) {
476
+ case 0:
477
+ _context4.next = 2;
478
+ return (_this$_requestBuilder = this._requestBuilder) === null || _this$_requestBuilder === void 0 ? void 0 : _this$_requestBuilder.prepareAuthRequest();
479
+ case 2:
480
+ authRequest = _context4.sent;
481
+ if (authRequest != null) {
482
+ this._redirectCurrentPage(authRequest.url);
483
+ }
484
+ // HUB-10867 Since we already redirecting the page, there is no actual need to throw an error
485
+ // and scare user with flashing error
486
+ // But let's keep it just in case redirect was not successful
487
+ _context4.next = 6;
488
+ return new Promise(function (resolve) {
489
+ return setTimeout(resolve, _this3.config.waitForRedirectTimeout);
490
+ });
491
+ case 6:
492
+ throw error;
493
+ case 7:
494
+ case "end":
495
+ return _context4.stop();
496
+ }
497
+ }, _callee4, this);
498
+ }));
499
+ function sendRedirect(_x3) {
500
+ return _sendRedirect.apply(this, arguments);
397
501
  }
398
-
399
- return (_await$this$_tokenVal = await this._tokenValidator?.validateTokenLocally()) !== null && _await$this$_tokenVal !== void 0 ? _await$this$_tokenVal : null;
400
- } catch (e) {
401
- return this.forceTokenUpdate();
402
- }
403
- }
404
- /**
405
- * Get new token in the background or redirect to the login page.
406
- * @return {Promise.<string>}
407
- */
408
- async forceTokenUpdate() {
409
- try {
410
- if (!this._backendCheckPromise) {
411
- this._backendCheckPromise = this._checkBackendsStatusesIfEnabled();
502
+ return sendRedirect;
503
+ }()
504
+ }, {
505
+ key: "handleInitError",
506
+ value: function () {
507
+ var _handleInitError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(error) {
508
+ var _this$_storage4, state, _this$_storage5;
509
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
510
+ while (1) switch (_context5.prev = _context5.next) {
511
+ case 0:
512
+ if (!('stateId' in error && error.stateId)) {
513
+ _context5.next = 13;
514
+ break;
515
+ }
516
+ _context5.prev = 1;
517
+ _context5.next = 4;
518
+ return (_this$_storage4 = this._storage) === null || _this$_storage4 === void 0 ? void 0 : _this$_storage4.getState(error.stateId);
519
+ case 4:
520
+ state = _context5.sent;
521
+ if (!(state && state.nonRedirect)) {
522
+ _context5.next = 9;
523
+ break;
524
+ }
525
+ state.error = error;
526
+ (_this$_storage5 = this._storage) === null || _this$_storage5 === void 0 ? void 0 : _this$_storage5.saveState(error.stateId, state);
527
+ // Return endless promise in the background to avoid service start
528
+ return _context5.abrupt("return", new Promise(noop));
529
+ case 9:
530
+ _context5.next = 13;
531
+ break;
532
+ case 11:
533
+ _context5.prev = 11;
534
+ _context5.t0 = _context5["catch"](1);
535
+ case 13:
536
+ throw error;
537
+ case 14:
538
+ case "end":
539
+ return _context5.stop();
540
+ }
541
+ }, _callee5, this, [[1, 11]]);
542
+ }));
543
+ function handleInitError(_x4) {
544
+ return _handleInitError.apply(this, arguments);
412
545
  }
413
- await this._backendCheckPromise;
414
- } catch (e) {
415
- throw new Error('Cannot refresh token: backend is not available. Postponed by user.');
416
- } finally {
417
- this._backendCheckPromise = null;
418
- }
419
- try {
420
- var _await$this$_backgrou;
421
- return (_await$this$_backgrou = await this._backgroundFlow?.authorize()) !== null && _await$this$_backgrou !== void 0 ? _await$this$_backgrou : null;
422
- } catch (error) {
423
- if (!(error instanceof Error)) {
424
- return null;
546
+ return handleInitError;
547
+ }()
548
+ }, {
549
+ key: "handleInitValidationError",
550
+ value: function () {
551
+ var _handleInitValidationError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(error) {
552
+ var _error$cause, _this$_initDeferred4, _this$_initDeferred4$;
553
+ var _this$_backgroundFlow, _this$_tokenValidator2, _this$_initDeferred3, _this$_initDeferred3$;
554
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
555
+ while (1) switch (_context6.prev = _context6.next) {
556
+ case 0:
557
+ if (!('cause' in error && error.cause instanceof Error && ((_error$cause = error.cause) === null || _error$cause === void 0 ? void 0 : _error$cause.message) === 'invalid_client')) {
558
+ _context6.next = 5;
559
+ break;
560
+ }
561
+ // eslint-disable-next-line no-console
562
+ console.error('RingUI Auth: invalid client detected. Logging out', error);
563
+ _context6.next = 4;
564
+ return this.logout();
565
+ case 4:
566
+ return _context6.abrupt("return", undefined);
567
+ case 5:
568
+ if (!('authRedirect' in error && error.authRedirect && this.config.redirect)) {
569
+ _context6.next = 7;
570
+ break;
571
+ }
572
+ return _context6.abrupt("return", this.sendRedirect(error));
573
+ case 7:
574
+ if (!('authRedirect' in error && error.authRedirect && !this.config.redirect)) {
575
+ _context6.next = 20;
576
+ break;
577
+ }
578
+ _context6.prev = 8;
579
+ _context6.next = 11;
580
+ return (_this$_backgroundFlow = this._backgroundFlow) === null || _this$_backgroundFlow === void 0 ? void 0 : _this$_backgroundFlow.authorize();
581
+ case 11:
582
+ _context6.next = 13;
583
+ return (_this$_tokenValidator2 = this._tokenValidator) === null || _this$_tokenValidator2 === void 0 ? void 0 : _this$_tokenValidator2.validateToken();
584
+ case 13:
585
+ (_this$_initDeferred3 = this._initDeferred) === null || _this$_initDeferred3 === void 0 ? void 0 : (_this$_initDeferred3$ = _this$_initDeferred3.resolve) === null || _this$_initDeferred3$ === void 0 ? void 0 : _this$_initDeferred3$.call(_this$_initDeferred3);
586
+ return _context6.abrupt("return", undefined);
587
+ case 17:
588
+ _context6.prev = 17;
589
+ _context6.t0 = _context6["catch"](8);
590
+ return _context6.abrupt("return", _context6.t0 instanceof Error ? this.sendRedirect(_context6.t0) : undefined);
591
+ case 20:
592
+ (_this$_initDeferred4 = this._initDeferred) === null || _this$_initDeferred4 === void 0 ? void 0 : (_this$_initDeferred4$ = _this$_initDeferred4.reject) === null || _this$_initDeferred4$ === void 0 ? void 0 : _this$_initDeferred4$.call(_this$_initDeferred4, error);
593
+ throw error;
594
+ case 22:
595
+ case "end":
596
+ return _context6.stop();
597
+ }
598
+ }, _callee6, this, [[8, 17]]);
599
+ }));
600
+ function handleInitValidationError(_x5) {
601
+ return _handleInitValidationError.apply(this, arguments);
425
602
  }
426
- if (this._canShowDialogs()) {
427
- return new Promise(resolve => {
428
- const onTryAgain = async () => {
429
- try {
430
- const result = await this._backgroundFlow?.authorize();
431
- resolve(result !== null && result !== void 0 ? result : null);
432
- } catch (retryError) {
433
- if (retryError instanceof Error) {
434
- this._showAuthDialog({
603
+ return handleInitValidationError;
604
+ }()
605
+ /**
606
+ * Get token from local storage or request it if necessary.
607
+ * Can redirect to login page.
608
+ * @return {Promise.<string>}
609
+ */
610
+ }, {
611
+ key: "requestToken",
612
+ value: function () {
613
+ var _requestToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
614
+ var _this$_initDeferred5, _yield$this$_tokenVal, _this$_tokenValidator3;
615
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
616
+ while (1) switch (_context7.prev = _context7.next) {
617
+ case 0:
618
+ if (!this._postponed) {
619
+ _context7.next = 2;
620
+ break;
621
+ }
622
+ throw new Error('You should log in to be able to make requests');
623
+ case 2:
624
+ _context7.prev = 2;
625
+ _context7.next = 5;
626
+ return (_this$_initDeferred5 = this._initDeferred) === null || _this$_initDeferred5 === void 0 ? void 0 : _this$_initDeferred5.promise;
627
+ case 5:
628
+ if (!Auth.storageIsUnavailable) {
629
+ _context7.next = 7;
630
+ break;
631
+ }
632
+ return _context7.abrupt("return", null);
633
+ case 7:
634
+ _context7.next = 9;
635
+ return (_this$_tokenValidator3 = this._tokenValidator) === null || _this$_tokenValidator3 === void 0 ? void 0 : _this$_tokenValidator3.validateTokenLocally();
636
+ case 9:
637
+ _context7.t1 = _yield$this$_tokenVal = _context7.sent;
638
+ _context7.t0 = _context7.t1 !== null;
639
+ if (!_context7.t0) {
640
+ _context7.next = 13;
641
+ break;
642
+ }
643
+ _context7.t0 = _yield$this$_tokenVal !== void 0;
644
+ case 13:
645
+ if (!_context7.t0) {
646
+ _context7.next = 17;
647
+ break;
648
+ }
649
+ _context7.t2 = _yield$this$_tokenVal;
650
+ _context7.next = 18;
651
+ break;
652
+ case 17:
653
+ _context7.t2 = null;
654
+ case 18:
655
+ return _context7.abrupt("return", _context7.t2);
656
+ case 21:
657
+ _context7.prev = 21;
658
+ _context7.t3 = _context7["catch"](2);
659
+ return _context7.abrupt("return", this.forceTokenUpdate());
660
+ case 24:
661
+ case "end":
662
+ return _context7.stop();
663
+ }
664
+ }, _callee7, this, [[2, 21]]);
665
+ }));
666
+ function requestToken() {
667
+ return _requestToken.apply(this, arguments);
668
+ }
669
+ return requestToken;
670
+ }()
671
+ /**
672
+ * Get new token in the background or redirect to the login page.
673
+ * @return {Promise.<string>}
674
+ */
675
+ }, {
676
+ key: "forceTokenUpdate",
677
+ value: function () {
678
+ var _forceTokenUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
679
+ var _this4 = this;
680
+ var _yield$this$_backgrou, _this$_backgroundFlow2, _this$_requestBuilder2, authRequest;
681
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
682
+ while (1) switch (_context9.prev = _context9.next) {
683
+ case 0:
684
+ _context9.prev = 0;
685
+ if (!this._backendCheckPromise) {
686
+ this._backendCheckPromise = this._checkBackendsStatusesIfEnabled();
687
+ }
688
+ _context9.next = 4;
689
+ return this._backendCheckPromise;
690
+ case 4:
691
+ _context9.next = 9;
692
+ break;
693
+ case 6:
694
+ _context9.prev = 6;
695
+ _context9.t0 = _context9["catch"](0);
696
+ throw new Error('Cannot refresh token: backend is not available. Postponed by user.');
697
+ case 9:
698
+ _context9.prev = 9;
699
+ this._backendCheckPromise = null;
700
+ return _context9.finish(9);
701
+ case 12:
702
+ _context9.prev = 12;
703
+ _context9.next = 15;
704
+ return (_this$_backgroundFlow2 = this._backgroundFlow) === null || _this$_backgroundFlow2 === void 0 ? void 0 : _this$_backgroundFlow2.authorize();
705
+ case 15:
706
+ _context9.t2 = _yield$this$_backgrou = _context9.sent;
707
+ _context9.t1 = _context9.t2 !== null;
708
+ if (!_context9.t1) {
709
+ _context9.next = 19;
710
+ break;
711
+ }
712
+ _context9.t1 = _yield$this$_backgrou !== void 0;
713
+ case 19:
714
+ if (!_context9.t1) {
715
+ _context9.next = 23;
716
+ break;
717
+ }
718
+ _context9.t3 = _yield$this$_backgrou;
719
+ _context9.next = 24;
720
+ break;
721
+ case 23:
722
+ _context9.t3 = null;
723
+ case 24:
724
+ return _context9.abrupt("return", _context9.t3);
725
+ case 27:
726
+ _context9.prev = 27;
727
+ _context9.t4 = _context9["catch"](12);
728
+ if (_context9.t4 instanceof Error) {
729
+ _context9.next = 31;
730
+ break;
731
+ }
732
+ return _context9.abrupt("return", null);
733
+ case 31:
734
+ if (!this._canShowDialogs()) {
735
+ _context9.next = 35;
736
+ break;
737
+ }
738
+ return _context9.abrupt("return", new Promise(function (resolve) {
739
+ var onTryAgain = /*#__PURE__*/function () {
740
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
741
+ var _this4$_backgroundFlo, result;
742
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
743
+ while (1) switch (_context8.prev = _context8.next) {
744
+ case 0:
745
+ _context8.prev = 0;
746
+ _context8.next = 3;
747
+ return (_this4$_backgroundFlo = _this4._backgroundFlow) === null || _this4$_backgroundFlo === void 0 ? void 0 : _this4$_backgroundFlo.authorize();
748
+ case 3:
749
+ result = _context8.sent;
750
+ resolve(result !== null && result !== void 0 ? result : null);
751
+ _context8.next = 11;
752
+ break;
753
+ case 7:
754
+ _context8.prev = 7;
755
+ _context8.t0 = _context8["catch"](0);
756
+ if (_context8.t0 instanceof Error) {
757
+ _this4._showAuthDialog({
758
+ nonInteractive: true,
759
+ error: _context8.t0,
760
+ onTryAgain: onTryAgain
761
+ });
762
+ }
763
+ throw _context8.t0;
764
+ case 11:
765
+ case "end":
766
+ return _context8.stop();
767
+ }
768
+ }, _callee8, null, [[0, 7]]);
769
+ }));
770
+ return function onTryAgain() {
771
+ return _ref4.apply(this, arguments);
772
+ };
773
+ }();
774
+ _this4._showAuthDialog({
435
775
  nonInteractive: true,
436
- error: retryError,
437
- onTryAgain
776
+ error: _context9.t4,
777
+ onTryAgain: onTryAgain
438
778
  });
779
+ }));
780
+ case 35:
781
+ _context9.next = 37;
782
+ return (_this$_requestBuilder2 = this._requestBuilder) === null || _this$_requestBuilder2 === void 0 ? void 0 : _this$_requestBuilder2.prepareAuthRequest();
783
+ case 37:
784
+ authRequest = _context9.sent;
785
+ if (authRequest != null) {
786
+ this._redirectCurrentPage(authRequest.url);
439
787
  }
440
- throw retryError;
441
- }
442
- };
443
- this._showAuthDialog({
444
- nonInteractive: true,
445
- error: error,
446
- onTryAgain
447
- });
448
- });
449
- } else {
450
- const authRequest = await this._requestBuilder?.prepareAuthRequest();
451
- if (authRequest != null) {
452
- this._redirectCurrentPage(authRequest.url);
453
- }
788
+ case 39:
789
+ throw new TokenValidator.TokenValidationError(_context9.t4.message);
790
+ case 40:
791
+ case "end":
792
+ return _context9.stop();
793
+ }
794
+ }, _callee9, this, [[0, 6, 9, 12], [12, 27]]);
795
+ }));
796
+ function forceTokenUpdate() {
797
+ return _forceTokenUpdate.apply(this, arguments);
454
798
  }
455
- throw new TokenValidator.TokenValidationError(error.message);
456
- }
457
- }
458
- async loadCurrentService() {
459
- if (this._service.serviceName) {
460
- return;
461
- }
462
- try {
463
- const {
464
- serviceName,
465
- iconUrl: serviceImage
466
- } = (await this.http.get(`oauth2/interactive/login/settings?client_id=${this.config.clientId}`)) || {};
467
- this.setCurrentService({
468
- serviceImage,
469
- serviceName
470
- });
471
- } catch (e) {
472
- // noop
473
- }
474
- }
475
- getAPIPath() {
476
- return this.config.serverUri + Auth.API_PATH;
477
- }
478
- /**
479
- * @return {Promise.<object>}
480
- */
481
- getUser(accessToken) {
482
- if (this.config.cacheCurrentUser) {
483
- return this._storage?.getCachedUser(() => this.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, this.config.userParams));
484
- } else {
485
- return this.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, this.config.userParams);
486
- }
487
- }
488
- /**
489
- * @return {Promise.<object>}
490
- */
491
- async requestUser() {
492
- if (this.user) {
493
- return this.user;
494
- }
495
- const accessToken = await this.requestToken();
496
- // If user was fetched during token request
497
- if (this.user) {
498
- return this.user;
499
- }
500
- const user = await this.getUser(accessToken);
501
- this.user = user;
502
- return user;
503
- }
504
- async updateUser() {
505
- this._setPostponed(false);
506
- const accessToken = await this.requestToken();
507
- this._storage?.wipeCachedCurrentUser();
508
- const user = await this.getUser(accessToken);
509
- this.user = user;
510
- this.listeners.trigger(USER_CHANGED_EVENT, user);
511
- }
512
- async _detectUserChange(accessToken) {
513
- const windowWasOpen = this._isLoginWindowOpen;
514
- const user = await this.getUser(accessToken);
515
- const onApply = () => {
516
- this.user = user;
517
- this.listeners.trigger(USER_CHANGED_EVENT, user);
518
- };
519
- if (user && this.user && this.user.id !== user.id) {
520
- if (!this._canShowDialogs() || this.user.guest || windowWasOpen) {
521
- onApply();
522
- return;
799
+ return forceTokenUpdate;
800
+ }()
801
+ }, {
802
+ key: "loadCurrentService",
803
+ value: function () {
804
+ var _loadCurrentService = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
805
+ var _ref5, serviceName, serviceImage;
806
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
807
+ while (1) switch (_context10.prev = _context10.next) {
808
+ case 0:
809
+ if (!this._service.serviceName) {
810
+ _context10.next = 2;
811
+ break;
812
+ }
813
+ return _context10.abrupt("return");
814
+ case 2:
815
+ _context10.prev = 2;
816
+ _context10.next = 5;
817
+ return this.http.get("oauth2/interactive/login/settings?client_id=".concat(this.config.clientId));
818
+ case 5:
819
+ _context10.t0 = _context10.sent;
820
+ if (_context10.t0) {
821
+ _context10.next = 8;
822
+ break;
823
+ }
824
+ _context10.t0 = {};
825
+ case 8:
826
+ _ref5 = _context10.t0;
827
+ serviceName = _ref5.serviceName;
828
+ serviceImage = _ref5.iconUrl;
829
+ this.setCurrentService({
830
+ serviceImage: serviceImage,
831
+ serviceName: serviceName
832
+ });
833
+ _context10.next = 16;
834
+ break;
835
+ case 14:
836
+ _context10.prev = 14;
837
+ _context10.t1 = _context10["catch"](2);
838
+ case 16:
839
+ case "end":
840
+ return _context10.stop();
841
+ }
842
+ }, _callee10, this, [[2, 14]]);
843
+ }));
844
+ function loadCurrentService() {
845
+ return _loadCurrentService.apply(this, arguments);
523
846
  }
524
- if (user.guest) {
525
- this._showAuthDialog({
526
- nonInteractive: true
847
+ return loadCurrentService;
848
+ }()
849
+ }, {
850
+ key: "getAPIPath",
851
+ value: function getAPIPath() {
852
+ return this.config.serverUri + Auth.API_PATH;
853
+ }
854
+ /**
855
+ * @return {Promise.<object>}
856
+ */
857
+ }, {
858
+ key: "getUser",
859
+ value: function getUser(accessToken) {
860
+ var _this5 = this;
861
+ if (this.config.cacheCurrentUser) {
862
+ var _this$_storage6;
863
+ return (_this$_storage6 = this._storage) === null || _this$_storage6 === void 0 ? void 0 : _this$_storage6.getCachedUser(function () {
864
+ return _this5.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, _this5.config.userParams);
527
865
  });
528
- return;
866
+ } else {
867
+ return this.http.authorizedFetch(Auth.API_PROFILE_PATH, accessToken, this.config.userParams);
529
868
  }
530
- await this._showUserChangedDialog({
531
- newUser: user,
532
- onApply,
533
- onPostpone: () => {
534
- this.listeners.trigger(USER_CHANGE_POSTPONED_EVENT);
535
- this.config.onPostponeChangedUser(this.user, user);
536
- }
537
- });
538
- }
539
- }
540
- _beforeLogout(params) {
541
- if (this._canShowDialogs()) {
542
- this._showAuthDialog(params);
543
- return;
544
869
  }
545
- this.logout();
546
- }
547
- _showAuthDialog() {
548
- let {
549
- nonInteractive,
550
- error,
551
- canCancel,
552
- onTryAgain
553
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
554
- const {
555
- embeddedLogin,
556
- onPostponeLogout,
557
- translations
558
- } = this.config;
559
- const cancelable = this.user?.guest || canCancel;
560
- const actualTranslations = translations !== null && translations !== void 0 ? translations : getTranslations();
561
- this._createInitDeferred();
562
- const closeDialog = () => {
563
- /* eslint-disable @typescript-eslint/no-use-before-define */
564
- stopTokenListening?.();
565
- stopMessageListening?.();
566
- hide?.();
567
- /* eslint-enable @typescript-eslint/no-use-before-define */
568
- };
569
-
570
- const onConfirm = () => {
571
- if (!embeddedLogin) {
572
- closeDialog();
573
- this.logout();
574
- return;
575
- }
576
- this._runEmbeddedLogin();
577
- };
578
- const onCancel = () => {
579
- this._embeddedFlow?.stop();
580
- this._storage?.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
581
- closeDialog();
582
- if (!cancelable) {
583
- this._initDeferred?.resolve?.();
584
- this.listeners.trigger(LOGOUT_POSTPONED_EVENT);
585
- onPostponeLogout();
586
- return;
587
- }
588
- if (this.user?.guest && nonInteractive) {
589
- this.forceTokenUpdate();
590
- } else {
591
- this._initDeferred?.resolve?.();
870
+ /**
871
+ * @return {Promise.<object>}
872
+ */
873
+ }, {
874
+ key: "requestUser",
875
+ value: function () {
876
+ var _requestUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
877
+ var accessToken, user;
878
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
879
+ while (1) switch (_context11.prev = _context11.next) {
880
+ case 0:
881
+ if (!this.user) {
882
+ _context11.next = 2;
883
+ break;
884
+ }
885
+ return _context11.abrupt("return", this.user);
886
+ case 2:
887
+ _context11.next = 4;
888
+ return this.requestToken();
889
+ case 4:
890
+ accessToken = _context11.sent;
891
+ if (!this.user) {
892
+ _context11.next = 7;
893
+ break;
894
+ }
895
+ return _context11.abrupt("return", this.user);
896
+ case 7:
897
+ _context11.next = 9;
898
+ return this.getUser(accessToken);
899
+ case 9:
900
+ user = _context11.sent;
901
+ this.user = user;
902
+ return _context11.abrupt("return", user);
903
+ case 12:
904
+ case "end":
905
+ return _context11.stop();
906
+ }
907
+ }, _callee11, this);
908
+ }));
909
+ function requestUser() {
910
+ return _requestUser.apply(this, arguments);
592
911
  }
593
- };
594
- const onTryAgainClick = async () => {
595
- await onTryAgain?.();
596
- closeDialog();
597
- };
598
- const hide = this._authDialogService?.({
599
- ...this._service,
600
- loginCaption: actualTranslations.login,
601
- loginToCaption: actualTranslations.loginTo,
602
- confirmLabel: actualTranslations.login,
603
- tryAgainLabel: actualTranslations.tryAgainLabel,
604
- cancelLabel: cancelable ? actualTranslations.cancel : actualTranslations.postpone,
605
- errorMessage: this._extractErrorMessage(error, true),
606
- onConfirm,
607
- onCancel,
608
- onTryAgain: onTryAgain ? onTryAgainClick : undefined
609
- });
610
- const stopTokenListening = this._storage?.onTokenChange(token => {
611
- if (token) {
612
- closeDialog();
613
- this._initDeferred?.resolve?.();
912
+ return requestUser;
913
+ }()
914
+ }, {
915
+ key: "updateUser",
916
+ value: function () {
917
+ var _updateUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
918
+ var _this$_storage7;
919
+ var accessToken, user;
920
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
921
+ while (1) switch (_context12.prev = _context12.next) {
922
+ case 0:
923
+ this._setPostponed(false);
924
+ _context12.next = 3;
925
+ return this.requestToken();
926
+ case 3:
927
+ accessToken = _context12.sent;
928
+ (_this$_storage7 = this._storage) === null || _this$_storage7 === void 0 ? void 0 : _this$_storage7.wipeCachedCurrentUser();
929
+ _context12.next = 7;
930
+ return this.getUser(accessToken);
931
+ case 7:
932
+ user = _context12.sent;
933
+ this.user = user;
934
+ this.listeners.trigger(USER_CHANGED_EVENT, user);
935
+ case 10:
936
+ case "end":
937
+ return _context12.stop();
938
+ }
939
+ }, _callee12, this);
940
+ }));
941
+ function updateUser() {
942
+ return _updateUser.apply(this, arguments);
614
943
  }
615
- });
616
- const stopMessageListening = this._storage?.onMessage(Auth.CLOSE_WINDOW_MESSAGE, () => this._embeddedFlow?.stop());
617
- }
618
- _showUserChangedDialog(_ref) {
619
- var _translations$youHave, _newUser$name, _newUser$name2, _translations$login, _translations$loginTo, _translations$applyCh, _translations$tryAgai, _translations$postpon;
620
- let {
621
- newUser,
622
- onApply,
623
- onPostpone
624
- } = _ref;
625
- const {
626
- translations
627
- } = this.config;
628
- this._createInitDeferred();
629
- const done = () => {
630
- this._initDeferred?.resolve?.();
631
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
632
- hide?.();
633
- };
634
- const hide = this._authDialogService?.({
635
- ...this._service,
636
- title: (_translations$youHave = translations?.youHaveLoggedInAs) !== null && _translations$youHave !== void 0 ? _translations$youHave : translate('youHaveLoggedInAs').replace('%userName%', (_newUser$name = newUser.name) !== null && _newUser$name !== void 0 ? _newUser$name : '').replace('{{userName}}', (_newUser$name2 = newUser.name) !== null && _newUser$name2 !== void 0 ? _newUser$name2 : ''),
637
- loginCaption: (_translations$login = translations?.login) !== null && _translations$login !== void 0 ? _translations$login : translate('login'),
638
- loginToCaption: (_translations$loginTo = translations?.loginTo) !== null && _translations$loginTo !== void 0 ? _translations$loginTo : translate('loginTo'),
639
- confirmLabel: (_translations$applyCh = translations?.applyChange) !== null && _translations$applyCh !== void 0 ? _translations$applyCh : translate('applyChange'),
640
- tryAgainLabel: (_translations$tryAgai = translations?.tryAgainLabel) !== null && _translations$tryAgai !== void 0 ? _translations$tryAgai : translate('tryAgainLabel'),
641
- cancelLabel: (_translations$postpon = translations?.postpone) !== null && _translations$postpon !== void 0 ? _translations$postpon : translate('postpone'),
642
- onConfirm: () => {
643
- done();
644
- onApply();
645
- },
646
- onCancel: () => {
647
- done();
648
- onPostpone();
944
+ return updateUser;
945
+ }()
946
+ }, {
947
+ key: "_detectUserChange",
948
+ value: function () {
949
+ var _detectUserChange2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(accessToken) {
950
+ var _this6 = this;
951
+ var windowWasOpen, user, onApply;
952
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
953
+ while (1) switch (_context13.prev = _context13.next) {
954
+ case 0:
955
+ windowWasOpen = this._isLoginWindowOpen;
956
+ _context13.next = 3;
957
+ return this.getUser(accessToken);
958
+ case 3:
959
+ user = _context13.sent;
960
+ onApply = function onApply() {
961
+ _this6.user = user;
962
+ _this6.listeners.trigger(USER_CHANGED_EVENT, user);
963
+ };
964
+ if (!(user && this.user && this.user.id !== user.id)) {
965
+ _context13.next = 14;
966
+ break;
967
+ }
968
+ if (!(!this._canShowDialogs() || this.user.guest || windowWasOpen)) {
969
+ _context13.next = 9;
970
+ break;
971
+ }
972
+ onApply();
973
+ return _context13.abrupt("return");
974
+ case 9:
975
+ if (!user.guest) {
976
+ _context13.next = 12;
977
+ break;
978
+ }
979
+ this._showAuthDialog({
980
+ nonInteractive: true
981
+ });
982
+ return _context13.abrupt("return");
983
+ case 12:
984
+ _context13.next = 14;
985
+ return this._showUserChangedDialog({
986
+ newUser: user,
987
+ onApply: onApply,
988
+ onPostpone: function onPostpone() {
989
+ _this6.listeners.trigger(USER_CHANGE_POSTPONED_EVENT);
990
+ _this6.config.onPostponeChangedUser(_this6.user, user);
991
+ }
992
+ });
993
+ case 14:
994
+ case "end":
995
+ return _context13.stop();
996
+ }
997
+ }, _callee13, this);
998
+ }));
999
+ function _detectUserChange(_x6) {
1000
+ return _detectUserChange2.apply(this, arguments);
649
1001
  }
650
- });
651
- }
652
- _extractErrorMessage(error) {
653
- let logError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
654
- if (!error) {
655
- return null;
656
- }
657
- if (logError) {
658
- // eslint-disable-next-line no-console
659
- console.error('RingUI Auth error', error);
660
- }
661
- try {
662
- // We've got some error from this list
663
- // https://www.jetbrains.com/help/youtrack/devportal/OAuth-2.0-Errors.html
664
- if ('code' in error && error.code && typeof error.code === 'object' && 'code' in error.code && typeof error.code.code === 'string') {
665
- const readableCode = error.code.code.split('_').join(' ');
666
- return `Authorization error: ${readableCode}`;
1002
+ return _detectUserChange;
1003
+ }()
1004
+ }, {
1005
+ key: "_beforeLogout",
1006
+ value: function _beforeLogout(params) {
1007
+ if (this._canShowDialogs()) {
1008
+ this._showAuthDialog(params);
1009
+ return;
667
1010
  }
668
- } catch {
669
- // noop
1011
+ this.logout();
670
1012
  }
671
- return error.toString ? error.toString() : null;
672
- }
673
- _showBackendDownDialog(backendError) {
674
- const {
675
- onBackendDown,
676
- translations
677
- } = this.config;
678
- const REPEAT_TIMEOUT = 5000;
679
- let timerId;
680
- return new Promise((resolve, reject) => {
681
- const done = () => {
1013
+ }, {
1014
+ key: "_showAuthDialog",
1015
+ value: function _showAuthDialog() {
1016
+ var _this$user2,
1017
+ _this7 = this,
1018
+ _this$_authDialogServ,
1019
+ _this$_storage8,
1020
+ _this$_storage9;
1021
+ var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1022
+ nonInteractive = _ref6.nonInteractive,
1023
+ error = _ref6.error,
1024
+ canCancel = _ref6.canCancel,
1025
+ onTryAgain = _ref6.onTryAgain;
1026
+ var _this$config2 = this.config,
1027
+ embeddedLogin = _this$config2.embeddedLogin,
1028
+ onPostponeLogout = _this$config2.onPostponeLogout,
1029
+ translations = _this$config2.translations;
1030
+ var cancelable = ((_this$user2 = this.user) === null || _this$user2 === void 0 ? void 0 : _this$user2.guest) || canCancel;
1031
+ var actualTranslations = translations !== null && translations !== void 0 ? translations : getTranslations();
1032
+ this._createInitDeferred();
1033
+ var closeDialog = function closeDialog() {
682
1034
  /* eslint-disable @typescript-eslint/no-use-before-define */
683
- hide();
684
- window.removeEventListener('online', onCheckAgain);
685
- stopListeningCloseMessage?.();
1035
+ stopTokenListening === null || stopTokenListening === void 0 ? void 0 : stopTokenListening();
1036
+ stopMessageListening === null || stopMessageListening === void 0 ? void 0 : stopMessageListening();
1037
+ hide === null || hide === void 0 ? void 0 : hide();
686
1038
  /* eslint-enable @typescript-eslint/no-use-before-define */
687
- this._storage?.sendMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, Date.now());
688
- clearTimeout(timerId);
689
1039
  };
690
- const stopListeningCloseMessage = this._storage?.onMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, () => {
691
- stopListeningCloseMessage?.();
692
- done();
693
- resolve();
694
- });
695
- const onCheckAgain = async () => {
696
- await this._checkBackendsAreUp();
697
- done();
698
- resolve();
1040
+
1041
+ var onConfirm = function onConfirm() {
1042
+ if (!embeddedLogin) {
1043
+ closeDialog();
1044
+ _this7.logout();
1045
+ return;
1046
+ }
1047
+ _this7._runEmbeddedLogin();
699
1048
  };
700
- const onPostpone = () => {
701
- done();
702
- reject(new Error('Auth(@jetbrains/ring-ui): postponed by user'));
1049
+ var onCancel = function onCancel() {
1050
+ var _this7$_embeddedFlow, _this7$_storage, _this7$user;
1051
+ (_this7$_embeddedFlow = _this7._embeddedFlow) === null || _this7$_embeddedFlow === void 0 ? void 0 : _this7$_embeddedFlow.stop();
1052
+ (_this7$_storage = _this7._storage) === null || _this7$_storage === void 0 ? void 0 : _this7$_storage.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
1053
+ closeDialog();
1054
+ if (!cancelable) {
1055
+ var _this7$_initDeferred, _this7$_initDeferred$;
1056
+ (_this7$_initDeferred = _this7._initDeferred) === null || _this7$_initDeferred === void 0 ? void 0 : (_this7$_initDeferred$ = _this7$_initDeferred.resolve) === null || _this7$_initDeferred$ === void 0 ? void 0 : _this7$_initDeferred$.call(_this7$_initDeferred);
1057
+ _this7.listeners.trigger(LOGOUT_POSTPONED_EVENT);
1058
+ onPostponeLogout();
1059
+ return;
1060
+ }
1061
+ if ((_this7$user = _this7.user) !== null && _this7$user !== void 0 && _this7$user.guest && nonInteractive) {
1062
+ _this7.forceTokenUpdate();
1063
+ } else {
1064
+ var _this7$_initDeferred2, _this7$_initDeferred3;
1065
+ (_this7$_initDeferred2 = _this7._initDeferred) === null || _this7$_initDeferred2 === void 0 ? void 0 : (_this7$_initDeferred3 = _this7$_initDeferred2.resolve) === null || _this7$_initDeferred3 === void 0 ? void 0 : _this7$_initDeferred3.call(_this7$_initDeferred2);
1066
+ }
703
1067
  };
704
- const hide = onBackendDown({
705
- onCheckAgain,
706
- onPostpone,
707
- backendError,
708
- translations: translations !== null && translations !== void 0 ? translations : getTranslationsWithFallback()
709
- });
710
- window.addEventListener('online', onCheckAgain);
711
- function networkWatchdog() {
712
- if (navigator && navigator.onLine) {
713
- onCheckAgain();
1068
+ var onTryAgainClick = /*#__PURE__*/function () {
1069
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1070
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1071
+ while (1) switch (_context14.prev = _context14.next) {
1072
+ case 0:
1073
+ _context14.next = 2;
1074
+ return onTryAgain === null || onTryAgain === void 0 ? void 0 : onTryAgain();
1075
+ case 2:
1076
+ closeDialog();
1077
+ case 3:
1078
+ case "end":
1079
+ return _context14.stop();
1080
+ }
1081
+ }, _callee14);
1082
+ }));
1083
+ return function onTryAgainClick() {
1084
+ return _ref7.apply(this, arguments);
1085
+ };
1086
+ }();
1087
+ var hide = (_this$_authDialogServ = this._authDialogService) === null || _this$_authDialogServ === void 0 ? void 0 : _this$_authDialogServ.call(this, _objectSpread2(_objectSpread2({}, this._service), {}, {
1088
+ loginCaption: actualTranslations.login,
1089
+ loginToCaption: actualTranslations.loginTo,
1090
+ confirmLabel: actualTranslations.login,
1091
+ tryAgainLabel: actualTranslations.tryAgainLabel,
1092
+ cancelLabel: cancelable ? actualTranslations.cancel : actualTranslations.postpone,
1093
+ errorMessage: this._extractErrorMessage(error, true),
1094
+ onConfirm: onConfirm,
1095
+ onCancel: onCancel,
1096
+ onTryAgain: onTryAgain ? onTryAgainClick : undefined
1097
+ }));
1098
+ var stopTokenListening = (_this$_storage8 = this._storage) === null || _this$_storage8 === void 0 ? void 0 : _this$_storage8.onTokenChange(function (token) {
1099
+ if (token) {
1100
+ var _this7$_initDeferred4, _this7$_initDeferred5;
1101
+ closeDialog();
1102
+ (_this7$_initDeferred4 = _this7._initDeferred) === null || _this7$_initDeferred4 === void 0 ? void 0 : (_this7$_initDeferred5 = _this7$_initDeferred4.resolve) === null || _this7$_initDeferred5 === void 0 ? void 0 : _this7$_initDeferred5.call(_this7$_initDeferred4);
714
1103
  }
715
- timerId = window.setTimeout(networkWatchdog, REPEAT_TIMEOUT);
716
- }
717
- timerId = window.setTimeout(networkWatchdog, REPEAT_TIMEOUT);
718
- });
719
- }
720
- /**
721
- * Wipe accessToken and redirect to auth page with required authorization
722
- */
723
- async logout(extraParams) {
724
- const requestParams = {
725
- // eslint-disable-next-line camelcase
726
- request_credentials: 'required',
727
- ...extraParams
728
- };
729
- await this._checkBackendsStatusesIfEnabled();
730
- await this.listeners.trigger('logout');
731
- this._updateDomainUser(null);
732
- await this._storage?.wipeToken();
733
- const authRequest = await this._requestBuilder?.prepareAuthRequest(requestParams);
734
- if (authRequest != null) {
735
- this._redirectCurrentPage(authRequest.url);
736
- }
737
- }
738
- async _runEmbeddedLogin() {
739
- this._storage?.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
740
- try {
741
- this._isLoginWindowOpen = true;
742
- return await this._embeddedFlow?.authorize();
743
- } catch (e) {
744
- throw e;
745
- } finally {
746
- this._isLoginWindowOpen = false;
1104
+ });
1105
+ var stopMessageListening = (_this$_storage9 = this._storage) === null || _this$_storage9 === void 0 ? void 0 : _this$_storage9.onMessage(Auth.CLOSE_WINDOW_MESSAGE, function () {
1106
+ var _this7$_embeddedFlow2;
1107
+ return (_this7$_embeddedFlow2 = _this7._embeddedFlow) === null || _this7$_embeddedFlow2 === void 0 ? void 0 : _this7$_embeddedFlow2.stop();
1108
+ });
747
1109
  }
748
- }
749
- /**
750
- * Wipe accessToken and redirect to auth page to obtain authorization data
751
- * if user is logged in or log her in otherwise
752
- */
753
- async login() {
754
- if (this.config.embeddedLogin) {
755
- await this._runEmbeddedLogin();
756
- return;
1110
+ }, {
1111
+ key: "_showUserChangedDialog",
1112
+ value: function _showUserChangedDialog(_ref8) {
1113
+ var _this8 = this,
1114
+ _this$_authDialogServ2,
1115
+ _translations$youHave,
1116
+ _newUser$name,
1117
+ _newUser$name2,
1118
+ _translations$login,
1119
+ _translations$loginTo,
1120
+ _translations$applyCh,
1121
+ _translations$tryAgai,
1122
+ _translations$postpon;
1123
+ var newUser = _ref8.newUser,
1124
+ onApply = _ref8.onApply,
1125
+ onPostpone = _ref8.onPostpone;
1126
+ var translations = this.config.translations;
1127
+ this._createInitDeferred();
1128
+ var done = function done() {
1129
+ var _this8$_initDeferred, _this8$_initDeferred$;
1130
+ (_this8$_initDeferred = _this8._initDeferred) === null || _this8$_initDeferred === void 0 ? void 0 : (_this8$_initDeferred$ = _this8$_initDeferred.resolve) === null || _this8$_initDeferred$ === void 0 ? void 0 : _this8$_initDeferred$.call(_this8$_initDeferred);
1131
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
1132
+ hide === null || hide === void 0 ? void 0 : hide();
1133
+ };
1134
+ var hide = (_this$_authDialogServ2 = this._authDialogService) === null || _this$_authDialogServ2 === void 0 ? void 0 : _this$_authDialogServ2.call(this, _objectSpread2(_objectSpread2({}, this._service), {}, {
1135
+ title: (_translations$youHave = translations === null || translations === void 0 ? void 0 : translations.youHaveLoggedInAs) !== null && _translations$youHave !== void 0 ? _translations$youHave : translate('youHaveLoggedInAs').replace('%userName%', (_newUser$name = newUser.name) !== null && _newUser$name !== void 0 ? _newUser$name : '').replace('{{userName}}', (_newUser$name2 = newUser.name) !== null && _newUser$name2 !== void 0 ? _newUser$name2 : ''),
1136
+ loginCaption: (_translations$login = translations === null || translations === void 0 ? void 0 : translations.login) !== null && _translations$login !== void 0 ? _translations$login : translate('login'),
1137
+ loginToCaption: (_translations$loginTo = translations === null || translations === void 0 ? void 0 : translations.loginTo) !== null && _translations$loginTo !== void 0 ? _translations$loginTo : translate('loginTo'),
1138
+ confirmLabel: (_translations$applyCh = translations === null || translations === void 0 ? void 0 : translations.applyChange) !== null && _translations$applyCh !== void 0 ? _translations$applyCh : translate('applyChange'),
1139
+ tryAgainLabel: (_translations$tryAgai = translations === null || translations === void 0 ? void 0 : translations.tryAgainLabel) !== null && _translations$tryAgai !== void 0 ? _translations$tryAgai : translate('tryAgainLabel'),
1140
+ cancelLabel: (_translations$postpon = translations === null || translations === void 0 ? void 0 : translations.postpone) !== null && _translations$postpon !== void 0 ? _translations$postpon : translate('postpone'),
1141
+ onConfirm: function onConfirm() {
1142
+ done();
1143
+ onApply();
1144
+ },
1145
+ onCancel: function onCancel() {
1146
+ done();
1147
+ onPostpone();
1148
+ }
1149
+ }));
757
1150
  }
758
- await this._checkBackendsStatusesIfEnabled();
759
- try {
760
- const accessToken = await this._backgroundFlow?.authorize();
761
- const user = await this.getUser(accessToken);
762
- if (user.guest) {
763
- this._beforeLogout();
764
- } else {
765
- this.user = user;
766
- this.listeners.trigger(USER_CHANGED_EVENT, user);
1151
+ }, {
1152
+ key: "_extractErrorMessage",
1153
+ value: function _extractErrorMessage(error) {
1154
+ var logError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1155
+ if (!error) {
1156
+ return null;
767
1157
  }
768
- } catch (e) {
769
- this._beforeLogout();
770
- }
771
- }
772
- async switchUser() {
773
- if (!this.config.embeddedLogin) {
774
- throw new Error('Auth: switchUser only supported for "embeddedLogin" mode');
775
- }
776
- await this._runEmbeddedLogin();
777
- }
778
- /**
779
- * Check if the hash contains an access token.
780
- * If it does, extract the state, compare with
781
- * config, and store the auth response for later use.
782
- *
783
- * @return {Promise} promise that is resolved to restoreLocation URL, or rejected
784
- * @private
785
- */
786
- async _checkForAuthResponse() {
787
- // getAuthResponseURL may throw an exception
788
- const authResponse = this._responseParser.getAuthResponseFromURL();
789
- const {
790
- scope: defaultScope,
791
- defaultExpiresIn,
792
- cleanHash
793
- } = this.config;
794
- if (authResponse && cleanHash) {
795
- this.setHash('');
796
- }
797
- if (!authResponse) {
798
- return undefined;
1158
+ if (logError) {
1159
+ // eslint-disable-next-line no-console
1160
+ console.error('RingUI Auth error', error);
1161
+ }
1162
+ try {
1163
+ // We've got some error from this list
1164
+ // https://www.jetbrains.com/help/youtrack/devportal/OAuth-2.0-Errors.html
1165
+ if ('code' in error && error.code && _typeof(error.code) === 'object' && 'code' in error.code && typeof error.code.code === 'string') {
1166
+ var readableCode = error.code.code.split('_').join(' ');
1167
+ return "Authorization error: ".concat(readableCode);
1168
+ }
1169
+ } catch (_unused) {
1170
+ // noop
1171
+ }
1172
+ return error.toString ? error.toString() : null;
799
1173
  }
800
- const {
801
- state: stateId,
802
- scope,
803
- expiresIn,
804
- accessToken
805
- } = authResponse;
806
- const newState = (await (stateId && this._storage?.getState(stateId))) || {};
807
- const scopes = scope ? scope.split(' ') : newState.scopes || defaultScope || [];
808
- const effectiveExpiresIn = expiresIn ? parseInt(expiresIn, 10) : defaultExpiresIn;
809
- const expires = TokenValidator._epoch() + effectiveExpiresIn;
810
- if (accessToken != null) {
811
- await this._storage?.saveToken({
812
- accessToken,
813
- scopes,
814
- expires,
815
- lifeTime: effectiveExpiresIn
1174
+ }, {
1175
+ key: "_showBackendDownDialog",
1176
+ value: function _showBackendDownDialog(backendError) {
1177
+ var _this9 = this;
1178
+ var _this$config3 = this.config,
1179
+ onBackendDown = _this$config3.onBackendDown,
1180
+ translations = _this$config3.translations;
1181
+ var REPEAT_TIMEOUT = 5000;
1182
+ var timerId;
1183
+ return new Promise(function (resolve, reject) {
1184
+ var _this9$_storage2;
1185
+ var done = function done() {
1186
+ var _this9$_storage;
1187
+ /* eslint-disable @typescript-eslint/no-use-before-define */
1188
+ hide();
1189
+ window.removeEventListener('online', onCheckAgain);
1190
+ stopListeningCloseMessage === null || stopListeningCloseMessage === void 0 ? void 0 : stopListeningCloseMessage();
1191
+ /* eslint-enable @typescript-eslint/no-use-before-define */
1192
+ (_this9$_storage = _this9._storage) === null || _this9$_storage === void 0 ? void 0 : _this9$_storage.sendMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, Date.now());
1193
+ clearTimeout(timerId);
1194
+ };
1195
+ var stopListeningCloseMessage = (_this9$_storage2 = _this9._storage) === null || _this9$_storage2 === void 0 ? void 0 : _this9$_storage2.onMessage(Auth.CLOSE_BACKEND_DOWN_MESSAGE, function () {
1196
+ stopListeningCloseMessage === null || stopListeningCloseMessage === void 0 ? void 0 : stopListeningCloseMessage();
1197
+ done();
1198
+ resolve();
1199
+ });
1200
+ var onCheckAgain = /*#__PURE__*/function () {
1201
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1202
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1203
+ while (1) switch (_context15.prev = _context15.next) {
1204
+ case 0:
1205
+ _context15.next = 2;
1206
+ return _this9._checkBackendsAreUp();
1207
+ case 2:
1208
+ done();
1209
+ resolve();
1210
+ case 4:
1211
+ case "end":
1212
+ return _context15.stop();
1213
+ }
1214
+ }, _callee15);
1215
+ }));
1216
+ return function onCheckAgain() {
1217
+ return _ref9.apply(this, arguments);
1218
+ };
1219
+ }();
1220
+ var onPostpone = function onPostpone() {
1221
+ done();
1222
+ reject(new Error('Auth(@jetbrains/ring-ui): postponed by user'));
1223
+ };
1224
+ var hide = onBackendDown({
1225
+ onCheckAgain: onCheckAgain,
1226
+ onPostpone: onPostpone,
1227
+ backendError: backendError,
1228
+ translations: translations !== null && translations !== void 0 ? translations : getTranslationsWithFallback()
1229
+ });
1230
+ window.addEventListener('online', onCheckAgain);
1231
+ function networkWatchdog() {
1232
+ if (navigator && navigator.onLine) {
1233
+ onCheckAgain();
1234
+ }
1235
+ timerId = window.setTimeout(networkWatchdog, REPEAT_TIMEOUT);
1236
+ }
1237
+ timerId = window.setTimeout(networkWatchdog, REPEAT_TIMEOUT);
816
1238
  });
817
1239
  }
818
- return newState;
819
- }
820
- async _checkForStateRestoration() {
821
- const authResponse = this._responseParser._authResponse;
822
- if (authResponse && this.config.cleanHash) {
823
- this.setHash('');
1240
+ /**
1241
+ * Wipe accessToken and redirect to auth page with required authorization
1242
+ */
1243
+ }, {
1244
+ key: "logout",
1245
+ value: function () {
1246
+ var _logout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(extraParams) {
1247
+ var _this$_storage10, _this$_requestBuilder3;
1248
+ var requestParams, authRequest;
1249
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1250
+ while (1) switch (_context16.prev = _context16.next) {
1251
+ case 0:
1252
+ requestParams = _objectSpread2({
1253
+ // eslint-disable-next-line camelcase
1254
+ request_credentials: 'required'
1255
+ }, extraParams);
1256
+ _context16.next = 3;
1257
+ return this._checkBackendsStatusesIfEnabled();
1258
+ case 3:
1259
+ _context16.next = 5;
1260
+ return this.listeners.trigger('logout');
1261
+ case 5:
1262
+ this._updateDomainUser(null);
1263
+ _context16.next = 8;
1264
+ return (_this$_storage10 = this._storage) === null || _this$_storage10 === void 0 ? void 0 : _this$_storage10.wipeToken();
1265
+ case 8:
1266
+ _context16.next = 10;
1267
+ return (_this$_requestBuilder3 = this._requestBuilder) === null || _this$_requestBuilder3 === void 0 ? void 0 : _this$_requestBuilder3.prepareAuthRequest(requestParams);
1268
+ case 10:
1269
+ authRequest = _context16.sent;
1270
+ if (authRequest != null) {
1271
+ this._redirectCurrentPage(authRequest.url);
1272
+ }
1273
+ case 12:
1274
+ case "end":
1275
+ return _context16.stop();
1276
+ }
1277
+ }, _callee16, this);
1278
+ }));
1279
+ function logout(_x7) {
1280
+ return _logout.apply(this, arguments);
1281
+ }
1282
+ return logout;
1283
+ }()
1284
+ }, {
1285
+ key: "_runEmbeddedLogin",
1286
+ value: function () {
1287
+ var _runEmbeddedLogin2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1288
+ var _this$_storage11;
1289
+ var _this$_embeddedFlow;
1290
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1291
+ while (1) switch (_context17.prev = _context17.next) {
1292
+ case 0:
1293
+ (_this$_storage11 = this._storage) === null || _this$_storage11 === void 0 ? void 0 : _this$_storage11.sendMessage(Auth.CLOSE_WINDOW_MESSAGE, Date.now());
1294
+ _context17.prev = 1;
1295
+ this._isLoginWindowOpen = true;
1296
+ _context17.next = 5;
1297
+ return (_this$_embeddedFlow = this._embeddedFlow) === null || _this$_embeddedFlow === void 0 ? void 0 : _this$_embeddedFlow.authorize();
1298
+ case 5:
1299
+ return _context17.abrupt("return", _context17.sent);
1300
+ case 8:
1301
+ _context17.prev = 8;
1302
+ _context17.t0 = _context17["catch"](1);
1303
+ throw _context17.t0;
1304
+ case 11:
1305
+ _context17.prev = 11;
1306
+ this._isLoginWindowOpen = false;
1307
+ return _context17.finish(11);
1308
+ case 14:
1309
+ case "end":
1310
+ return _context17.stop();
1311
+ }
1312
+ }, _callee17, this, [[1, 8, 11, 14]]);
1313
+ }));
1314
+ function _runEmbeddedLogin() {
1315
+ return _runEmbeddedLogin2.apply(this, arguments);
1316
+ }
1317
+ return _runEmbeddedLogin;
1318
+ }()
1319
+ /**
1320
+ * Wipe accessToken and redirect to auth page to obtain authorization data
1321
+ * if user is logged in or log her in otherwise
1322
+ */
1323
+ }, {
1324
+ key: "login",
1325
+ value: function () {
1326
+ var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1327
+ var _this$_backgroundFlow3, accessToken, _user;
1328
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1329
+ while (1) switch (_context18.prev = _context18.next) {
1330
+ case 0:
1331
+ if (!this.config.embeddedLogin) {
1332
+ _context18.next = 4;
1333
+ break;
1334
+ }
1335
+ _context18.next = 3;
1336
+ return this._runEmbeddedLogin();
1337
+ case 3:
1338
+ return _context18.abrupt("return");
1339
+ case 4:
1340
+ _context18.next = 6;
1341
+ return this._checkBackendsStatusesIfEnabled();
1342
+ case 6:
1343
+ _context18.prev = 6;
1344
+ _context18.next = 9;
1345
+ return (_this$_backgroundFlow3 = this._backgroundFlow) === null || _this$_backgroundFlow3 === void 0 ? void 0 : _this$_backgroundFlow3.authorize();
1346
+ case 9:
1347
+ accessToken = _context18.sent;
1348
+ _context18.next = 12;
1349
+ return this.getUser(accessToken);
1350
+ case 12:
1351
+ _user = _context18.sent;
1352
+ if (_user.guest) {
1353
+ this._beforeLogout();
1354
+ } else {
1355
+ this.user = _user;
1356
+ this.listeners.trigger(USER_CHANGED_EVENT, _user);
1357
+ }
1358
+ _context18.next = 19;
1359
+ break;
1360
+ case 16:
1361
+ _context18.prev = 16;
1362
+ _context18.t0 = _context18["catch"](6);
1363
+ this._beforeLogout();
1364
+ case 19:
1365
+ case "end":
1366
+ return _context18.stop();
1367
+ }
1368
+ }, _callee18, this, [[6, 16]]);
1369
+ }));
1370
+ function login() {
1371
+ return _login.apply(this, arguments);
1372
+ }
1373
+ return login;
1374
+ }()
1375
+ }, {
1376
+ key: "switchUser",
1377
+ value: function () {
1378
+ var _switchUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
1379
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1380
+ while (1) switch (_context19.prev = _context19.next) {
1381
+ case 0:
1382
+ if (this.config.embeddedLogin) {
1383
+ _context19.next = 2;
1384
+ break;
1385
+ }
1386
+ throw new Error('Auth: switchUser only supported for "embeddedLogin" mode');
1387
+ case 2:
1388
+ _context19.next = 4;
1389
+ return this._runEmbeddedLogin();
1390
+ case 4:
1391
+ case "end":
1392
+ return _context19.stop();
1393
+ }
1394
+ }, _callee19, this);
1395
+ }));
1396
+ function switchUser() {
1397
+ return _switchUser.apply(this, arguments);
1398
+ }
1399
+ return switchUser;
1400
+ }()
1401
+ /**
1402
+ * Check if the hash contains an access token.
1403
+ * If it does, extract the state, compare with
1404
+ * config, and store the auth response for later use.
1405
+ *
1406
+ * @return {Promise} promise that is resolved to restoreLocation URL, or rejected
1407
+ * @private
1408
+ */
1409
+ }, {
1410
+ key: "_checkForAuthResponse",
1411
+ value: function () {
1412
+ var _checkForAuthResponse2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1413
+ var _this$_storage12;
1414
+ var authResponse, _this$config4, defaultScope, defaultExpiresIn, cleanHash, stateId, scope, expiresIn, accessToken, newState, scopes, effectiveExpiresIn, expires, _this$_storage13;
1415
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1416
+ while (1) switch (_context20.prev = _context20.next) {
1417
+ case 0:
1418
+ // getAuthResponseURL may throw an exception
1419
+ authResponse = this._responseParser.getAuthResponseFromURL();
1420
+ _this$config4 = this.config, defaultScope = _this$config4.scope, defaultExpiresIn = _this$config4.defaultExpiresIn, cleanHash = _this$config4.cleanHash;
1421
+ if (authResponse && cleanHash) {
1422
+ this.setHash('');
1423
+ }
1424
+ if (authResponse) {
1425
+ _context20.next = 5;
1426
+ break;
1427
+ }
1428
+ return _context20.abrupt("return", undefined);
1429
+ case 5:
1430
+ stateId = authResponse.state, scope = authResponse.scope, expiresIn = authResponse.expiresIn, accessToken = authResponse.accessToken;
1431
+ _context20.next = 8;
1432
+ return stateId && ((_this$_storage12 = this._storage) === null || _this$_storage12 === void 0 ? void 0 : _this$_storage12.getState(stateId));
1433
+ case 8:
1434
+ _context20.t0 = _context20.sent;
1435
+ if (_context20.t0) {
1436
+ _context20.next = 11;
1437
+ break;
1438
+ }
1439
+ _context20.t0 = {};
1440
+ case 11:
1441
+ newState = _context20.t0;
1442
+ scopes = scope ? scope.split(' ') : newState.scopes || defaultScope || [];
1443
+ effectiveExpiresIn = expiresIn ? parseInt(expiresIn, 10) : defaultExpiresIn;
1444
+ expires = TokenValidator._epoch() + effectiveExpiresIn;
1445
+ if (!(accessToken != null)) {
1446
+ _context20.next = 18;
1447
+ break;
1448
+ }
1449
+ _context20.next = 18;
1450
+ return (_this$_storage13 = this._storage) === null || _this$_storage13 === void 0 ? void 0 : _this$_storage13.saveToken({
1451
+ accessToken: accessToken,
1452
+ scopes: scopes,
1453
+ expires: expires,
1454
+ lifeTime: effectiveExpiresIn
1455
+ });
1456
+ case 18:
1457
+ return _context20.abrupt("return", newState);
1458
+ case 19:
1459
+ case "end":
1460
+ return _context20.stop();
1461
+ }
1462
+ }, _callee20, this);
1463
+ }));
1464
+ function _checkForAuthResponse() {
1465
+ return _checkForAuthResponse2.apply(this, arguments);
1466
+ }
1467
+ return _checkForAuthResponse;
1468
+ }()
1469
+ }, {
1470
+ key: "_checkForStateRestoration",
1471
+ value: function () {
1472
+ var _checkForStateRestoration2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1473
+ var _this$_storage14;
1474
+ var authResponse, stateId;
1475
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1476
+ while (1) switch (_context21.prev = _context21.next) {
1477
+ case 0:
1478
+ authResponse = this._responseParser._authResponse;
1479
+ if (authResponse && this.config.cleanHash) {
1480
+ this.setHash('');
1481
+ }
1482
+ stateId = authResponse === null || authResponse === void 0 ? void 0 : authResponse.restoreAuthState;
1483
+ _context21.next = 5;
1484
+ return stateId && ((_this$_storage14 = this._storage) === null || _this$_storage14 === void 0 ? void 0 : _this$_storage14.getState(stateId));
1485
+ case 5:
1486
+ _context21.t0 = _context21.sent;
1487
+ if (_context21.t0) {
1488
+ _context21.next = 8;
1489
+ break;
1490
+ }
1491
+ _context21.t0 = {};
1492
+ case 8:
1493
+ return _context21.abrupt("return", _context21.t0);
1494
+ case 9:
1495
+ case "end":
1496
+ return _context21.stop();
1497
+ }
1498
+ }, _callee21, this);
1499
+ }));
1500
+ function _checkForStateRestoration() {
1501
+ return _checkForStateRestoration2.apply(this, arguments);
1502
+ }
1503
+ return _checkForStateRestoration;
1504
+ }()
1505
+ }, {
1506
+ key: "_checkBackendsAreUp",
1507
+ value: function _checkBackendsAreUp() {
1508
+ var abortCtrl = new AbortController();
1509
+ var backendCheckTimeout = this.config.backendCheckTimeout;
1510
+ return Promise.all([promiseWithTimeout(this.http.fetch('settings/public?fields=id', {
1511
+ signal: abortCtrl.signal
1512
+ }), backendCheckTimeout, {
1513
+ error: new Error('The authorization server is taking too long to respond. Please try again later.'),
1514
+ onTimeout: function onTimeout() {
1515
+ return abortCtrl.abort();
1516
+ }
1517
+ }), this.config.checkBackendIsUp()]).catch(function (err) {
1518
+ if (err instanceof TypeError) {
1519
+ throw new TypeError('Could not connect to the server due to network error. Please check your connection and try again.');
1520
+ }
1521
+ throw err;
1522
+ });
824
1523
  }
825
- const stateId = authResponse?.restoreAuthState;
826
- return (await (stateId && this._storage?.getState(stateId))) || {};
827
- }
828
- _checkBackendsAreUp() {
829
- const abortCtrl = new AbortController();
830
- const {
831
- backendCheckTimeout
832
- } = this.config;
833
- return Promise.all([promiseWithTimeout(this.http.fetch('settings/public?fields=id', {
834
- signal: abortCtrl.signal
835
- }), backendCheckTimeout, {
836
- error: new Error('The authorization server is taking too long to respond. Please try again later.'),
837
- onTimeout: () => abortCtrl.abort()
838
- }), this.config.checkBackendIsUp()]).catch(err => {
839
- if (err instanceof TypeError) {
840
- throw new TypeError('Could not connect to the server due to network error. Please check your connection and try again.');
1524
+ }, {
1525
+ key: "_checkBackendsStatusesIfEnabled",
1526
+ value: function () {
1527
+ var _checkBackendsStatusesIfEnabled2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1528
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1529
+ while (1) switch (_context22.prev = _context22.next) {
1530
+ case 0:
1531
+ if (this.config.enableBackendStatusCheck) {
1532
+ _context22.next = 2;
1533
+ break;
1534
+ }
1535
+ return _context22.abrupt("return");
1536
+ case 2:
1537
+ _context22.prev = 2;
1538
+ _context22.next = 5;
1539
+ return this._checkBackendsAreUp();
1540
+ case 5:
1541
+ _context22.next = 12;
1542
+ break;
1543
+ case 7:
1544
+ _context22.prev = 7;
1545
+ _context22.t0 = _context22["catch"](2);
1546
+ if (!(_context22.t0 instanceof Error)) {
1547
+ _context22.next = 12;
1548
+ break;
1549
+ }
1550
+ _context22.next = 12;
1551
+ return this._showBackendDownDialog(_context22.t0);
1552
+ case 12:
1553
+ case "end":
1554
+ return _context22.stop();
1555
+ }
1556
+ }, _callee22, this, [[2, 7]]);
1557
+ }));
1558
+ function _checkBackendsStatusesIfEnabled() {
1559
+ return _checkBackendsStatusesIfEnabled2.apply(this, arguments);
841
1560
  }
842
- throw err;
843
- });
844
- }
845
- async _checkBackendsStatusesIfEnabled() {
846
- if (!this.config.enableBackendStatusCheck) {
847
- return;
1561
+ return _checkBackendsStatusesIfEnabled;
1562
+ }()
1563
+ /**
1564
+ * Adds preconnect tag to help browser to establish connection to URL.
1565
+ * See https://w3c.github.io/resource-hints/
1566
+ * @param url Url to preconnect to.
1567
+ */
1568
+ }, {
1569
+ key: "setUpPreconnect",
1570
+ value: function setUpPreconnect(url) {
1571
+ var linkNode = document.createElement('link');
1572
+ linkNode.rel = 'preconnect';
1573
+ linkNode.href = url;
1574
+ linkNode.pr = '1.0';
1575
+ linkNode.crossOrigin = 'use-credentials';
1576
+ document.head.appendChild(linkNode);
848
1577
  }
849
- try {
850
- await this._checkBackendsAreUp();
851
- } catch (backendDownErr) {
852
- if (backendDownErr instanceof Error) {
853
- await this._showBackendDownDialog(backendDownErr);
1578
+ /**
1579
+ * Redirects current page to the given URL
1580
+ * @param {string} url
1581
+ * @private
1582
+ */
1583
+ }, {
1584
+ key: "_redirectCurrentPage",
1585
+ value: function _redirectCurrentPage(url) {
1586
+ {
1587
+ window.location.href = fixUrl(url);
854
1588
  }
855
1589
  }
856
- }
857
- /**
858
- * Adds preconnect tag to help browser to establish connection to URL.
859
- * See https://w3c.github.io/resource-hints/
860
- * @param url Url to preconnect to.
861
- */
862
- setUpPreconnect(url) {
863
- const linkNode = document.createElement('link');
864
- linkNode.rel = 'preconnect';
865
- linkNode.href = url;
866
- linkNode.pr = '1.0';
867
- linkNode.crossOrigin = 'use-credentials';
868
- document.head.appendChild(linkNode);
869
- }
870
- /**
871
- * Redirects current page to the given URL
872
- * @param {string} url
873
- * @private
874
- */
875
- _redirectCurrentPage(url) {
876
- {
877
- window.location.href = fixUrl(url);
1590
+ /**
1591
+ * Reloads current page
1592
+ */
1593
+ }, {
1594
+ key: "_reloadCurrentPage",
1595
+ value: function _reloadCurrentPage() {
1596
+ this._redirectCurrentPage(window.location.href);
878
1597
  }
879
- }
880
- /**
881
- * Reloads current page
882
- */
883
- _reloadCurrentPage() {
884
- this._redirectCurrentPage(window.location.href);
885
- }
886
- _canShowDialogs() {
887
- return this.config.embeddedLogin && this._authDialogService;
888
- }
889
- /**
890
- * Sets the location hash
891
- * @param {string} hash
892
- */
893
- setHash(hash) {
894
- if (history.replaceState) {
895
- // NB! History.replaceState is used here, because Firefox saves
896
- // a record in history.
897
- // NB! URL to redirect is formed manually because baseURI could be messed up,
898
- // in which case it's not obvious where redirect will lead.
899
- const cleanedUrl = [window.location.pathname, window.location.search].join('');
900
- const hashIfExist = hash ? `#${hash}` : '';
901
- history.replaceState(undefined, '', `${cleanedUrl}${hashIfExist}`);
902
- } else {
903
- window.location.hash = hash;
1598
+ }, {
1599
+ key: "_canShowDialogs",
1600
+ value: function _canShowDialogs() {
1601
+ return this.config.embeddedLogin && this._authDialogService;
904
1602
  }
905
- }
906
- }
1603
+ /**
1604
+ * Sets the location hash
1605
+ * @param {string} hash
1606
+ */
1607
+ }, {
1608
+ key: "setHash",
1609
+ value: function setHash(hash) {
1610
+ if (history.replaceState) {
1611
+ // NB! History.replaceState is used here, because Firefox saves
1612
+ // a record in history.
1613
+ // NB! URL to redirect is formed manually because baseURI could be messed up,
1614
+ // in which case it's not obvious where redirect will lead.
1615
+ var cleanedUrl = [window.location.pathname, window.location.search].join('');
1616
+ var hashIfExist = hash ? "#".concat(hash) : '';
1617
+ history.replaceState(undefined, '', "".concat(cleanedUrl).concat(hashIfExist));
1618
+ } else {
1619
+ window.location.hash = hash;
1620
+ }
1621
+ }
1622
+ }]);
1623
+ return Auth;
1624
+ }();
1625
+ _defineProperty(Auth, "DEFAULT_CONFIG", DEFAULT_CONFIG);
1626
+ _defineProperty(Auth, "API_PATH", 'api/rest/');
1627
+ _defineProperty(Auth, "API_AUTH_PATH", 'oauth2/auth');
1628
+ _defineProperty(Auth, "API_PROFILE_PATH", 'users/me');
1629
+ _defineProperty(Auth, "CLOSE_BACKEND_DOWN_MESSAGE", 'backend-check-succeeded');
1630
+ _defineProperty(Auth, "CLOSE_WINDOW_MESSAGE", 'close-login-window');
1631
+ _defineProperty(Auth, "shouldRefreshToken", TokenValidator.shouldRefreshToken);
1632
+ _defineProperty(Auth, "storageIsUnavailable", !navigator.cookieEnabled);
907
1633
 
908
1634
  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 };