@shellui/core 0.6.0 → 0.6.1
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.
- package/README.md +1 -1
- package/package.json +2 -2
- package/schemas/shellui.config.schema.json +15 -0
- package/src/features/auth/AuthProvider.tsx +167 -69
- package/src/features/auth/backends/shellui.spec.ts +115 -0
- package/src/features/auth/backends/shellui.ts +8 -2
- package/src/features/auth/backends/types.ts +9 -1
- package/src/features/auth/hooks/useAuth.tsx +1 -0
- package/src/features/auth/utils/accessTokenRefreshDue.spec.ts +15 -0
- package/src/features/auth/utils/accessTokenRefreshDue.ts +8 -0
- package/src/features/auth/utils/desktopAuthCallback.spec.ts +68 -0
- package/src/features/auth/utils/desktopAuthCallback.ts +126 -0
- package/src/features/auth/utils/desktopSignIn.spec.ts +162 -0
- package/src/features/auth/utils/desktopSignIn.ts +445 -0
- package/src/features/auth/utils/frameSessionRefresher.spec.ts +23 -0
- package/src/features/auth/utils/frameSessionRefresher.ts +21 -0
- package/src/features/auth/utils/pkce.spec.ts +36 -0
- package/src/features/auth/utils/pkce.ts +38 -0
- package/src/features/config/types.ts +17 -0
- package/src/features/settings/SettingsProvider.tsx +83 -31
- package/src/index.ts +6 -0
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
type ReactNode,
|
|
9
9
|
} from 'react';
|
|
10
10
|
import {
|
|
11
|
+
bindVisibleResume,
|
|
12
|
+
deliverSessionHandoff,
|
|
11
13
|
getLogger,
|
|
12
14
|
shellui,
|
|
13
15
|
type ShellUIMessage,
|
|
@@ -29,6 +31,7 @@ import {
|
|
|
29
31
|
toSettingsUser,
|
|
30
32
|
} from './utils';
|
|
31
33
|
import { unregisterServiceWorker } from '../../service-worker/register';
|
|
34
|
+
import { refreshFrameAccessTokenIfNeeded } from '../auth/utils/frameSessionRefresher';
|
|
32
35
|
|
|
33
36
|
const logger = getLogger('shellcore');
|
|
34
37
|
|
|
@@ -242,15 +245,38 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
242
245
|
[config, isTrustedFrameForAuthTokenCallback],
|
|
243
246
|
);
|
|
244
247
|
|
|
248
|
+
const applyHandoffToken = useCallback((token: string | null | undefined) => {
|
|
249
|
+
if (token !== undefined) accessTokenRef.current = token;
|
|
250
|
+
}, []);
|
|
251
|
+
|
|
252
|
+
const handoffSettingsToIframes = useCallback(() => {
|
|
253
|
+
const base = settingsRef.current ?? defaultSettings;
|
|
254
|
+
return deliverSessionHandoff(() => propagateSettingsToIframes(base));
|
|
255
|
+
}, [propagateSettingsToIframes]);
|
|
256
|
+
|
|
245
257
|
// When the shell rotates the JWT, `authUser` often does not change, so the user-sync effect
|
|
246
258
|
// above skips — still push `SHELLUI_SETTINGS` so trusted iframes get the new `accessToken`.
|
|
259
|
+
// The follow-up turn covers an app that subscribes after the first post.
|
|
247
260
|
const accessTokenForChildren = session?.accessToken ?? null;
|
|
248
261
|
useEffect(() => {
|
|
249
262
|
if (typeof window === 'undefined' || window.parent !== window || !accessTokenForChildren) {
|
|
250
263
|
return;
|
|
251
264
|
}
|
|
252
|
-
|
|
253
|
-
}, [accessTokenForChildren,
|
|
265
|
+
return handoffSettingsToIframes();
|
|
266
|
+
}, [accessTokenForChildren, handoffSettingsToIframes]);
|
|
267
|
+
|
|
268
|
+
// Background tabs throttle the refresh interval. On show, refresh if due and
|
|
269
|
+
// re-send the session even when the token string did not change.
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
if (typeof window === 'undefined' || window.parent !== window) return;
|
|
272
|
+
return bindVisibleResume(() => {
|
|
273
|
+
void (async () => {
|
|
274
|
+
const token = await refreshFrameAccessTokenIfNeeded();
|
|
275
|
+
applyHandoffToken(token);
|
|
276
|
+
handoffSettingsToIframes();
|
|
277
|
+
})();
|
|
278
|
+
});
|
|
279
|
+
}, [applyHandoffToken, handoffSettingsToIframes]);
|
|
254
280
|
|
|
255
281
|
// Keep load/sync helpers stable across access-token rotation (refresh after preference sync).
|
|
256
282
|
const loadUserPreferencesRef = useRef(loadUserPreferences);
|
|
@@ -449,35 +475,50 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
449
475
|
const cleanupSettingsRequested = shellui.addMessageListener(
|
|
450
476
|
'SHELLUI_SETTINGS_REQUESTED',
|
|
451
477
|
(message: ShellUIMessage) => {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
const
|
|
459
|
-
.
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
478
|
+
void (async () => {
|
|
479
|
+
// An app that asks while the access token is expired must get a fresh one,
|
|
480
|
+
// not the JWT that died while the tab was hidden.
|
|
481
|
+
const token = await refreshFrameAccessTokenIfNeeded();
|
|
482
|
+
applyHandoffToken(token);
|
|
483
|
+
|
|
484
|
+
const send = () => {
|
|
485
|
+
const currentSettings = settingsRef.current ?? defaultSettings;
|
|
486
|
+
const requestingPath = (message.from ?? []).filter(Boolean);
|
|
487
|
+
|
|
488
|
+
if (requestingPath.length > 0) {
|
|
489
|
+
const [firstHopIframeUuid] = requestingPath;
|
|
490
|
+
const frame = shellui.frameRegistry
|
|
491
|
+
.getAllIframes()
|
|
492
|
+
.find(([uuid]) => uuid === firstHopIframeUuid)?.[1];
|
|
493
|
+
const lang = currentSettings.language?.code || 'en';
|
|
494
|
+
const includeAuthAccessToken = frame
|
|
495
|
+
? isTrustedFrameForAuthTokenCallback(frame.src ?? '')
|
|
496
|
+
: false;
|
|
497
|
+
const settingsToPropagate = buildSettingsForPropagation(
|
|
498
|
+
currentSettings,
|
|
499
|
+
config,
|
|
500
|
+
lang,
|
|
501
|
+
{
|
|
502
|
+
includeAuthAccessToken,
|
|
503
|
+
accessToken: accessTokenRef.current,
|
|
504
|
+
includeLayoutChrome: isMainLayoutFrame(frame),
|
|
505
|
+
},
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
// Route through the full parent -> child -> ... -> requester path so deep descendants
|
|
509
|
+
// receive settings even when they are nested more than one level under root.
|
|
510
|
+
shellui.sendMessage({
|
|
511
|
+
type: 'SHELLUI_SETTINGS',
|
|
512
|
+
payload: { settings: settingsToPropagate },
|
|
513
|
+
to: requestingPath,
|
|
514
|
+
});
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
propagateSettingsToIframes(currentSettings);
|
|
518
|
+
};
|
|
470
519
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
shellui.sendMessage({
|
|
474
|
-
type: 'SHELLUI_SETTINGS',
|
|
475
|
-
payload: { settings: settingsToPropagate },
|
|
476
|
-
to: requestingPath,
|
|
477
|
-
});
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
propagateSettingsToIframes(currentSettings);
|
|
520
|
+
deliverSessionHandoff(send);
|
|
521
|
+
})();
|
|
481
522
|
},
|
|
482
523
|
);
|
|
483
524
|
|
|
@@ -518,7 +559,17 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
518
559
|
.find(([, iframe]) => iframe?.contentWindow === source);
|
|
519
560
|
if (!match) return;
|
|
520
561
|
const [iframeUuid, iframe] = match;
|
|
521
|
-
|
|
562
|
+
void (async () => {
|
|
563
|
+
const token = await refreshFrameAccessTokenIfNeeded();
|
|
564
|
+
applyHandoffToken(token);
|
|
565
|
+
deliverSessionHandoff(() =>
|
|
566
|
+
pushSettingsToFrame(
|
|
567
|
+
iframeUuid,
|
|
568
|
+
iframe?.src ?? '',
|
|
569
|
+
settingsRef.current ?? defaultSettings,
|
|
570
|
+
),
|
|
571
|
+
);
|
|
572
|
+
})();
|
|
522
573
|
},
|
|
523
574
|
);
|
|
524
575
|
|
|
@@ -531,6 +582,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
531
582
|
}, [
|
|
532
583
|
config,
|
|
533
584
|
isTrustedFrameForAuthTokenCallback,
|
|
585
|
+
applyHandoffToken,
|
|
534
586
|
propagateSettingsToIframes,
|
|
535
587
|
pushSettingsToFrame,
|
|
536
588
|
schedulePropagateSettingsToIframes,
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,7 @@ export type {
|
|
|
26
26
|
LayoutType,
|
|
27
27
|
BackendType,
|
|
28
28
|
BackendConfig,
|
|
29
|
+
AuthConfig,
|
|
29
30
|
AdministrationConfig,
|
|
30
31
|
StorageConfig,
|
|
31
32
|
HostingConfig,
|
|
@@ -102,6 +103,11 @@ export {
|
|
|
102
103
|
} from './features/theme/themes.js';
|
|
103
104
|
export { useConfig } from './features/config/useConfig.js';
|
|
104
105
|
export { useAuth } from './features/auth/hooks/useAuth.js';
|
|
106
|
+
export {
|
|
107
|
+
configureDesktopAuth,
|
|
108
|
+
handleDesktopAuthCallback,
|
|
109
|
+
} from './features/auth/utils/desktopSignIn.js';
|
|
110
|
+
export type { DesktopAuthAdapters } from './features/auth/utils/desktopSignIn.js';
|
|
105
111
|
export { AuthProvider } from './features/auth/AuthProvider.js';
|
|
106
112
|
export { ConfigProvider } from './features/config/ConfigProvider.js';
|
|
107
113
|
export type { ConfigContextValue, ConfigProviderProps } from './features/config/ConfigProvider.js';
|