@jetbrains/ring-ui 7.0.117 → 7.0.118
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.
|
@@ -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
|
|
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.
|
|
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;
|
package/components/http/http.js
CHANGED
|
@@ -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 =
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jetbrains/ring-ui",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.118",
|
|
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": "^
|
|
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.
|
|
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.
|
|
121
|
-
"@storybook/addon-docs": "^10.4.
|
|
122
|
-
"@storybook/addon-themes": "^10.4.
|
|
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.
|
|
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",
|
|
@@ -133,17 +133,17 @@
|
|
|
133
133
|
"@types/react-dom": "^19.2.3",
|
|
134
134
|
"@types/webpack-env": "^1.18.8",
|
|
135
135
|
"@vitejs/plugin-react": "^6.0.2",
|
|
136
|
-
"@vitest/eslint-plugin": "^1.6.
|
|
137
|
-
"acorn": "^8.
|
|
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.
|
|
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.
|
|
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,8 +154,8 @@
|
|
|
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.
|
|
158
|
-
"eslint-plugin-unicorn": "^
|
|
157
|
+
"eslint-plugin-storybook": "^10.4.6",
|
|
158
|
+
"eslint-plugin-unicorn": "^68.0.0",
|
|
159
159
|
"events": "^3.3.0",
|
|
160
160
|
"glob": "^13.0.6",
|
|
161
161
|
"globals": "^17.6.0",
|
|
@@ -166,20 +166,20 @@
|
|
|
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.
|
|
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.
|
|
173
|
+
"prettier": "^3.8.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.
|
|
179
|
+
"rollup": "^4.62.2",
|
|
180
180
|
"rollup-plugin-clear": "^2.0.7",
|
|
181
181
|
"storage-mock": "^2.1.0",
|
|
182
|
-
"storybook": "10.4.
|
|
182
|
+
"storybook": "10.4.6",
|
|
183
183
|
"stylelint": "^17.13.0",
|
|
184
184
|
"stylelint-config-sass-guidelines": "^13.0.0",
|
|
185
185
|
"svg-inline-loader": "^0.8.2",
|
|
@@ -187,9 +187,9 @@
|
|
|
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.
|
|
190
|
+
"typescript-eslint": "^8.61.1",
|
|
191
191
|
"vite": "^8.0.16",
|
|
192
|
-
"vitest": "^4.1.
|
|
192
|
+
"vitest": "^4.1.9",
|
|
193
193
|
"vitest-teamcity-reporter": "^0.4.1",
|
|
194
194
|
"webpack": "^5.107.2",
|
|
195
195
|
"webpack-cli": "^7.0.3",
|
|
@@ -216,9 +216,9 @@
|
|
|
216
216
|
},
|
|
217
217
|
"dependencies": {
|
|
218
218
|
"@babel/core": "^7.29.7",
|
|
219
|
-
"@babel/preset-typescript": "^
|
|
219
|
+
"@babel/preset-typescript": "^8.0.1",
|
|
220
220
|
"@jetbrains/babel-preset-jetbrains": "^2.4.0",
|
|
221
|
-
"@jetbrains/icons": "^5.
|
|
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",
|
|
@@ -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.
|
|
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",
|