@jetbrains/ring-ui 5.0.35 → 5.0.37

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