@jetbrains/ring-ui 7.0.95 → 7.0.96

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.
@@ -8,6 +8,7 @@ import TokenValidator, { type TokenValidationError, type TokenValidatorConfig }
8
8
  import type AuthDialogService from '../auth-dialog-service/auth-dialog-service';
9
9
  export declare const DEFAULT_EXPIRES_TIMEOUT: number;
10
10
  export declare const DEFAULT_BACKGROUND_TIMEOUT: number;
11
+ export declare const TOKEN_REFRESH_RETRY_DELAYS: number[];
11
12
  export declare const USER_CHANGED_EVENT = "userChange";
12
13
  export declare const DOMAIN_USER_CHANGED_EVENT = "domainUser";
13
14
  export declare const LOGOUT_EVENT = "logout";
@@ -80,6 +81,7 @@ export interface AuthConfig extends TokenValidatorConfig {
80
81
  translations?: AuthTranslations | null | undefined;
81
82
  userParams?: RequestParams | undefined;
82
83
  waitForRedirectTimeout: number;
84
+ tokenRefreshRetryDelays: readonly number[];
83
85
  rpInitiatedLogout: boolean;
84
86
  }
85
87
  type AuthPayloadMap = {
@@ -139,6 +141,7 @@ declare class Auth implements HTTPAuth {
139
141
  _tokenValidator: TokenValidator | null;
140
142
  private _postponed;
141
143
  private _backendCheckPromise;
144
+ private _forceTokenUpdatePromise;
142
145
  private _authDialogService;
143
146
  _domainStorage: AuthStorage<UserChange>;
144
147
  user: AuthUser | null;
@@ -168,9 +171,18 @@ declare class Auth implements HTTPAuth {
168
171
  requestToken(): Promise<string | null>;
169
172
  /**
170
173
  * Get new token in the background or redirect to the login page.
171
- * @return {Promise.<string>}
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
+ * @return {Promise.<string | null>}
172
183
  */
173
184
  forceTokenUpdate(): Promise<string | null>;
185
+ private _doForceTokenUpdate;
174
186
  loadCurrentService(): Promise<void>;
175
187
  getAPIPath(): string;
176
188
  /**
@@ -15,6 +15,7 @@ export const DEFAULT_BACKGROUND_TIMEOUT = 10 * 1000;
15
15
  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
+ export const TOKEN_REFRESH_RETRY_DELAYS = [0, 2000, 5000];
18
19
  export const USER_CHANGED_EVENT = 'userChange';
19
20
  export const DOMAIN_USER_CHANGED_EVENT = 'domainUser';
20
21
  export const LOGOUT_EVENT = 'logout';
@@ -43,6 +44,7 @@ const DEFAULT_CONFIG = {
43
44
  onBackendDown: () => () => { },
44
45
  defaultExpiresIn: DEFAULT_EXPIRES_TIMEOUT,
45
46
  waitForRedirectTimeout: DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT,
47
+ tokenRefreshRetryDelays: TOKEN_REFRESH_RETRY_DELAYS,
46
48
  rpInitiatedLogout: true,
47
49
  translations: null,
48
50
  };
@@ -68,6 +70,7 @@ class Auth {
68
70
  _tokenValidator = null;
69
71
  _postponed = false;
70
72
  _backendCheckPromise = null;
73
+ _forceTokenUpdatePromise = null;
71
74
  _authDialogService = undefined;
72
75
  _domainStorage;
73
76
  user = null;
@@ -208,6 +211,8 @@ class Auth {
208
211
  throw error;
209
212
  }
210
213
  if (this._canShowDialogs()) {
214
+ // eslint-disable-next-line no-console
215
+ console.error('RingUI Auth: Init failure', error);
211
216
  this._showAuthDialog({ nonInteractive: true, error });
212
217
  }
213
218
  }
@@ -221,7 +226,7 @@ class Auth {
221
226
  if (this.user && userID === this.user.id) {
222
227
  return;
223
228
  }
224
- this.forceTokenUpdate();
229
+ this.forceTokenUpdate().catch(noop);
225
230
  });
226
231
  let state;
227
232
  try {
@@ -243,7 +248,7 @@ class Auth {
243
248
  if (message) {
244
249
  const { userID, serviceID } = message;
245
250
  if (serviceID !== this.config.clientId && (!userID || this.user?.id !== userID)) {
246
- this.forceTokenUpdate();
251
+ this.forceTokenUpdate().catch(noop);
247
252
  }
248
253
  }
249
254
  // Access token appears to be valid.
@@ -341,9 +346,26 @@ class Auth {
341
346
  }
342
347
  /**
343
348
  * Get new token in the background or redirect to the login page.
344
- * @return {Promise.<string>}
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
+ * @return {Promise.<string | null>}
345
358
  */
346
- async forceTokenUpdate() {
359
+ forceTokenUpdate() {
360
+ if (this._forceTokenUpdatePromise) {
361
+ return this._forceTokenUpdatePromise;
362
+ }
363
+ this._forceTokenUpdatePromise = this._doForceTokenUpdate().finally(() => {
364
+ this._forceTokenUpdatePromise = null;
365
+ });
366
+ return this._forceTokenUpdatePromise;
367
+ }
368
+ async _doForceTokenUpdate() {
347
369
  try {
348
370
  if (!this._backendCheckPromise) {
349
371
  this._backendCheckPromise = this._checkBackendsStatusesIfEnabled();
@@ -356,44 +378,48 @@ class Auth {
356
378
  finally {
357
379
  this._backendCheckPromise = null;
358
380
  }
359
- try {
360
- return (await this._backgroundFlow?.authorize()) ?? null;
361
- }
362
- catch (error) {
363
- if (!(error instanceof Error)) {
364
- return null;
381
+ let lastError = null;
382
+ for (const delay of this.config.tokenRefreshRetryDelays) {
383
+ if (delay > 0) {
384
+ await new Promise(resolve => setTimeout(resolve, delay));
365
385
  }
366
- if (this._canShowDialogs()) {
367
- return new Promise(resolve => {
368
- const onTryAgain = async () => {
369
- try {
370
- const result = await this._backgroundFlow?.authorize();
371
- resolve(result ?? null);
372
- }
373
- catch (retryError) {
374
- if (retryError instanceof Error) {
375
- this._showAuthDialog({
376
- nonInteractive: true,
377
- error: retryError,
378
- onTryAgain,
379
- });
380
- }
381
- throw retryError;
382
- }
383
- };
384
- this._showAuthDialog({
385
- nonInteractive: true,
386
- error: error,
387
- onTryAgain,
388
- });
389
- });
386
+ try {
387
+ return (await this._backgroundFlow?.authorize()) ?? null;
390
388
  }
391
- const authRequest = await this._requestBuilder?.prepareAuthRequest();
392
- if (authRequest) {
393
- this._redirectCurrentPage(authRequest.url);
389
+ catch (error) {
390
+ lastError = error instanceof Error ? error : new Error(String(error));
394
391
  }
395
- throw new TokenValidator.TokenValidationError(error.message);
396
392
  }
393
+ if (this._canShowDialogs()) {
394
+ return new Promise(resolve => {
395
+ const onTryAgain = async () => {
396
+ try {
397
+ const result = await this._backgroundFlow?.authorize();
398
+ resolve(result ?? null);
399
+ }
400
+ catch (retryError) {
401
+ if (retryError instanceof Error) {
402
+ this._showAuthDialog({
403
+ nonInteractive: true,
404
+ error: retryError,
405
+ onTryAgain,
406
+ });
407
+ }
408
+ throw retryError;
409
+ }
410
+ };
411
+ this._showAuthDialog({
412
+ nonInteractive: true,
413
+ error: lastError,
414
+ onTryAgain,
415
+ });
416
+ });
417
+ }
418
+ const authRequest = await this._requestBuilder?.prepareAuthRequest();
419
+ if (authRequest) {
420
+ this._redirectCurrentPage(authRequest.url);
421
+ }
422
+ throw new TokenValidator.TokenValidationError(lastError?.message ?? 'Failed to refresh token');
397
423
  }
398
424
  async loadCurrentService() {
399
425
  if (this._service.serviceName) {
@@ -471,7 +497,10 @@ class Auth {
471
497
  }
472
498
  _beforeLogout(params) {
473
499
  if (this._canShowDialogs()) {
474
- this._showAuthDialog(params);
500
+ const onTryAgain = async () => {
501
+ await this.forceTokenUpdate();
502
+ };
503
+ this._showAuthDialog({ onTryAgain, ...params });
475
504
  return;
476
505
  }
477
506
  this.logout();
@@ -507,7 +536,7 @@ class Auth {
507
536
  return;
508
537
  }
509
538
  if (this.user?.guest && nonInteractive) {
510
- this.forceTokenUpdate();
539
+ this.forceTokenUpdate().catch(noop);
511
540
  }
512
541
  else {
513
542
  this._initDeferred?.resolve?.();
@@ -688,6 +717,8 @@ class Auth {
688
717
  }
689
718
  }
690
719
  catch (e) {
720
+ // eslint-disable-next-line no-console
721
+ console.error('RingUI Auth: login failure', e);
691
722
  this._beforeLogout();
692
723
  }
693
724
  }
@@ -109,7 +109,7 @@ export default class List<T = unknown> extends Component<ListProps<T>, ListState
109
109
  };
110
110
  componentDidMount(): void;
111
111
  shouldComponentUpdate(nextProps: ListProps<T>, nextState: ListState<T>): boolean;
112
- componentDidUpdate(prevProps: ListProps<T>): void;
112
+ componentDidUpdate(prevProps: ListProps<T>, prevState: ListState<T>): void;
113
113
  componentWillUnmount(): void;
114
114
  scheduleScrollListener: (cb: () => void) => void;
115
115
  static isItemType: typeof isItemType;
@@ -126,11 +126,24 @@ export default class List extends Component {
126
126
  return (Object.keys(nextProps).some(key => !Object.is(nextProps[key], this.props[key])) ||
127
127
  Object.keys(nextState).some(key => nextState[key] !== this.state[key]));
128
128
  }
129
- componentDidUpdate(prevProps) {
129
+ componentDidUpdate(prevProps, prevState) {
130
130
  if (this.virtualizedList && prevProps.data !== this.props.data) {
131
131
  this.virtualizedList.recomputeRowHeights();
132
132
  }
133
133
  const { activeIndex } = this.state;
134
+ if (!this.virtualizedList &&
135
+ !this.props.disableScrollToActive &&
136
+ this.state.needScrollToActive &&
137
+ activeIndex != null &&
138
+ activeIndex !== prevState.activeIndex) {
139
+ const itemId = this.getId(this.props.data[activeIndex]);
140
+ if (itemId) {
141
+ document.getElementById(itemId)?.scrollIntoView?.({
142
+ block: 'center',
143
+ });
144
+ }
145
+ this.setState({ needScrollToActive: false });
146
+ }
134
147
  const isActiveItemRetainedPosition = activeIndex
135
148
  ? prevProps.data[activeIndex]?.key === this.props.data[activeIndex]?.key
136
149
  : false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetbrains/ring-ui",
3
- "version": "7.0.95",
3
+ "version": "7.0.96",
4
4
  "description": "JetBrains UI library",
5
5
  "author": {
6
6
  "name": "JetBrains"
@@ -100,7 +100,7 @@
100
100
  "@csstools/stylelint-no-at-nest-rule": "^5.0.0",
101
101
  "@eslint/compat": "^2.0.2",
102
102
  "@eslint/eslintrc": "^3.3.3",
103
- "@eslint/js": "^9.39.2",
103
+ "@eslint/js": "^10.0.1",
104
104
  "@figma/code-connect": "^1.3.13",
105
105
  "@jetbrains/eslint-config": "^6.0.5",
106
106
  "@jetbrains/logos": "3.0.0-canary.734b213.0",
@@ -128,17 +128,17 @@
128
128
  "@types/react-dom": "^19.2.3",
129
129
  "@types/webpack-env": "^1.18.8",
130
130
  "@vitejs/plugin-react": "^5.1.4",
131
- "@vitest/eslint-plugin": "^1.6.7",
131
+ "@vitest/eslint-plugin": "^1.6.9",
132
132
  "acorn": "^8.15.0",
133
133
  "babel-plugin-require-context-hook": "^1.0.0",
134
- "caniuse-lite": "^1.0.30001769",
134
+ "caniuse-lite": "^1.0.30001770",
135
135
  "chai-as-promised": "^8.0.2",
136
136
  "chai-dom": "^1.12.1",
137
137
  "cheerio": "^1.2.0",
138
138
  "core-js": "^3.48.0",
139
139
  "cpy-cli": "^7.0.0",
140
140
  "dotenv-cli": "^11.0.0",
141
- "eslint": "^9.39.2",
141
+ "eslint": "^10.0.1",
142
142
  "eslint-config-prettier": "^10.1.8",
143
143
  "eslint-import-resolver-exports": "^1.0.0-beta.5",
144
144
  "eslint-import-resolver-typescript": "^4.4.4",
@@ -149,7 +149,7 @@
149
149
  "eslint-plugin-react": "^7.37.5",
150
150
  "eslint-plugin-react-hooks": "^7.0.1",
151
151
  "eslint-plugin-storybook": "^10.2.8",
152
- "eslint-plugin-unicorn": "^62.0.0",
152
+ "eslint-plugin-unicorn": "^63.0.0",
153
153
  "events": "^3.3.0",
154
154
  "glob": "^13.0.3",
155
155
  "globals": "^17.3.0",
@@ -169,13 +169,13 @@
169
169
  "react": "^19.2.4",
170
170
  "react-dom": "^19.2.4",
171
171
  "regenerator-runtime": "^0.14.1",
172
- "rimraf": "^6.1.2",
172
+ "rimraf": "^6.1.3",
173
173
  "rollup": "^4.57.1",
174
174
  "rollup-plugin-clear": "^2.0.7",
175
175
  "storage-mock": "^2.1.0",
176
- "storybook": "10.2.8",
176
+ "storybook": "10.2.13",
177
177
  "stylelint": "^17.3.0",
178
- "stylelint-config-sass-guidelines": "^12.1.0",
178
+ "stylelint-config-sass-guidelines": "^13.0.0",
179
179
  "svg-inline-loader": "^0.8.2",
180
180
  "teamcity-service-messages": "^0.1.14",
181
181
  "terser-webpack-plugin": "^5.3.16",
@@ -223,7 +223,7 @@
223
223
  "change-case": "^4.1.1",
224
224
  "classnames": "^2.5.1",
225
225
  "combokeys": "^3.0.1",
226
- "css-loader": "^7.1.3",
226
+ "css-loader": "^7.1.4",
227
227
  "csstype": "^3.2.1",
228
228
  "date-fns": "^4.1.0",
229
229
  "dequal": "^2.0.3",
@@ -238,7 +238,7 @@
238
238
  "postcss-calc": "^10.1.1",
239
239
  "postcss-flexbugs-fixes": "^5.0.2",
240
240
  "postcss-font-family-system-ui": "^5.0.0",
241
- "postcss-loader": "^8.2.0",
241
+ "postcss-loader": "^8.2.1",
242
242
  "postcss-modules-values-replace": "^4.2.2",
243
243
  "postcss-preset-env": "^11.1.3",
244
244
  "react-compiler-runtime": "^1.0.0",