@jetbrains/ring-ui 7.0.117 → 7.0.119

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.
@@ -0,0 +1,4 @@
1
+ import { type HTMLAttributes } from 'react';
2
+ export interface AlertActionsProps extends HTMLAttributes<HTMLDivElement> {
3
+ }
4
+ export default function AlertActions({ className, ...restProps }: AlertActionsProps): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import classNames from 'classnames';
2
+ import styles from './alert.css';
3
+ export default function AlertActions({ className, ...restProps }) {
4
+ return <div className={classNames(styles.actions, className)} {...restProps}/>;
5
+ }
@@ -0,0 +1,4 @@
1
+ import { type HeadingProps } from '../heading/heading';
2
+ export interface AlertHeadingProps extends HeadingProps {
3
+ }
4
+ export default function AlertHeading({ level, className, ...restProps }: AlertHeadingProps): import("react").JSX.Element;
@@ -0,0 +1,6 @@
1
+ import classNames from 'classnames';
2
+ import Heading, { Levels } from '../heading/heading';
3
+ import styles from './alert.css';
4
+ export default function AlertHeading({ level = Levels.H3, className, ...restProps }) {
5
+ return <Heading level={level} className={classNames(styles.heading, className)} {...restProps}/>;
6
+ }
@@ -8,11 +8,14 @@
8
8
 
9
9
  display: flex;
10
10
  align-items: baseline;
11
+ gap: var(--ring-unit);
11
12
 
12
13
  box-sizing: border-box;
13
- min-height: calc(var(--ring-unit) * 5);
14
+ width: calc(var(--ring-unit) * 45);
15
+ max-width: 100%;
16
+ min-height: calc(var(--ring-unit) * 5.5);
14
17
  margin: var(--ring-unit) auto;
15
- padding: 0 calc(var(--ring-unit) * 2);
18
+ padding: calc(var(--ring-unit) * 1.5);
16
19
 
17
20
  transition:
18
21
  transform var(--ring-alert-animation-duration) var(--ring-alert-animation-easing),
@@ -21,16 +24,18 @@
21
24
  white-space: nowrap;
22
25
  pointer-events: auto;
23
26
 
24
- border-radius: var(--ring-border-radius);
27
+ border-radius: var(--ring-border-radius-large);
25
28
  background-color: var(--ring-popup-background-color);
26
29
  box-shadow: var(--ring-popup-shadow);
27
30
 
28
31
  font-size: var(--ring-font-size);
29
- line-height: calc(var(--ring-unit) * 5);
32
+ line-height: 20px;
30
33
  }
31
34
 
32
35
  .alertInline {
33
36
  margin: var(--ring-unit);
37
+ /* Keep the margin box within narrow parents despite the fixed width */
38
+ max-width: calc(100% - var(--ring-unit) * 2);
34
39
  }
35
40
 
36
41
  .error {
@@ -39,26 +44,42 @@
39
44
  color: var(--ring-error-color);
40
45
  }
41
46
 
42
- .icon {
43
- margin-right: var(--ring-unit);
47
+ .error .icon {
48
+ color: var(--ring-icon-error-color);
49
+ }
50
+
51
+ .success .icon {
52
+ color: var(--ring-icon-success-color);
53
+ }
54
+
55
+ .warning .icon {
56
+ color: var(--ring-icon-warning-color);
57
+ }
58
+
59
+ .info .icon {
60
+ color: var(--ring-link-color);
44
61
  }
45
62
 
46
63
  .caption {
47
64
  overflow: hidden;
48
65
 
49
- max-width: calc(100% - calc(var(--ring-unit) * 5));
66
+ flex-grow: 1;
50
67
 
51
- margin: 12px 0;
68
+ min-width: 0;
52
69
 
53
70
  white-space: normal;
54
71
 
55
72
  color: var(--ring-active-text-color);
73
+ }
56
74
 
57
- line-height: 20px;
75
+ .afterMessage {
76
+ overflow: hidden;
58
77
 
59
- &.withCloseButton {
60
- margin-right: calc(var(--ring-unit) * 5);
61
- }
78
+ min-width: 0;
79
+
80
+ white-space: normal;
81
+
82
+ color: var(--ring-active-text-color);
62
83
  }
63
84
 
64
85
  .badge {
@@ -68,21 +89,17 @@
68
89
  }
69
90
 
70
91
  .loader {
71
- top: 2px;
92
+ top: 3px;
72
93
 
73
- margin-right: var(--ring-unit);
94
+ margin-top: -1px;
74
95
  }
75
96
 
97
+ /* Padding restores a comfortable hit target around the bare 16px glyph
98
+ of the inline icon-only Button; negative margin keeps the glyph where
99
+ the flex layout would put it without the padding */
76
100
  .close.close {
77
- position: absolute;
78
- top: 2px;
79
- right: 0;
80
-
81
- margin: calc(var(--ring-unit) / 2);
101
+ margin: calc(var(--ring-unit) * -1);
82
102
  padding: var(--ring-unit);
83
-
84
- font-size: 0;
85
- line-height: 0;
86
103
  }
87
104
 
88
105
  @keyframes show {
@@ -135,5 +152,29 @@
135
152
 
136
153
  .animationShaking {
137
154
  animation-name: shaking;
155
+
138
156
  animation-duration: 500ms;
139
157
  }
158
+
159
+ /* Doubled to override the Heading component's level-based styles, so the
160
+ level prop stays semantic and doesn't change the alert design: Heading's
161
+ :is(hN) selectors have higher specificity than a single class */
162
+ .heading.heading {
163
+ margin: 0 0 calc(var(--ring-unit) / 2);
164
+
165
+ letter-spacing: normal;
166
+ text-transform: none;
167
+
168
+ color: inherit;
169
+
170
+ font-size: var(--ring-font-size);
171
+ font-weight: var(--ring-font-weight-bold);
172
+ line-height: var(--ring-line-height);
173
+ }
174
+
175
+ .actions {
176
+ display: flex;
177
+ gap: calc(var(--ring-unit)*2);
178
+
179
+ margin: calc(var(--ring-unit) * 2) 0 calc(var(--ring-unit) / 2);
180
+ }
@@ -1,6 +1,8 @@
1
1
  import { PureComponent, type ReactNode } from 'react';
2
2
  import * as React from 'react';
3
3
  import Theme from '../global/theme';
4
+ import AlertHeading from './alert-heading';
5
+ import AlertActions from './alert-actions';
4
6
  export declare const ANIMATION_TIME = 500;
5
7
  /**
6
8
  * @name Alert
@@ -14,8 +16,16 @@ export declare enum AlertType {
14
16
  MESSAGE = "message",
15
17
  SUCCESS = "success",
16
18
  WARNING = "warning",
17
- LOADING = "loading"
19
+ LOADING = "loading",
20
+ INFO = "info"
18
21
  }
22
+ /**
23
+ * Maps the values React renders as nothing (except empty arrays/fragments,
24
+ * which are not worth chasing here) to undefined, so that they neither create
25
+ * the afterMessage wrapper nor distinguish alerts in the alert-service
26
+ * duplicate check
27
+ */
28
+ export declare function normalizeAfterMessage(afterMessage: ReactNode): ReactNode;
19
29
  export interface AlertProps {
20
30
  theme: Theme;
21
31
  timeout: number;
@@ -39,6 +49,7 @@ export interface AlertProps {
39
49
  captionClassName?: string | null | undefined;
40
50
  closeButtonClassName?: string | null | undefined;
41
51
  'data-test'?: string | null | undefined;
52
+ afterMessage?: ReactNode;
42
53
  }
43
54
  interface State {
44
55
  height: number | null;
@@ -74,6 +85,8 @@ export default class Alert extends PureComponent<AlertProps, State> {
74
85
  node?: HTMLDivElement | null;
75
86
  hideTimeout?: number;
76
87
  static Type: typeof AlertType;
88
+ static Heading: typeof AlertHeading;
89
+ static Actions: typeof AlertActions;
77
90
  closeRequest: (event: React.MouseEvent<HTMLElement>) => void;
78
91
  startCloseAnimation: () => void;
79
92
  private _close;
@@ -2,15 +2,18 @@ import { PureComponent } from 'react';
2
2
  import * as React from 'react';
3
3
  import classNames from 'classnames';
4
4
  import exceptionIcon from '@jetbrains/icons/exception';
5
- import checkmarkIcon from '@jetbrains/icons/checkmark';
5
+ import successIcon from '@jetbrains/icons/success';
6
6
  import warningIcon from '@jetbrains/icons/warning';
7
+ import infoIcon from '@jetbrains/icons/info-filled';
7
8
  import closeIcon from '@jetbrains/icons/close';
8
- import Icon, { Color } from '../icon/icon';
9
+ import Icon from '../icon/icon';
9
10
  import Loader from '../loader-inline/loader-inline';
10
11
  import { getRect } from '../global/dom';
11
12
  import dataTests from '../global/data-tests';
12
13
  import Button from '../button/button';
13
14
  import Theme, { ThemeProvider } from '../global/theme';
15
+ import AlertHeading from './alert-heading';
16
+ import AlertActions from './alert-actions';
14
17
  import styles from './alert.css';
15
18
  export const ANIMATION_TIME = 500;
16
19
  /**
@@ -27,6 +30,7 @@ export var AlertType;
27
30
  AlertType["SUCCESS"] = "success";
28
31
  AlertType["WARNING"] = "warning";
29
32
  AlertType["LOADING"] = "loading";
33
+ AlertType["INFO"] = "info";
30
34
  })(AlertType || (AlertType = {}));
31
35
  /**
32
36
  * Lookup table of alert type to icon modifier.
@@ -34,18 +38,19 @@ export var AlertType;
34
38
  */
35
39
  const TypeToIcon = {
36
40
  [AlertType.ERROR]: exceptionIcon,
37
- [AlertType.SUCCESS]: checkmarkIcon,
41
+ [AlertType.SUCCESS]: successIcon,
38
42
  [AlertType.WARNING]: warningIcon,
43
+ [AlertType.INFO]: infoIcon,
39
44
  };
40
45
  /**
41
- * Lookup table of alert type to icon color.
42
- * @type {Object.<AlertType, Icon.Color>}
46
+ * Maps the values React renders as nothing (except empty arrays/fragments,
47
+ * which are not worth chasing here) to undefined, so that they neither create
48
+ * the afterMessage wrapper nor distinguish alerts in the alert-service
49
+ * duplicate check
43
50
  */
44
- const TypeToIconColor = {
45
- [AlertType.ERROR]: Color.RED,
46
- [AlertType.SUCCESS]: Color.GREEN,
47
- [AlertType.WARNING]: Color.WHITE,
48
- };
51
+ export function normalizeAfterMessage(afterMessage) {
52
+ return afterMessage == null || typeof afterMessage === 'boolean' || afterMessage === '' ? undefined : afterMessage;
53
+ }
49
54
  /**
50
55
  * @constructor
51
56
  * @name Alert
@@ -87,6 +92,8 @@ export default class Alert extends PureComponent {
87
92
  node;
88
93
  hideTimeout;
89
94
  static Type = AlertType;
95
+ static Heading = AlertHeading;
96
+ static Actions = AlertActions;
90
97
  closeRequest = (event) => {
91
98
  this.startCloseAnimation();
92
99
  return this.props.onCloseRequest(event);
@@ -106,7 +113,8 @@ export default class Alert extends PureComponent {
106
113
  * @private
107
114
  */
108
115
  _handleCaptionsLinksClick = (evt) => {
109
- if (evt.target instanceof Element && evt.target.matches('a')) {
116
+ const link = evt.target instanceof Element ? evt.target.closest('a') : null;
117
+ if (link != null && evt.currentTarget.contains(link)) {
110
118
  this.closeRequest(evt);
111
119
  }
112
120
  };
@@ -114,13 +122,11 @@ export default class Alert extends PureComponent {
114
122
  * @private
115
123
  */
116
124
  _getCaption() {
117
- return (<span className={classNames(styles.caption, this.props.captionClassName, {
118
- [styles.withCloseButton]: this.props.closeable,
119
- })} onClick={this._handleCaptionsLinksClick}
125
+ return (<div className={classNames(styles.caption, this.props.captionClassName)} onClick={this._handleCaptionsLinksClick}
120
126
  // We only process clicks on `a` elements, see above
121
127
  role='presentation'>
122
128
  {this.props.children}
123
- </span>);
129
+ </div>);
124
130
  }
125
131
  /**
126
132
  * @private
@@ -129,7 +135,7 @@ export default class Alert extends PureComponent {
129
135
  _getIcon() {
130
136
  const glyph = TypeToIcon[this.props.type];
131
137
  if (glyph) {
132
- return <Icon glyph={glyph} className={styles.icon} color={TypeToIconColor[this.props.type] || Color.DEFAULT}/>;
138
+ return <Icon glyph={glyph} className={styles.icon}/>;
133
139
  }
134
140
  if (this.props.type === AlertType.LOADING) {
135
141
  return <Loader className={styles.loader}/>;
@@ -140,21 +146,30 @@ export default class Alert extends PureComponent {
140
146
  this.node = node;
141
147
  };
142
148
  render() {
143
- const { type, inline, isClosing, isShaking, closeButtonClassName, showWithAnimation, className, 'data-test': dataTest, theme, } = this.props;
149
+ const { type, inline, isClosing, isShaking, closeButtonClassName, showWithAnimation, className, 'data-test': dataTest, theme, afterMessage, } = this.props;
144
150
  const classes = classNames(className, {
145
151
  [styles.alert]: true,
146
152
  [styles.animationOpen]: showWithAnimation,
147
- [styles.error]: type === 'error',
153
+ [styles.error]: type === AlertType.ERROR,
154
+ [styles.success]: type === AlertType.SUCCESS,
155
+ [styles.warning]: type === AlertType.WARNING,
156
+ [styles.info]: type === AlertType.INFO,
148
157
  [styles.alertInline]: inline,
149
158
  [styles.animationClosing]: isClosing,
150
159
  [styles.animationShaking]: isShaking,
151
160
  });
152
161
  const height = this.state.height;
153
162
  const style = height ? { marginBottom: -height } : undefined;
163
+ const shownAfterMessage = normalizeAfterMessage(afterMessage);
154
164
  return (<ThemeProvider theme={theme} className={classes} data-test={dataTests('alert', dataTest)} data-test-type={type} style={style} ref={this.storeAlertRef}>
155
165
  {this._getIcon()}
156
166
  {this._getCaption()}
157
- {this.props.closeable ? (<Button icon={closeIcon} className={classNames(styles.close, closeButtonClassName)} data-test='alert-close' aria-label='close alert' onClick={this.closeRequest}/>) : ('')}
167
+ {shownAfterMessage != null && (<div className={styles.afterMessage} onClick={this._handleCaptionsLinksClick}
168
+ // We only process clicks on `a` elements, see above
169
+ role='presentation'>
170
+ {shownAfterMessage}
171
+ </div>)}
172
+ {this.props.closeable ? (<Button icon={closeIcon} className={classNames(styles.close, closeButtonClassName)} data-test='alert-close' aria-label='close alert' onClick={this.closeRequest}/>) : null}
158
173
  </ThemeProvider>);
159
174
  }
160
175
  }
@@ -11,6 +11,7 @@
11
11
  align-items: flex-end;
12
12
  flex-direction: column;
13
13
 
14
+ max-width: calc(100vw - var(--ring-unit) * 4);
14
15
  max-height: calc(100vh - 2 * var(--ring-unit));
15
16
 
16
17
  pointer-events: none;
@@ -24,7 +25,5 @@
24
25
 
25
26
  overflow-y: auto;
26
27
 
27
- min-width: calc(var(--ring-unit) * 30);
28
- max-width: calc(var(--ring-unit) * 50);
29
28
  margin-top: 0;
30
29
  }
@@ -20,7 +20,7 @@ export declare class AlertService {
20
20
  * Renders alert container into virtual node to skip maintaining container
21
21
  */
22
22
  renderAlerts(): void;
23
- findSameAlert(message: ReactNode, type: AlertType | undefined): AlertItem;
23
+ findSameAlert(message: ReactNode, type: AlertType | undefined, afterMessage?: ReactNode): AlertItem | undefined;
24
24
  startAlertClosing(alert: AlertItem): void;
25
25
  remove(key: string | number | null | undefined): void;
26
26
  removeWithoutAnimation(key: string | number): void;
@@ -31,6 +31,7 @@ export declare class AlertService {
31
31
  message(message: ReactNode, timeout?: number): string | number;
32
32
  warning(message: ReactNode, timeout?: number): string | number;
33
33
  successMessage(message: ReactNode, timeout?: number): string | number;
34
+ infoMessage(message: ReactNode, timeout?: number): string | number;
34
35
  loadingMessage(message: ReactNode, timeout?: number): string | number;
35
36
  }
36
37
  declare const alertService: AlertService;
@@ -1,6 +1,6 @@
1
1
  import { createRoot } from 'react-dom/client';
2
2
  import getUID from '../global/get-uid';
3
- import Alert, { ANIMATION_TIME, Container as AlertContainer } from '../alert/alert';
3
+ import Alert, { ANIMATION_TIME, Container as AlertContainer, normalizeAfterMessage, } from '../alert/alert';
4
4
  export const DEFAULT_ALERT_TIMEOUT = 10000; // 10 seconds
5
5
  /**
6
6
  * @name Alert Service
@@ -33,8 +33,9 @@ export class AlertService {
33
33
  renderAlerts() {
34
34
  this.reactRoot.render(this.renderAlertContainer(this.showingAlerts));
35
35
  }
36
- findSameAlert(message, type) {
37
- return this.showingAlerts.filter(it => it.type === type && it.message === message)[0];
36
+ findSameAlert(message, type, afterMessage) {
37
+ const normalizedAfterMessage = normalizeAfterMessage(afterMessage);
38
+ return this.showingAlerts.find(it => it.type === type && it.message === message && normalizeAfterMessage(it.afterMessage) === normalizedAfterMessage);
38
39
  }
39
40
  startAlertClosing(alert) {
40
41
  alert.isClosing = true;
@@ -60,7 +61,7 @@ export class AlertService {
60
61
  }
61
62
  addAlert(message, type, timeout = this.defaultTimeout, options = {}) {
62
63
  const { onCloseRequest, onClose, ...restOptions } = options;
63
- const sameAlert = this.findSameAlert(message, type);
64
+ const sameAlert = this.findSameAlert(message, type, options.afterMessage);
64
65
  if (sameAlert) {
65
66
  sameAlert.isShaking = true;
66
67
  this.renderAlerts();
@@ -102,6 +103,9 @@ export class AlertService {
102
103
  successMessage(message, timeout) {
103
104
  return this.addAlert(message, Alert.Type.SUCCESS, timeout);
104
105
  }
106
+ infoMessage(message, timeout) {
107
+ return this.addAlert(message, Alert.Type.INFO, timeout);
108
+ }
105
109
  loadingMessage(message, timeout) {
106
110
  return this.addAlert(message, Alert.Type.LOADING, timeout);
107
111
  }
@@ -171,18 +171,13 @@ declare class Auth implements HTTPAuth {
171
171
  requestToken(): Promise<string | null>;
172
172
  /**
173
173
  * Get new token in the background or redirect to the login page.
174
- *
175
- * Retries background token refresh with delays from {@link AuthConfig.tokenRefreshRetryDelays}
176
- * with increasing delays before showing the auth dialog.
177
- * This handles transient failures that commonly occur after network
178
- * recovery (e.g. waking from sleep, switching networks) where the first
179
- * iframe-based auth attempt fails but a subsequent one succeeds once
180
- * the Hub session is re-established.
181
- *
182
174
  * @return {Promise.<string | null>}
183
175
  */
184
- forceTokenUpdate(): Promise<string | null>;
176
+ forceTokenUpdate(failedToken?: string | null): Promise<string | null>;
185
177
  private _doForceTokenUpdate;
178
+ private _refreshTokenUnderWebLock;
179
+ private _refreshTokenOrReuseChanged;
180
+ private _handleTokenRefreshFailure;
186
181
  loadCurrentService(): Promise<void>;
187
182
  getAPIPath(): string;
188
183
  /**
@@ -195,6 +190,7 @@ declare class Auth implements HTTPAuth {
195
190
  requestUser(): Promise<any>;
196
191
  updateUser(): Promise<void>;
197
192
  _detectUserChange(accessToken: string): Promise<void>;
193
+ private _getUserWithTokenRefresh;
198
194
  _beforeLogout(params?: AuthDialogParams): void;
199
195
  _showAuthDialog({ nonInteractive, error, canCancel, onTryAgain }?: AuthDialogParams): void;
200
196
  _showUserChangedDialog({ newUser, onApply, onPostpone }: UserChangedDialogParams): void;
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-underscore-dangle,max-lines */
2
2
  import { fixUrl, getAbsoluteBaseURL } from '../global/url';
3
3
  import Listeners from '../global/listeners';
4
- import HTTP from '../http/http';
4
+ import HTTP, { CODE, HTTPError } from '../http/http';
5
5
  import promiseWithTimeout from '../global/promise-with-timeout';
6
6
  import { getTranslations, getTranslationsWithFallback, translate } from '../i18n/i18n';
7
7
  import AuthStorage from './storage';
@@ -16,6 +16,7 @@ const DEFAULT_BACKEND_CHECK_TIMEOUT = 10 * 1000;
16
16
  const BACKGROUND_REDIRECT_TIMEOUT = 20 * 1000;
17
17
  const DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT = 5 * 1000;
18
18
  export const TOKEN_REFRESH_RETRY_DELAYS = [0, 2000, 5000];
19
+ const TOKEN_REFRESH_LOCK_TIMEOUT = 15 * 1000;
19
20
  export const USER_CHANGED_EVENT = 'userChange';
20
21
  export const DOMAIN_USER_CHANGED_EVENT = 'domainUser';
21
22
  export const LOGOUT_EVENT = 'logout';
@@ -346,26 +347,19 @@ class Auth {
346
347
  }
347
348
  /**
348
349
  * Get new token in the background or redirect to the login page.
349
- *
350
- * Retries background token refresh with delays from {@link AuthConfig.tokenRefreshRetryDelays}
351
- * with increasing delays before showing the auth dialog.
352
- * This handles transient failures that commonly occur after network
353
- * recovery (e.g. waking from sleep, switching networks) where the first
354
- * iframe-based auth attempt fails but a subsequent one succeeds once
355
- * the Hub session is re-established.
356
- *
357
350
  * @return {Promise.<string | null>}
358
351
  */
359
- forceTokenUpdate() {
352
+ forceTokenUpdate(failedToken) {
360
353
  if (this._forceTokenUpdatePromise) {
361
354
  return this._forceTokenUpdatePromise;
362
355
  }
363
- this._forceTokenUpdatePromise = this._doForceTokenUpdate().finally(() => {
356
+ this._forceTokenUpdatePromise = this._doForceTokenUpdate(failedToken).finally(() => {
364
357
  this._forceTokenUpdatePromise = null;
365
358
  });
366
359
  return this._forceTokenUpdatePromise;
367
360
  }
368
- async _doForceTokenUpdate() {
361
+ async _doForceTokenUpdate(failedToken) {
362
+ const previousToken = failedToken ?? (await this._storage?.getToken())?.accessToken ?? null;
369
363
  try {
370
364
  if (!this._backendCheckPromise) {
371
365
  this._backendCheckPromise = this._checkBackendsStatusesIfEnabled();
@@ -378,18 +372,50 @@ class Auth {
378
372
  finally {
379
373
  this._backendCheckPromise = null;
380
374
  }
375
+ const attempt = await this._refreshTokenUnderWebLock(previousToken);
376
+ if ('token' in attempt) {
377
+ return attempt.token;
378
+ }
379
+ return this._handleTokenRefreshFailure(attempt.error);
380
+ }
381
+ async _refreshTokenUnderWebLock(previousToken) {
382
+ if (navigator.locks == null) {
383
+ return this._refreshTokenOrReuseChanged(previousToken);
384
+ }
385
+ const lockName = `ring-ui-token-refresh-${this.config.clientId}`;
386
+ try {
387
+ return await navigator.locks.request(lockName, { signal: AbortSignal.timeout(TOKEN_REFRESH_LOCK_TIMEOUT) }, () => this._refreshTokenOrReuseChanged(previousToken));
388
+ }
389
+ catch {
390
+ return this._refreshTokenOrReuseChanged(previousToken);
391
+ }
392
+ }
393
+ async _refreshTokenOrReuseChanged(previousToken) {
394
+ let storedToken = null;
395
+ try {
396
+ storedToken = (await this._tokenValidator?.validateTokenLocally()) ?? null;
397
+ }
398
+ catch {
399
+ // No valid local token — fall through to refresh.
400
+ }
401
+ if (storedToken != null && storedToken !== previousToken) {
402
+ return { token: storedToken };
403
+ }
381
404
  let lastError = null;
382
405
  for (const delay of this.config.tokenRefreshRetryDelays) {
383
406
  if (delay > 0) {
384
407
  await new Promise(resolve => setTimeout(resolve, delay));
385
408
  }
386
409
  try {
387
- return (await this._backgroundFlow?.authorize()) ?? null;
410
+ return { token: (await this._backgroundFlow?.authorize()) ?? null };
388
411
  }
389
412
  catch (error) {
390
413
  lastError = error instanceof Error ? error : new Error(String(error));
391
414
  }
392
415
  }
416
+ return { error: lastError ?? new Error('Failed to refresh token') };
417
+ }
418
+ async _handleTokenRefreshFailure(lastError) {
393
419
  if (this._canShowDialogs()) {
394
420
  return new Promise(resolve => {
395
421
  const onTryAgain = async () => {
@@ -419,7 +445,7 @@ class Auth {
419
445
  if (authRequest) {
420
446
  this._redirectCurrentPage(authRequest.url);
421
447
  }
422
- throw new TokenValidator.TokenValidationError(lastError?.message ?? 'Failed to refresh token');
448
+ throw new TokenValidator.TokenValidationError(lastError.message);
423
449
  }
424
450
  async loadCurrentService() {
425
451
  if (this._service.serviceName) {
@@ -471,7 +497,7 @@ class Auth {
471
497
  }
472
498
  async _detectUserChange(accessToken) {
473
499
  const windowWasOpen = this._isLoginWindowOpen;
474
- const user = await this.getUser(accessToken);
500
+ const user = await this._getUserWithTokenRefresh(accessToken);
475
501
  const onApply = () => {
476
502
  this.user = user;
477
503
  this.listeners.trigger(USER_CHANGED_EVENT, user);
@@ -495,6 +521,21 @@ class Auth {
495
521
  });
496
522
  }
497
523
  }
524
+ async _getUserWithTokenRefresh(accessToken) {
525
+ try {
526
+ return await this.getUser(accessToken);
527
+ }
528
+ catch (error) {
529
+ if (!(error instanceof HTTPError) || error.status !== CODE.UNAUTHORIZED) {
530
+ throw error;
531
+ }
532
+ const attempt = await this._refreshTokenUnderWebLock(accessToken);
533
+ if ('error' in attempt) {
534
+ throw error;
535
+ }
536
+ return this.getUser(attempt.token);
537
+ }
538
+ }
498
539
  _beforeLogout(params) {
499
540
  if (this._canShowDialogs()) {
500
541
  const onTryAgain = async () => {
@@ -20,7 +20,7 @@ export interface RequestParams<RawBody extends boolean = true | false> extends F
20
20
  export type RequestParamsWithoutMethod<RawBody extends boolean = boolean> = Omit<RequestParams<RawBody>, 'method'>;
21
21
  export interface HTTPAuth {
22
22
  requestToken(): Promise<string | null> | string | null;
23
- forceTokenUpdate(): Promise<string | null>;
23
+ forceTokenUpdate(failedToken?: string | null): Promise<string | null>;
24
24
  }
25
25
  export default class HTTP implements Partial<HTTPAuth> {
26
26
  baseUrl: string | null | undefined;
@@ -28,7 +28,7 @@ export default class HTTP implements Partial<HTTPAuth> {
28
28
  fetchConfig: RequestInit;
29
29
  requestToken?: () => Promise<string | null> | string | null;
30
30
  shouldRefreshToken?: (error: string) => boolean;
31
- forceTokenUpdate?: () => Promise<string | null>;
31
+ forceTokenUpdate?: (failedToken?: string | null) => Promise<string | null>;
32
32
  constructor(auth?: HTTPAuth, baseUrl?: string | null | undefined, fetchConfig?: RequestInit);
33
33
  setAuth: (auth: HTTPAuth) => void;
34
34
  setBaseUrl: (baseUrl: string | null | undefined) => void;
@@ -50,7 +50,7 @@ export default class HTTP {
50
50
  setAuth = (auth) => {
51
51
  this.requestToken = () => auth.requestToken();
52
52
  this.shouldRefreshToken = auth.constructor.shouldRefreshToken;
53
- this.forceTokenUpdate = () => auth.forceTokenUpdate();
53
+ this.forceTokenUpdate = failedToken => auth.forceTokenUpdate(failedToken);
54
54
  };
55
55
  setBaseUrl = (baseUrl) => {
56
56
  this.baseUrl = baseUrl;
@@ -141,7 +141,7 @@ export default class HTTP {
141
141
  }
142
142
  const shouldRefreshToken = typeof error.data.error === 'string' ? this.shouldRefreshToken?.(error.data.error) : false;
143
143
  if (shouldRefreshToken) {
144
- token = await this.forceTokenUpdate?.();
144
+ token = await this.forceTokenUpdate?.(token);
145
145
  response = await this._performRequest(url, token, params);
146
146
  return this._processResponse(response);
147
147
  }
@@ -10,6 +10,6 @@ export default class SmartUserCardTooltip extends Component<SmartUserCardTooltip
10
10
  loading: boolean;
11
11
  };
12
12
  loadUser: () => Promise<void>;
13
- renderNoUser: () => "" | import("react").JSX.Element;
13
+ renderNoUser: () => import("react").JSX.Element | "";
14
14
  render(): import("react").JSX.Element;
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetbrains/ring-ui",
3
- "version": "7.0.117",
3
+ "version": "7.0.119",
4
4
  "description": "JetBrains UI library",
5
5
  "author": {
6
6
  "name": "JetBrains"
@@ -99,14 +99,14 @@
99
99
  },
100
100
  "readmeFilename": "README.md",
101
101
  "devDependencies": {
102
- "@babel/cli": "^7.29.7",
102
+ "@babel/cli": "^8.0.1",
103
103
  "@babel/eslint-parser": "^7.29.7",
104
104
  "@csstools/css-parser-algorithms": "^4.0.0",
105
105
  "@csstools/stylelint-no-at-nest-rule": "^5.0.0",
106
106
  "@eslint/compat": "^2.1.0",
107
107
  "@eslint/eslintrc": "^3.3.5",
108
108
  "@eslint/js": "^10.0.1",
109
- "@figma/code-connect": "^1.4.7",
109
+ "@figma/code-connect": "^1.4.8",
110
110
  "@jetbrains/eslint-config": "^6.0.5",
111
111
  "@jetbrains/logos": "3.0.0-canary.734b213.0",
112
112
  "@jetbrains/rollup-css-plugin": "./packages/rollup-css-plugin",
@@ -117,11 +117,11 @@
117
117
  "@rollup/plugin-json": "^6.1.0",
118
118
  "@rollup/plugin-node-resolve": "^16.0.3",
119
119
  "@rollup/plugin-replace": "^6.0.3",
120
- "@storybook/addon-a11y": "10.4.2",
121
- "@storybook/addon-docs": "^10.4.2",
122
- "@storybook/addon-themes": "^10.4.2",
120
+ "@storybook/addon-a11y": "10.4.6",
121
+ "@storybook/addon-docs": "^10.4.6",
122
+ "@storybook/addon-themes": "^10.4.6",
123
123
  "@storybook/csf": "^0.1.13",
124
- "@storybook/react-webpack5": "10.4.2",
124
+ "@storybook/react-webpack5": "10.4.6",
125
125
  "@storybook/test-runner": "^0.24.4",
126
126
  "@testing-library/dom": "^10.4.1",
127
127
  "@testing-library/react": "^16.3.2",
@@ -132,18 +132,18 @@
132
132
  "@types/react": "^19.2.17",
133
133
  "@types/react-dom": "^19.2.3",
134
134
  "@types/webpack-env": "^1.18.8",
135
- "@vitejs/plugin-react": "^6.0.2",
136
- "@vitest/eslint-plugin": "^1.6.19",
137
- "acorn": "^8.16.0",
135
+ "@vitejs/plugin-react": "^6.0.3",
136
+ "@vitest/eslint-plugin": "^1.6.20",
137
+ "acorn": "^8.17.0",
138
138
  "babel-plugin-require-context-hook": "^1.0.0",
139
- "caniuse-lite": "^1.0.30001797",
139
+ "caniuse-lite": "^1.0.30001799",
140
140
  "chai-as-promised": "^8.0.2",
141
141
  "chai-dom": "^1.12.1",
142
142
  "cheerio": "^1.2.0",
143
143
  "core-js": "^3.49.0",
144
144
  "cpy-cli": "^7.0.0",
145
145
  "dotenv-cli": "^11.0.0",
146
- "eslint": "^9.39.2",
146
+ "eslint": "^9.39.4",
147
147
  "eslint-config-prettier": "^10.1.8",
148
148
  "eslint-formatter-jslint-xml": "^9.0.1",
149
149
  "eslint-import-resolver-exports": "^1.0.0-beta.5",
@@ -154,11 +154,11 @@
154
154
  "eslint-plugin-prettier": "^5.5.6",
155
155
  "eslint-plugin-react": "^7.37.5",
156
156
  "eslint-plugin-react-hooks": "^7.1.1",
157
- "eslint-plugin-storybook": "^10.4.2",
158
- "eslint-plugin-unicorn": "^64.0.0",
157
+ "eslint-plugin-storybook": "^10.4.6",
158
+ "eslint-plugin-unicorn": "^70.0.0",
159
159
  "events": "^3.3.0",
160
160
  "glob": "^13.0.6",
161
- "globals": "^17.6.0",
161
+ "globals": "^17.7.0",
162
162
  "html-webpack-plugin": "^5.6.7",
163
163
  "http-server": "^14.1.1",
164
164
  "husky": "^9.1.7",
@@ -166,33 +166,33 @@
166
166
  "jest": "~30.4.2",
167
167
  "jest-environment-jsdom": "^30.4.1",
168
168
  "jest-teamcity": "^1.12.0",
169
- "lint-staged": "^17.0.6",
169
+ "lint-staged": "^17.0.8",
170
170
  "markdown-it": "^14.2.0",
171
171
  "merge-options": "^3.0.4",
172
172
  "pinst": "^3.0.0",
173
- "prettier": "^3.8.3",
173
+ "prettier": "^3.9.4",
174
174
  "raw-loader": "^4.0.2",
175
175
  "react": "^19.2.7",
176
176
  "react-dom": "^19.2.7",
177
177
  "regenerator-runtime": "^0.14.1",
178
178
  "rimraf": "^6.1.3",
179
- "rollup": "^4.61.1",
179
+ "rollup": "^4.62.2",
180
180
  "rollup-plugin-clear": "^2.0.7",
181
181
  "storage-mock": "^2.1.0",
182
- "storybook": "10.4.4",
183
- "stylelint": "^17.13.0",
182
+ "storybook": "10.4.6",
183
+ "stylelint": "^17.14.0",
184
184
  "stylelint-config-sass-guidelines": "^13.0.0",
185
185
  "svg-inline-loader": "^0.8.2",
186
186
  "teamcity-service-messages": "^0.1.14",
187
187
  "terser-webpack-plugin": "^5.6.1",
188
188
  "typed-css-modules": "^0.9.1",
189
189
  "typescript": "~6.0.3",
190
- "typescript-eslint": "^8.60.0",
191
- "vite": "^8.0.16",
192
- "vitest": "^4.1.8",
190
+ "typescript-eslint": "^8.62.1",
191
+ "vite": "^8.1.0",
192
+ "vitest": "^4.1.9",
193
193
  "vitest-teamcity-reporter": "^0.4.1",
194
- "webpack": "^5.107.2",
195
- "webpack-cli": "^7.0.3",
194
+ "webpack": "^5.108.1",
195
+ "webpack-cli": "^7.1.0",
196
196
  "xmlappend": "^1.0.4"
197
197
  },
198
198
  "peerDependencies": {
@@ -216,9 +216,9 @@
216
216
  },
217
217
  "dependencies": {
218
218
  "@babel/core": "^7.29.7",
219
- "@babel/preset-typescript": "^7.29.7",
219
+ "@babel/preset-typescript": "^8.0.1",
220
220
  "@jetbrains/babel-preset-jetbrains": "^2.4.0",
221
- "@jetbrains/icons": "^5.22.0",
221
+ "@jetbrains/icons": "^5.23.0",
222
222
  "@jetbrains/postcss-require-hover": "^0.2.0",
223
223
  "@types/combokeys": "^2.4.9",
224
224
  "@types/element-resize-detector": "^1.1.6",
@@ -227,7 +227,7 @@
227
227
  "babel-loader": "10.1.1",
228
228
  "babel-plugin-react-compiler": "^1.0.0",
229
229
  "babel-plugin-transform-define": "^2.1.4",
230
- "browserslist": "^4.28.2",
230
+ "browserslist": "^4.28.4",
231
231
  "change-case": "^4.1.1",
232
232
  "classnames": "^2.5.1",
233
233
  "combokeys": "^3.0.1",
@@ -238,7 +238,7 @@
238
238
  "element-resize-detector": "^1.2.4",
239
239
  "fastdom": "^1.0.12",
240
240
  "file-loader": "^6.2.0",
241
- "focus-trap": "^8.2.1",
241
+ "focus-trap": "^8.2.2",
242
242
  "highlight.js": "^10.7.2",
243
243
  "just-debounce-it": "^3.2.0",
244
244
  "memoize-one": "^6.0.0",
@@ -247,7 +247,7 @@
247
247
  "postcss-font-family-system-ui": "^5.0.0",
248
248
  "postcss-loader": "^8.2.1",
249
249
  "postcss-modules-values-replace": "^4.2.2",
250
- "postcss-preset-env": "^11.3.0",
250
+ "postcss-preset-env": "^11.3.1",
251
251
  "react-compiler-runtime": "^1.0.0",
252
252
  "react-movable": "^3.4.1",
253
253
  "react-virtualized": "^9.22.6",