@shellui/core 0.6.0-beta.1 → 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/components/LoginView.tsx +5 -1
- package/src/features/auth/components/OAuthCallbackView.tsx +12 -3
- 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/authRequestError.spec.ts +11 -0
- package/src/features/auth/utils/authRequestError.ts +6 -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/index.ts +1 -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/i18n/translations/en/common.json +4 -1
- package/src/i18n/translations/en/settings.json +1 -0
- package/src/i18n/translations/fr/common.json +4 -1
- package/src/i18n/translations/fr/settings.json +1 -0
- 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,
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"navigationError": "Navigation error",
|
|
11
11
|
"navigationNotAllowed": "This URL is not configured in the app navigation.",
|
|
12
|
+
"modalContent": "Modal content",
|
|
12
13
|
"sessionLoading": "Restoring your session…",
|
|
13
14
|
"adminShell": {
|
|
14
15
|
"djangoAdmin": "Django admin"
|
|
@@ -23,7 +24,8 @@
|
|
|
23
24
|
"userFallback": "User",
|
|
24
25
|
"goToLoginAriaLabel": "Go to login",
|
|
25
26
|
"openAccountMenuAriaLabel": "Open account menu for {{name}}",
|
|
26
|
-
"loadingAccount": "Loading account…"
|
|
27
|
+
"loadingAccount": "Loading account…",
|
|
28
|
+
"backToHome": "Back to home"
|
|
27
29
|
},
|
|
28
30
|
"loginPage": {
|
|
29
31
|
"welcomeBack": "Welcome back",
|
|
@@ -60,6 +62,7 @@
|
|
|
60
62
|
"couldNotVerifyCapabilities": "Could not verify backend login capabilities.",
|
|
61
63
|
"walletLoginFailed": "Unable to complete Ethereum wallet login.",
|
|
62
64
|
"signInCouldNotContinue": "Sign-in could not continue.",
|
|
65
|
+
"magicLinkStaffDisabled": "Staff accounts can't sign in with an email link. Sign in with your usual sign-in method instead.",
|
|
63
66
|
"magicLinkMethod": "magic link",
|
|
64
67
|
"redirectNotAllowedHint": " Add this origin in shellui-auth (Django admin or shellui-admin → Company → Login redirect URLs), for example: {{origin}}."
|
|
65
68
|
},
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"navigationError": "Erreur de navigation",
|
|
11
11
|
"navigationNotAllowed": "Cette URL n'est pas configurée dans la navigation de l'application.",
|
|
12
|
+
"modalContent": "Contenu de la modale",
|
|
12
13
|
"sessionLoading": "Restauration de votre session…",
|
|
13
14
|
"adminShell": {
|
|
14
15
|
"djangoAdmin": "Admin Django"
|
|
@@ -23,7 +24,8 @@
|
|
|
23
24
|
"userFallback": "Utilisateur",
|
|
24
25
|
"goToLoginAriaLabel": "Aller à la connexion",
|
|
25
26
|
"openAccountMenuAriaLabel": "Ouvrir le menu du compte pour {{name}}",
|
|
26
|
-
"loadingAccount": "Chargement du compte…"
|
|
27
|
+
"loadingAccount": "Chargement du compte…",
|
|
28
|
+
"backToHome": "Retour à l'accueil"
|
|
27
29
|
},
|
|
28
30
|
"loginPage": {
|
|
29
31
|
"welcomeBack": "Bon retour",
|
|
@@ -60,6 +62,7 @@
|
|
|
60
62
|
"couldNotVerifyCapabilities": "Impossible de vérifier les capacités de connexion du backend.",
|
|
61
63
|
"walletLoginFailed": "Impossible de terminer la connexion au portefeuille Ethereum.",
|
|
62
64
|
"signInCouldNotContinue": "La connexion n'a pas pu se poursuivre.",
|
|
65
|
+
"magicLinkStaffDisabled": "Les comptes staff ne peuvent pas se connecter avec un lien envoyé par e-mail. Connectez-vous avec votre méthode de connexion habituelle.",
|
|
63
66
|
"magicLinkMethod": "lien magique",
|
|
64
67
|
"redirectNotAllowedHint": " Ajoutez cette origine dans shellui-auth (admin Django ou shellui-admin → Company → Login redirect URLs), par exemple : {{origin}}."
|
|
65
68
|
},
|
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';
|