@shellui/core 0.5.0-beta.3 → 0.5.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 +5 -5
- package/package.json +3 -2
- package/schemas/shellui.config.schema.json +98 -33
- package/src/app.tsx +10 -4
- package/src/components/ContentView.tsx +3 -5
- package/src/components/contentIframeSandbox.spec.ts +25 -0
- package/src/components/contentIframeSandbox.ts +43 -0
- package/src/components/ui/dialog.tsx +5 -1
- package/src/components/ui/dropdown-menu.tsx +39 -4
- package/src/components/ui/sheet.tsx +1 -1
- package/src/components/ui/sidebar.tsx +3 -2
- package/src/components/ui/tabs.tsx +52 -0
- package/src/constants/urls.ts +1 -0
- package/src/features/auth/AuthProvider.tsx +169 -35
- package/src/features/auth/backends/index.ts +2 -0
- package/src/features/auth/backends/shellui.ts +43 -35
- package/src/features/auth/backends/supabase.ts +1 -0
- package/src/features/auth/backends/types.ts +5 -0
- package/src/features/auth/components/LoginView.tsx +5 -1
- package/src/features/auth/components/OAuthCallbackView.tsx +115 -44
- package/src/features/auth/constants/oauth.ts +2 -0
- package/src/features/auth/hooks/useAuth.tsx +4 -0
- package/src/features/auth/utils/authSessionPersistence.spec.ts +93 -0
- package/src/features/auth/utils/authSessionPersistence.ts +138 -0
- package/src/features/auth/utils/authStorageKeys.ts +8 -0
- package/src/features/auth/utils/bffAuthClient.ts +107 -0
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +22 -0
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +17 -0
- package/src/features/auth/utils/buildSessionFromTokenPayload.spec.ts +29 -0
- package/src/features/auth/utils/buildSessionFromTokenPayload.ts +24 -0
- package/src/features/auth/utils/index.ts +18 -3
- package/src/features/auth/utils/isBffAuthEnabled.ts +12 -0
- package/src/features/chromeActions/ChromeActionIcons.tsx +261 -0
- package/src/features/chromeActions/ChromeActionsDemoView.tsx +149 -0
- package/src/features/chromeActions/ChromeActionsHost.tsx +1511 -0
- package/src/features/chromeActions/ChromeActionsProvider.tsx +141 -0
- package/src/features/chromeActions/chromeActionsStore.spec.ts +61 -0
- package/src/features/chromeActions/chromeActionsStore.ts +77 -0
- package/src/features/chromeActions/computeActionInsets.spec.ts +360 -0
- package/src/features/chromeActions/computeActionInsets.ts +326 -0
- package/src/features/chromeActions/index.ts +26 -0
- package/src/features/chromeActions/resolveUuidForRemoveIframe.spec.ts +49 -0
- package/src/features/config/types.ts +49 -2
- package/src/features/layouts/AppLayout.tsx +4 -4
- package/src/features/layouts/OverlayShell.tsx +60 -12
- package/src/features/layouts/app-bar-inset/AppBarInsetLayout.tsx +1 -1
- package/src/features/layouts/appbar/AppBarLayout.tsx +194 -89
- package/src/features/layouts/chrome/DesktopChrome.tsx +17 -3
- package/src/features/layouts/chrome/InsetMobileRadiusOverlay.tsx +18 -0
- package/src/features/layouts/chrome/index.ts +8 -0
- package/src/features/layouts/chrome/runtime.ts +73 -0
- package/src/features/layouts/chrome/useScrollHideChrome.ts +210 -0
- package/src/features/layouts/floating/FloatingBottomDock.tsx +410 -0
- package/src/features/layouts/floating/FloatingLayout.tsx +31 -21
- package/src/features/layouts/floating/FloatingStatusScrim.tsx +36 -0
- package/src/features/layouts/floating/computeFloatingInsets.spec.ts +5 -5
- package/src/features/layouts/floating/computeFloatingInsets.ts +64 -12
- package/src/features/layouts/floating/isShellOwnedPath.spec.ts +2 -0
- package/src/features/layouts/floating/isShellOwnedPath.ts +1 -0
- package/src/features/layouts/floating/layoutChromeStore.spec.ts +138 -0
- package/src/features/layouts/floating/layoutChromeStore.ts +169 -6
- package/src/features/layouts/floating/useFloatingChrome.ts +20 -30
- package/src/features/layouts/sidebar/SidebarLayout.tsx +87 -31
- package/src/features/layouts/sidebar-inset/SidebarInsetLayout.tsx +1 -1
- package/src/features/layouts/windows/WindowsLayout.tsx +240 -110
- package/src/features/messaging/MessagingSecurityBootstrap.tsx +19 -0
- package/src/features/messaging/deriveAllowedMessageOrigins.spec.ts +86 -0
- package/src/features/messaging/deriveAllowedMessageOrigins.ts +74 -0
- package/src/features/modal/ModalContext.spec.ts +13 -2
- package/src/features/modal/validateAndNormalizeUrl.ts +9 -23
- package/src/features/overlays/ResponsiveModal.tsx +201 -21
- package/src/features/overlays/overlaySize.spec.ts +18 -0
- package/src/features/overlays/overlaySize.ts +89 -0
- package/src/features/security/trustedFrames.spec.ts +129 -0
- package/src/features/security/trustedFrames.ts +79 -0
- package/src/features/security/urlAllowlist.spec.ts +99 -0
- package/src/features/security/urlAllowlist.ts +122 -0
- package/src/features/settings/SettingsProvider.tsx +38 -54
- package/src/features/settings/components/Develop.tsx +2 -0
- package/src/features/settings/components/develop/ChromeActionsTestButtons.tsx +63 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +23 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +7 -0
- package/src/features/storage/StorageBridge.spec.ts +82 -0
- package/src/features/storage/StorageBridge.tsx +25 -3
- package/src/features/storage/StoragePickerContext.tsx +3 -4
- package/src/features/storage/uploads/uploadQueue.spec.ts +56 -1
- package/src/features/storage/uploads/uploadQueue.ts +44 -6
- package/src/features/theme/applyTheme.ts +23 -5
- package/src/hooks/use-mobile.tsx +21 -7
- package/src/i18n/translations/en/settings.json +9 -0
- package/src/i18n/translations/fr/settings.json +9 -0
- package/src/index.css +264 -124
- package/src/index.html +6 -4
- package/src/index.ts +8 -0
- package/src/routes/components/NavigationItemRoute.tsx +30 -15
- package/src/routes/components/RouteFallback.tsx +15 -0
- package/src/routes/routes.tsx +14 -0
- package/src/routes/utils/navigationRouteAccess.spec.ts +85 -0
- package/src/routes/utils/navigationRouteAccess.ts +43 -0
- package/src/features/auth/utils/clearStoredAuthSession.spec.ts +0 -23
- package/src/features/auth/utils/clearStoredAuthSession.ts +0 -10
- package/src/features/auth/utils/persistAuthSession.spec.ts +0 -35
- package/src/features/auth/utils/persistAuthSession.ts +0 -12
- package/src/features/auth/utils/readStoredAuthSession.spec.ts +0 -34
- package/src/features/auth/utils/readStoredAuthSession.ts +0 -14
- package/src/features/layouts/floating/FloatingFadeMask.tsx +0 -22
- package/src/features/layouts/floating/FloatingTabBar.tsx +0 -437
- package/src/features/layouts/floating/FloatingTabIndicator.tsx +0 -216
|
@@ -8,10 +8,8 @@ import {
|
|
|
8
8
|
} from '@shellui/sdk';
|
|
9
9
|
import { SettingsContext } from './SettingsContext';
|
|
10
10
|
import { useConfig } from '../config/useConfig';
|
|
11
|
-
import type { NavigationItem } from '../config/types';
|
|
12
11
|
import { useAuth } from '../auth/hooks/useAuth';
|
|
13
|
-
import {
|
|
14
|
-
import { isFrameForAppUrl } from '../layouts/utils';
|
|
12
|
+
import { isTrustedFrameForAuthToken } from '../security/trustedFrames';
|
|
15
13
|
import { isMainLayoutFrame } from '../layouts/floating/layoutChromeStore';
|
|
16
14
|
import { defaultTheme } from '../theme/themes';
|
|
17
15
|
import {
|
|
@@ -30,9 +28,6 @@ const STORAGE_KEY = 'shellui:settings';
|
|
|
30
28
|
const AUTH_SESSION_STORAGE_KEY = 'shellui.auth.session';
|
|
31
29
|
const AUTH_LAST_USED_LOGIN_STORAGE_KEY = 'shellui.auth.last_used_login';
|
|
32
30
|
|
|
33
|
-
const isFrameForNavigationItem = (frameSrc: string, itemUrl: string): boolean =>
|
|
34
|
-
isFrameForAppUrl(frameSrc, itemUrl);
|
|
35
|
-
|
|
36
31
|
const stripSensitiveUserFields = (settings: Settings): Settings => {
|
|
37
32
|
return {
|
|
38
33
|
...settings,
|
|
@@ -170,40 +165,9 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
170
165
|
return defaultSettings;
|
|
171
166
|
});
|
|
172
167
|
|
|
173
|
-
const
|
|
174
|
-
() =>
|
|
175
|
-
|
|
176
|
-
'title' in item && 'items' in item ? item.items : [item],
|
|
177
|
-
) ?? [],
|
|
178
|
-
[config?.navigation],
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
const isTrustedFrameForAuthToken = useCallback(
|
|
182
|
-
(frameSrc: string): boolean => {
|
|
183
|
-
if (isAdminFrame(frameSrc, config)) {
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
// Trust admin-panel iframe apps (navigation + storage files explorer / viewer modals).
|
|
187
|
-
const adminNavItems = config?.administration?.navigation ?? [];
|
|
188
|
-
if (
|
|
189
|
-
adminNavItems.some(
|
|
190
|
-
(item) =>
|
|
191
|
-
item.openIn !== 'external' &&
|
|
192
|
-
Boolean(item.url?.trim()) &&
|
|
193
|
-
isFrameForNavigationItem(frameSrc, item.url),
|
|
194
|
-
)
|
|
195
|
-
) {
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
const filesUrl = config?.storage?.filesUrl?.trim();
|
|
199
|
-
if (filesUrl && isFrameForNavigationItem(frameSrc, filesUrl)) {
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
return navigationItems.some(
|
|
203
|
-
(item) => item.safeForAuthToken !== false && isFrameForNavigationItem(frameSrc, item.url),
|
|
204
|
-
);
|
|
205
|
-
},
|
|
206
|
-
[config, navigationItems],
|
|
168
|
+
const isTrustedFrameForAuthTokenCallback = useCallback(
|
|
169
|
+
(frameSrc: string): boolean => isTrustedFrameForAuthToken(frameSrc, config),
|
|
170
|
+
[config],
|
|
207
171
|
);
|
|
208
172
|
|
|
209
173
|
const accessTokenRef = useRef<string | null>(session?.accessToken ?? null);
|
|
@@ -217,7 +181,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
217
181
|
const accessToken = accessTokenRef.current;
|
|
218
182
|
for (const [uuid, iframe] of iframes) {
|
|
219
183
|
const frameSrc = iframe?.src ?? '';
|
|
220
|
-
const includeAuthAccessToken =
|
|
184
|
+
const includeAuthAccessToken = isTrustedFrameForAuthTokenCallback(frameSrc);
|
|
221
185
|
const settingsToPropagate = buildSettingsForPropagation(baseSettings, config, lang, {
|
|
222
186
|
includeAuthAccessToken,
|
|
223
187
|
accessToken,
|
|
@@ -230,13 +194,13 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
230
194
|
});
|
|
231
195
|
}
|
|
232
196
|
},
|
|
233
|
-
[config,
|
|
197
|
+
[config, isTrustedFrameForAuthTokenCallback],
|
|
234
198
|
);
|
|
235
199
|
|
|
236
200
|
const pushSettingsToFrame = useCallback(
|
|
237
201
|
(iframeUuid: string, frameSrc: string, baseSettings: Settings) => {
|
|
238
202
|
const lang = baseSettings.language?.code || 'en';
|
|
239
|
-
const includeAuthAccessToken =
|
|
203
|
+
const includeAuthAccessToken = isTrustedFrameForAuthTokenCallback(frameSrc);
|
|
240
204
|
const iframe = shellui.frameRegistry
|
|
241
205
|
.getAllIframes()
|
|
242
206
|
.find(([uuid]) => uuid === iframeUuid)?.[1];
|
|
@@ -251,7 +215,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
251
215
|
to: [iframeUuid],
|
|
252
216
|
});
|
|
253
217
|
},
|
|
254
|
-
[config,
|
|
218
|
+
[config, isTrustedFrameForAuthTokenCallback],
|
|
255
219
|
);
|
|
256
220
|
|
|
257
221
|
// When the shell rotates the JWT, `authUser` often does not change, so the user-sync effect
|
|
@@ -315,17 +279,27 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
315
279
|
const mergedSettings = mergePreferencesIntoSettings(currentSettings, tokenPreferences);
|
|
316
280
|
const signature = JSON.stringify(getPreferenceSnapshot(mergedSettings));
|
|
317
281
|
const prevSignature = JSON.stringify(getPreferenceSnapshot(currentSettings));
|
|
318
|
-
lastSyncedPreferencesRef.current = signature;
|
|
319
282
|
if (signature === prevSignature) {
|
|
283
|
+
lastSyncedPreferencesRef.current = signature;
|
|
320
284
|
logger.info('JWT app preferences match current settings; skipping state update', {
|
|
321
285
|
preferences: getPreferenceSnapshot(mergedSettings),
|
|
322
286
|
});
|
|
323
287
|
return;
|
|
324
288
|
}
|
|
289
|
+
// Current UI already matches what we last synced — JWT is lagging a newer
|
|
290
|
+
// local change (or a superseded sync). Don’t regress appearance.
|
|
291
|
+
if (prevSignature === lastSyncedPreferencesRef.current) {
|
|
292
|
+
logger.info('Ignoring stale JWT preferences that lag last-synced settings', {
|
|
293
|
+
jwt: getPreferenceSnapshot(mergedSettings),
|
|
294
|
+
current: getPreferenceSnapshot(currentSettings),
|
|
295
|
+
});
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
lastSyncedPreferencesRef.current = signature;
|
|
325
299
|
settingsRef.current = mergedSettings;
|
|
326
300
|
setSettings(mergedSettings);
|
|
327
301
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(mergedSettings));
|
|
328
|
-
|
|
302
|
+
schedulePropagateSettingsToIframes(mergedSettings);
|
|
329
303
|
logger.info('Loaded app preferences from JWT metadata', {
|
|
330
304
|
preferences: getPreferenceSnapshot(mergedSettings),
|
|
331
305
|
});
|
|
@@ -437,7 +411,8 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
437
411
|
try {
|
|
438
412
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(nextSettings));
|
|
439
413
|
logger.info('Root Parent received settings update', { message });
|
|
440
|
-
|
|
414
|
+
// Coalesce with rapid theme spam (same debounce as updateSettings).
|
|
415
|
+
schedulePropagateSettingsToIframes(nextSettings);
|
|
441
416
|
} catch (error) {
|
|
442
417
|
logger.error('Failed to update settings from message:', { error });
|
|
443
418
|
}
|
|
@@ -460,7 +435,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
460
435
|
.find(([uuid]) => uuid === firstHopIframeUuid)?.[1];
|
|
461
436
|
const lang = currentSettings.language?.code || 'en';
|
|
462
437
|
const includeAuthAccessToken = frame
|
|
463
|
-
?
|
|
438
|
+
? isTrustedFrameForAuthTokenCallback(frame.src ?? '')
|
|
464
439
|
: false;
|
|
465
440
|
const settingsToPropagate = buildSettingsForPropagation(currentSettings, config, lang, {
|
|
466
441
|
includeAuthAccessToken,
|
|
@@ -528,7 +503,13 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
528
503
|
cleanupSettingsRequested();
|
|
529
504
|
cleanupInitialized();
|
|
530
505
|
};
|
|
531
|
-
}, [
|
|
506
|
+
}, [
|
|
507
|
+
config,
|
|
508
|
+
isTrustedFrameForAuthTokenCallback,
|
|
509
|
+
propagateSettingsToIframes,
|
|
510
|
+
pushSettingsToFrame,
|
|
511
|
+
schedulePropagateSettingsToIframes,
|
|
512
|
+
]);
|
|
532
513
|
|
|
533
514
|
// Apply config activeTheme / defaultTheme on first visit (no localStorage preference yet)
|
|
534
515
|
useEffect(() => {
|
|
@@ -605,7 +586,9 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
605
586
|
// ACTIONS
|
|
606
587
|
const updateSettings = useCallback(
|
|
607
588
|
(updates: Partial<Settings>) => {
|
|
608
|
-
|
|
589
|
+
// Always merge from the latest ref so rapid theme toggles don’t clobber each other.
|
|
590
|
+
const base = settingsRef.current ?? defaultSettings;
|
|
591
|
+
const nextSettings = { ...base, ...updates };
|
|
609
592
|
|
|
610
593
|
// Update localStorage and propagate to children if we're in the root window
|
|
611
594
|
if (typeof window !== 'undefined' && window.parent === window) {
|
|
@@ -631,20 +614,21 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
631
614
|
payload: { settings: stripSensitiveUserFields(nextSettings) },
|
|
632
615
|
});
|
|
633
616
|
},
|
|
634
|
-
[
|
|
617
|
+
[schedulePropagateSettingsToIframes],
|
|
635
618
|
);
|
|
636
619
|
|
|
637
620
|
const updateSetting = useCallback(
|
|
638
621
|
<K extends keyof Settings>(key: K, updates: Partial<Settings[K]>) => {
|
|
639
|
-
// Deep merge: preserve existing nested properties
|
|
640
|
-
const
|
|
622
|
+
// Deep merge from latest ref: preserve existing nested properties
|
|
623
|
+
const base = settingsRef.current ?? defaultSettings;
|
|
624
|
+
const currentValue = base[key];
|
|
641
625
|
const mergedValue =
|
|
642
626
|
typeof currentValue === 'object' && currentValue !== null && !Array.isArray(currentValue)
|
|
643
627
|
? { ...currentValue, ...updates }
|
|
644
628
|
: updates;
|
|
645
629
|
updateSettings({ [key]: mergedValue } as Partial<Settings>);
|
|
646
630
|
},
|
|
647
|
-
[
|
|
631
|
+
[updateSettings],
|
|
648
632
|
);
|
|
649
633
|
|
|
650
634
|
const resetAllData = useCallback(() => {
|
|
@@ -16,6 +16,7 @@ import { DialogTestButtons } from './develop/DialogTestButtons';
|
|
|
16
16
|
import { ModalTestButtons } from './develop/ModalTestButtons';
|
|
17
17
|
import { DrawerTestButtons } from './develop/DrawerTestButtons';
|
|
18
18
|
import { StoragePickerTestButtons } from './develop/StoragePickerTestButtons';
|
|
19
|
+
import { ChromeActionsTestButtons } from './develop/ChromeActionsTestButtons';
|
|
19
20
|
import { captureException } from '../../sentry/initSentry';
|
|
20
21
|
import { useCookieConsent } from '../../cookieConsent/useCookieConsent';
|
|
21
22
|
import { normalizeLayoutType, type LayoutType } from '../../config/types';
|
|
@@ -231,6 +232,7 @@ export const Develop = () => {
|
|
|
231
232
|
<ModalTestButtons />
|
|
232
233
|
<DrawerTestButtons />
|
|
233
234
|
<StoragePickerTestButtons />
|
|
235
|
+
<ChromeActionsTestButtons />
|
|
234
236
|
{errorReportingConfigured && (
|
|
235
237
|
<div className="flex items-center justify-between">
|
|
236
238
|
<div className="space-y-0.5">
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import { Button } from '../../../../components/ui/button';
|
|
3
|
+
import { shellui } from '@shellui/sdk';
|
|
4
|
+
import urls from '../../../../constants/urls';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Settings → Develop: open the chrome-actions demo inside a modal/drawer iframe
|
|
8
|
+
* so `shellui.actions.*` runs through the real postMessage path.
|
|
9
|
+
*/
|
|
10
|
+
export const ChromeActionsTestButtons = () => {
|
|
11
|
+
const { t } = useTranslation('settings');
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
<h4
|
|
16
|
+
className="text-sm font-medium mb-2"
|
|
17
|
+
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
18
|
+
>
|
|
19
|
+
{t('develop.testing.chromeActions.title')}
|
|
20
|
+
</h4>
|
|
21
|
+
<div className="flex flex-wrap gap-2">
|
|
22
|
+
<Button
|
|
23
|
+
type="button"
|
|
24
|
+
variant="outline"
|
|
25
|
+
onClick={() =>
|
|
26
|
+
shellui.openModal({
|
|
27
|
+
url: urls.chromeActionsDemo,
|
|
28
|
+
size: 'lg',
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
>
|
|
32
|
+
{t('develop.testing.chromeActions.buttons.openModal')}
|
|
33
|
+
</Button>
|
|
34
|
+
<Button
|
|
35
|
+
type="button"
|
|
36
|
+
variant="outline"
|
|
37
|
+
onClick={() =>
|
|
38
|
+
shellui.openDrawer({
|
|
39
|
+
url: urls.chromeActionsDemo,
|
|
40
|
+
position: 'bottom',
|
|
41
|
+
size: '70vh',
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
>
|
|
45
|
+
{t('develop.testing.chromeActions.buttons.openDrawer')}
|
|
46
|
+
</Button>
|
|
47
|
+
<Button
|
|
48
|
+
type="button"
|
|
49
|
+
variant="outline"
|
|
50
|
+
onClick={() => {
|
|
51
|
+
shellui.closeDrawer();
|
|
52
|
+
shellui.closeModal();
|
|
53
|
+
}}
|
|
54
|
+
>
|
|
55
|
+
{t('develop.testing.chromeActions.buttons.close')}
|
|
56
|
+
</Button>
|
|
57
|
+
</div>
|
|
58
|
+
<p className="text-xs text-muted-foreground mt-2">
|
|
59
|
+
{t('develop.testing.chromeActions.description')}
|
|
60
|
+
</p>
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
@@ -116,7 +116,29 @@ describe('buildSettingsForPropagation', () => {
|
|
|
116
116
|
expect(result.appearance?.availableThemes?.length).toBeGreaterThan(0);
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
-
it('
|
|
119
|
+
it('never propagates refresh tokens to iframe settings', () => {
|
|
120
|
+
const settingsWithRefresh = {
|
|
121
|
+
...baseSettings,
|
|
122
|
+
refreshToken: 'secret-refresh-token',
|
|
123
|
+
} as Settings & { refreshToken: string };
|
|
124
|
+
|
|
125
|
+
const result = buildSettingsForPropagation(settingsWithRefresh, undefined, 'en', {
|
|
126
|
+
includeAuthAccessToken: true,
|
|
127
|
+
accessToken: 'access-jwt',
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
expect(result.accessToken).toBe('access-jwt');
|
|
131
|
+
expect(result).not.toHaveProperty('refreshToken');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('defaults access token to null when includeAuthAccessToken is omitted', () => {
|
|
135
|
+
const result = buildSettingsForPropagation(baseSettings, undefined, 'en', {
|
|
136
|
+
accessToken: 'jwt.should.not.be.exposed',
|
|
137
|
+
});
|
|
138
|
+
expect(result.accessToken).toBeNull();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('injects access token into settings only when explicitly allowed', () => {
|
|
120
142
|
const settingsWithUser: Settings = {
|
|
121
143
|
...baseSettings,
|
|
122
144
|
user: {
|
|
@@ -122,5 +122,12 @@ export const buildSettingsForPropagation = (
|
|
|
122
122
|
authBackendBaseUrl,
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
+
if ('refreshToken' in result) {
|
|
126
|
+
const { refreshToken: _refreshRemoved, ...withoutRefresh } = result as Settings & {
|
|
127
|
+
refreshToken?: string;
|
|
128
|
+
};
|
|
129
|
+
return withoutRefresh;
|
|
130
|
+
}
|
|
131
|
+
|
|
125
132
|
return result;
|
|
126
133
|
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import type { ShellUIConfig } from '../config/types';
|
|
3
|
+
import { getStorageRequestTrustDenial } from '../security/trustedFrames';
|
|
4
|
+
import { handleStorageRequest } from './handleRequest';
|
|
5
|
+
|
|
6
|
+
const config = {
|
|
7
|
+
navigation: [
|
|
8
|
+
{
|
|
9
|
+
label: 'Companion',
|
|
10
|
+
path: 'companion',
|
|
11
|
+
url: 'http://localhost:5175/',
|
|
12
|
+
safeForAuthToken: true,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: 'Hostile',
|
|
16
|
+
path: 'hostile',
|
|
17
|
+
url: 'http://localhost:5199/',
|
|
18
|
+
safeForAuthToken: false,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
} as ShellUIConfig;
|
|
22
|
+
|
|
23
|
+
describe('StorageBridge trust gate', () => {
|
|
24
|
+
it('rejects hostile iframe storage requests before storage I/O', async () => {
|
|
25
|
+
const fetchMock = vi.fn();
|
|
26
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
27
|
+
|
|
28
|
+
const denial = getStorageRequestTrustDenial(
|
|
29
|
+
['hostile-uuid'],
|
|
30
|
+
{
|
|
31
|
+
getAllIframes: () => [
|
|
32
|
+
['hostile-uuid', { src: 'http://localhost:5199/widget' } as HTMLIFrameElement],
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
config,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
expect(denial).toEqual({
|
|
39
|
+
message: 'Storage request rejected: untrusted frame',
|
|
40
|
+
status: 403,
|
|
41
|
+
});
|
|
42
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
43
|
+
|
|
44
|
+
vi.unstubAllGlobals();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('allows trusted companion frames to reach handleStorageRequest', async () => {
|
|
48
|
+
const denial = getStorageRequestTrustDenial(
|
|
49
|
+
['companion-uuid'],
|
|
50
|
+
{
|
|
51
|
+
getAllIframes: () => [
|
|
52
|
+
['companion-uuid', { src: 'http://localhost:5175/company' } as HTMLIFrameElement],
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
config,
|
|
56
|
+
);
|
|
57
|
+
expect(denial).toBeNull();
|
|
58
|
+
|
|
59
|
+
vi.stubGlobal(
|
|
60
|
+
'fetch',
|
|
61
|
+
vi.fn().mockResolvedValue({
|
|
62
|
+
ok: true,
|
|
63
|
+
status: 200,
|
|
64
|
+
headers: new Headers({ 'Content-Type': 'application/json' }),
|
|
65
|
+
json: async () => [{ name: 'company' }],
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
await expect(
|
|
70
|
+
handleStorageRequest({
|
|
71
|
+
storageUrl: 'http://localhost:8001',
|
|
72
|
+
accessToken: 'token',
|
|
73
|
+
payload: { id: 'req-trusted', op: 'listBuckets' },
|
|
74
|
+
}),
|
|
75
|
+
).resolves.toEqual({
|
|
76
|
+
id: 'req-trusted',
|
|
77
|
+
data: [{ name: 'company' }],
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
vi.unstubAllGlobals();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
postShellMessage,
|
|
4
|
+
shellui,
|
|
5
|
+
type ShellUIMessage,
|
|
6
|
+
type StorageRequestPayload,
|
|
7
|
+
} from '@shellui/sdk';
|
|
3
8
|
import { useAuth } from '../auth/hooks/useAuth';
|
|
4
9
|
import { useConfig } from '../config/useConfig';
|
|
10
|
+
import { getStorageRequestTrustDenial } from '../security/trustedFrames';
|
|
5
11
|
import { handleStorageRequest } from './handleRequest';
|
|
6
12
|
import { getStorageBaseUrl } from './quota';
|
|
7
13
|
import { handleTrackedUpload, isUploadPayload } from './uploads/handleTrackedUpload';
|
|
@@ -25,6 +31,22 @@ export const StorageBridge = () => {
|
|
|
25
31
|
const payload = message.payload as StorageRequestPayload | undefined;
|
|
26
32
|
if (!payload?.id || !payload.op) return;
|
|
27
33
|
|
|
34
|
+
const trustDenial = getStorageRequestTrustDenial(message.from, shellui.frameRegistry, config);
|
|
35
|
+
if (trustDenial) {
|
|
36
|
+
const response = { id: payload.id, error: trustDenial };
|
|
37
|
+
const reply = {
|
|
38
|
+
type: 'SHELLUI_STORAGE_RESPONSE' as const,
|
|
39
|
+
payload: response,
|
|
40
|
+
};
|
|
41
|
+
const from = message.from?.filter(Boolean) as string[] | undefined;
|
|
42
|
+
if (from?.length) {
|
|
43
|
+
shellui.sendMessage({ ...reply, to: from });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
window.postMessage(reply, '*');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
28
50
|
const run = isUploadPayload(payload)
|
|
29
51
|
? handleTrackedUpload({ storageUrl, accessToken, payload })
|
|
30
52
|
: handleStorageRequest({ storageUrl, accessToken, payload });
|
|
@@ -39,12 +61,12 @@ export const StorageBridge = () => {
|
|
|
39
61
|
shellui.sendMessage({ ...reply, to: from });
|
|
40
62
|
return;
|
|
41
63
|
}
|
|
42
|
-
|
|
64
|
+
postShellMessage(reply);
|
|
43
65
|
});
|
|
44
66
|
};
|
|
45
67
|
|
|
46
68
|
return shellui.addMessageListener('SHELLUI_STORAGE_REQUEST', listener);
|
|
47
|
-
}, [storageUrl, accessToken]);
|
|
69
|
+
}, [storageUrl, accessToken, config]);
|
|
48
70
|
|
|
49
71
|
return null;
|
|
50
72
|
};
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from 'react';
|
|
10
10
|
import { useTranslation } from 'react-i18next';
|
|
11
11
|
import {
|
|
12
|
+
postShellMessage,
|
|
12
13
|
shellui,
|
|
13
14
|
type ShellUIMessage,
|
|
14
15
|
type StorageSelectMode,
|
|
@@ -63,9 +64,7 @@ function replyToRequester(pending: PendingSelect, payload: StorageSelectResponse
|
|
|
63
64
|
shellui.sendMessage({ ...message, to });
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
|
-
|
|
67
|
-
window.postMessage(message, '*');
|
|
68
|
-
}
|
|
67
|
+
postShellMessage(message);
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
interface StoragePickerProviderProps {
|
|
@@ -104,7 +103,7 @@ export const StoragePickerProvider = ({ children }: StoragePickerProviderProps)
|
|
|
104
103
|
shellui.sendMessage({ ...reply, to });
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
|
-
|
|
106
|
+
postShellMessage(reply);
|
|
108
107
|
}, []);
|
|
109
108
|
|
|
110
109
|
useEffect(() => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it } from 'vitest';
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import {
|
|
3
3
|
addUpload,
|
|
4
4
|
closeUploadToaster,
|
|
@@ -15,11 +15,17 @@ import {
|
|
|
15
15
|
setUploadProgress,
|
|
16
16
|
setUploadToastExpanded,
|
|
17
17
|
isUploadToastExpanded,
|
|
18
|
+
UPLOAD_TOAST_AUTO_DISMISS_MS,
|
|
18
19
|
} from './uploadQueue';
|
|
19
20
|
|
|
20
21
|
describe('uploadQueue', () => {
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
vi.useFakeTimers();
|
|
24
|
+
});
|
|
25
|
+
|
|
21
26
|
afterEach(() => {
|
|
22
27
|
resetUploadQueue();
|
|
28
|
+
vi.useRealTimers();
|
|
23
29
|
});
|
|
24
30
|
|
|
25
31
|
it('tracks progress and overall percent across files', () => {
|
|
@@ -115,4 +121,53 @@ describe('uploadQueue', () => {
|
|
|
115
121
|
expect(getUploadQueue()).toEqual([]);
|
|
116
122
|
expect(isUploadToastExpanded()).toBe(false);
|
|
117
123
|
});
|
|
124
|
+
|
|
125
|
+
it('auto-dismisses the toaster a few seconds after all uploads succeed', () => {
|
|
126
|
+
addUpload({ id: 'a', name: 'a.pdf', path: 'a.pdf', bucket: 'company', size: 10 });
|
|
127
|
+
addUpload({ id: 'b', name: 'b.pdf', path: 'b.pdf', bucket: 'company', size: 10 });
|
|
128
|
+
completeUpload('a');
|
|
129
|
+
expect(getUploadQueue()).toHaveLength(2);
|
|
130
|
+
completeUpload('b');
|
|
131
|
+
expect(getUploadQueue()).toHaveLength(2);
|
|
132
|
+
|
|
133
|
+
vi.advanceTimersByTime(UPLOAD_TOAST_AUTO_DISMISS_MS - 1);
|
|
134
|
+
expect(getUploadQueue()).toHaveLength(2);
|
|
135
|
+
|
|
136
|
+
vi.advanceTimersByTime(1);
|
|
137
|
+
expect(getUploadQueue()).toEqual([]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('does not auto-dismiss when any upload fails', () => {
|
|
141
|
+
addUpload({ id: 'ok', name: 'ok.pdf', path: 'ok.pdf', bucket: 'company', size: 10 });
|
|
142
|
+
addUpload({ id: 'bad', name: 'bad.pdf', path: 'bad.pdf', bucket: 'company', size: 10 });
|
|
143
|
+
completeUpload('ok');
|
|
144
|
+
failUpload('bad', 'Denied');
|
|
145
|
+
|
|
146
|
+
vi.advanceTimersByTime(UPLOAD_TOAST_AUTO_DISMISS_MS * 2);
|
|
147
|
+
expect(getUploadQueue()).toHaveLength(2);
|
|
148
|
+
expect(getUploadQueue().map((item) => item.status)).toEqual(['success', 'error']);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('cancels a pending auto-dismiss when a new upload starts', () => {
|
|
152
|
+
addUpload({ id: 'ok', name: 'ok.pdf', path: 'ok.pdf', bucket: 'company', size: 10 });
|
|
153
|
+
completeUpload('ok');
|
|
154
|
+
|
|
155
|
+
vi.advanceTimersByTime(UPLOAD_TOAST_AUTO_DISMISS_MS - 100);
|
|
156
|
+
addUpload({ id: 'next', name: 'next.pdf', path: 'next.pdf', bucket: 'company', size: 10 });
|
|
157
|
+
|
|
158
|
+
vi.advanceTimersByTime(UPLOAD_TOAST_AUTO_DISMISS_MS);
|
|
159
|
+
expect(getUploadQueue().map((item) => item.id)).toEqual(['ok', 'next']);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('cancels a pending auto-dismiss when the toaster is closed manually', () => {
|
|
163
|
+
addUpload({ id: 'ok', name: 'ok.pdf', path: 'ok.pdf', bucket: 'company', size: 10 });
|
|
164
|
+
completeUpload('ok');
|
|
165
|
+
closeUploadToaster();
|
|
166
|
+
expect(getUploadQueue()).toEqual([]);
|
|
167
|
+
|
|
168
|
+
addUpload({ id: 'again', name: 'again.pdf', path: 'again.pdf', bucket: 'company', size: 10 });
|
|
169
|
+
vi.advanceTimersByTime(UPLOAD_TOAST_AUTO_DISMISS_MS);
|
|
170
|
+
expect(getUploadQueue()).toHaveLength(1);
|
|
171
|
+
expect(getUploadQueue()[0]?.status).toBe('uploading');
|
|
172
|
+
});
|
|
118
173
|
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { postShellMessage } from '@shellui/sdk';
|
|
1
2
|
import type { UploadItem, UploadItemStatus, UploadQueueSummary } from './types';
|
|
2
3
|
|
|
3
4
|
export const UPLOAD_TOAST_ID = 'shellui-upload-progress';
|
|
4
5
|
export const UPLOAD_TOAST_DEMO_MESSAGE = 'SHELLUI_UPLOAD_TOAST_DEMO';
|
|
6
|
+
/** Brief pause so the success state is visible before the toaster hides. */
|
|
7
|
+
export const UPLOAD_TOAST_AUTO_DISMISS_MS = 2500;
|
|
5
8
|
|
|
6
9
|
type UploadListener = () => void;
|
|
7
10
|
|
|
@@ -21,6 +24,33 @@ const demoStartTimeouts: ReturnType<typeof setTimeout>[] = [];
|
|
|
21
24
|
|
|
22
25
|
let items: UploadItem[] = [];
|
|
23
26
|
let expanded = false;
|
|
27
|
+
let autoDismissTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
28
|
+
|
|
29
|
+
function clearAutoDismissTimeout(): void {
|
|
30
|
+
if (autoDismissTimeout === null) return;
|
|
31
|
+
clearTimeout(autoDismissTimeout);
|
|
32
|
+
autoDismissTimeout = null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Hide the toaster a few seconds after every upload finishes successfully.
|
|
37
|
+
* Errors and in-progress uploads keep the panel open; cancelled-only queues stay too.
|
|
38
|
+
*/
|
|
39
|
+
function scheduleAutoDismissIfNeeded(): void {
|
|
40
|
+
clearAutoDismissTimeout();
|
|
41
|
+
const summary = getUploadSummary();
|
|
42
|
+
if (summary.uploading > 0 || summary.error > 0 || summary.success === 0) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
autoDismissTimeout = setTimeout(() => {
|
|
46
|
+
autoDismissTimeout = null;
|
|
47
|
+
const current = getUploadSummary();
|
|
48
|
+
if (current.uploading > 0 || current.error > 0 || current.success === 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
resetUploadQueue();
|
|
52
|
+
}, UPLOAD_TOAST_AUTO_DISMISS_MS);
|
|
53
|
+
}
|
|
24
54
|
|
|
25
55
|
function emit(): void {
|
|
26
56
|
listeners.forEach((listener) => listener());
|
|
@@ -115,6 +145,7 @@ export function getItemPercent(item: UploadItem): number {
|
|
|
115
145
|
}
|
|
116
146
|
|
|
117
147
|
export function addUpload(input: AddUploadInput): { id: string; signal: AbortSignal } {
|
|
148
|
+
clearAutoDismissTimeout();
|
|
118
149
|
const id = input.id ?? createId();
|
|
119
150
|
const existing = abortControllers.get(id);
|
|
120
151
|
existing?.abort();
|
|
@@ -159,6 +190,7 @@ export function completeUpload(id: string): void {
|
|
|
159
190
|
bytesUploaded: item.size || item.bytesUploaded,
|
|
160
191
|
error: undefined,
|
|
161
192
|
});
|
|
193
|
+
scheduleAutoDismissIfNeeded();
|
|
162
194
|
}
|
|
163
195
|
|
|
164
196
|
export function failUpload(id: string, message: string): void {
|
|
@@ -167,6 +199,7 @@ export function failUpload(id: string, message: string): void {
|
|
|
167
199
|
abortControllers.delete(id);
|
|
168
200
|
clearDemoTimer(id);
|
|
169
201
|
patchItem(id, { status: 'error', error: message });
|
|
202
|
+
clearAutoDismissTimeout();
|
|
170
203
|
}
|
|
171
204
|
|
|
172
205
|
export function markUploadCancelled(id: string): void {
|
|
@@ -174,6 +207,7 @@ export function markUploadCancelled(id: string): void {
|
|
|
174
207
|
abortControllers.delete(id);
|
|
175
208
|
clearDemoTimer(id);
|
|
176
209
|
patchItem(id, { status: 'cancelled' });
|
|
210
|
+
scheduleAutoDismissIfNeeded();
|
|
177
211
|
}
|
|
178
212
|
|
|
179
213
|
/** Abort an in-progress upload and keep it visible as cancelled. */
|
|
@@ -196,11 +230,18 @@ export function removeUpload(id: string): void {
|
|
|
196
230
|
const next = items.filter((entry) => entry.id !== id);
|
|
197
231
|
if (next.length === items.length) return;
|
|
198
232
|
items = next;
|
|
199
|
-
if (items.length === 0)
|
|
233
|
+
if (items.length === 0) {
|
|
234
|
+
expanded = false;
|
|
235
|
+
clearAutoDismissTimeout();
|
|
236
|
+
}
|
|
200
237
|
emit();
|
|
238
|
+
if (items.length > 0) {
|
|
239
|
+
scheduleAutoDismissIfNeeded();
|
|
240
|
+
}
|
|
201
241
|
}
|
|
202
242
|
|
|
203
243
|
export function dismissFinishedUploads(): void {
|
|
244
|
+
clearAutoDismissTimeout();
|
|
204
245
|
const keep = items.filter((item) => item.status === 'uploading');
|
|
205
246
|
items.forEach((item) => {
|
|
206
247
|
if (item.status === 'uploading') return;
|
|
@@ -228,6 +269,7 @@ export function closeUploadToaster(): void {
|
|
|
228
269
|
}
|
|
229
270
|
|
|
230
271
|
export function resetUploadQueue(): void {
|
|
272
|
+
clearAutoDismissTimeout();
|
|
231
273
|
abortControllers.forEach((controller) => controller.abort());
|
|
232
274
|
abortControllers.clear();
|
|
233
275
|
demoTimers.forEach((timer) => clearInterval(timer));
|
|
@@ -300,11 +342,7 @@ function clearDemoUploads(): void {
|
|
|
300
342
|
export function requestUploadToastDemo(): void {
|
|
301
343
|
if (typeof window === 'undefined') return;
|
|
302
344
|
const message = { type: UPLOAD_TOAST_DEMO_MESSAGE, payload: {} };
|
|
303
|
-
|
|
304
|
-
window.parent.postMessage(message, '*');
|
|
305
|
-
return;
|
|
306
|
-
}
|
|
307
|
-
window.postMessage(message, '*');
|
|
345
|
+
postShellMessage(message);
|
|
308
346
|
}
|
|
309
347
|
|
|
310
348
|
/** Simulated uploads for the Develop panel — no network requests. */
|