@shellui/core 0.3.0 → 0.4.0

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.
Files changed (75) hide show
  1. package/package.json +2 -2
  2. package/src/app.tsx +31 -3
  3. package/src/components/ui/dialog.tsx +26 -6
  4. package/src/components/ui/sonner.tsx +9 -5
  5. package/src/features/admin/AdminView.tsx +5 -49
  6. package/src/features/admin/config.ts +15 -0
  7. package/src/features/admin/index.ts +4 -0
  8. package/src/features/admin/routes.tsx +14 -0
  9. package/src/features/admin/utils.ts +79 -0
  10. package/src/features/auth/AuthProvider.tsx +68 -13
  11. package/src/features/auth/backends/shellui.ts +8 -1
  12. package/src/features/auth/components/AccessPendingView.tsx +112 -0
  13. package/src/features/auth/components/LoginButton.tsx +5 -10
  14. package/src/features/auth/components/LoginView.tsx +20 -2
  15. package/src/features/auth/components/OAuthCallbackView.tsx +211 -50
  16. package/src/features/auth/hooks/useAuth.tsx +8 -1
  17. package/src/features/auth/utils/authRequestError.spec.ts +52 -0
  18. package/src/features/auth/utils/authRequestError.ts +45 -0
  19. package/src/features/auth/utils/buildAuthUrlWithNext.spec.ts +18 -0
  20. package/src/features/auth/utils/buildAuthUrlWithNext.ts +12 -0
  21. package/src/features/auth/utils/index.ts +8 -0
  22. package/src/features/auth/utils/isTokenAutoRefreshDisabled.spec.ts +71 -0
  23. package/src/features/auth/utils/isTokenAutoRefreshDisabled.ts +18 -0
  24. package/src/features/config/ConfigProvider.ts +1 -1
  25. package/src/features/config/types.ts +46 -5
  26. package/src/features/layouts/AppLayout.tsx +3 -3
  27. package/src/features/layouts/OverlayShell.tsx +17 -28
  28. package/src/features/layouts/resolveSdkNavigatePath.spec.ts +55 -0
  29. package/src/features/layouts/resolveSdkNavigatePath.ts +68 -0
  30. package/src/features/settings/SettingsIcons.tsx +35 -0
  31. package/src/features/settings/SettingsProvider.tsx +79 -10
  32. package/src/features/settings/SettingsRoutes.tsx +14 -6
  33. package/src/features/settings/SettingsView.tsx +11 -5
  34. package/src/features/settings/components/Advanced.tsx +117 -44
  35. package/src/features/settings/components/Develop.tsx +38 -0
  36. package/src/features/settings/components/ServiceWorker.tsx +52 -25
  37. package/src/features/settings/components/Storage.tsx +138 -0
  38. package/src/features/settings/components/UpdateApp.tsx +1 -1
  39. package/src/features/settings/components/develop/StoragePickerTestButtons.tsx +148 -0
  40. package/src/features/settings/components/develop/UploadToastTestButton.tsx +29 -0
  41. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +55 -1
  42. package/src/features/settings/utils/buildSettingsForPropagation.ts +34 -0
  43. package/src/features/settings/utils/mergePreferencesIntoSettings.spec.ts +1 -1
  44. package/src/features/settings/utils/toSettingsUser.spec.ts +4 -0
  45. package/src/features/settings/utils/toSettingsUser.ts +2 -0
  46. package/src/features/sonner/SonnerContext.tsx +44 -60
  47. package/src/features/storage/StorageBridge.tsx +50 -0
  48. package/src/features/storage/StoragePickerContext.tsx +214 -0
  49. package/src/features/storage/api.spec.ts +303 -0
  50. package/src/features/storage/api.ts +414 -0
  51. package/src/features/storage/handleRequest.spec.ts +88 -0
  52. package/src/features/storage/handleRequest.ts +53 -0
  53. package/src/features/storage/quota.spec.ts +151 -0
  54. package/src/features/storage/quota.ts +104 -0
  55. package/src/features/storage/uploads/UploadToastCard.tsx +442 -0
  56. package/src/features/storage/uploads/UploadToaster.tsx +41 -0
  57. package/src/features/storage/uploads/handleTrackedUpload.spec.ts +170 -0
  58. package/src/features/storage/uploads/handleTrackedUpload.ts +97 -0
  59. package/src/features/storage/uploads/types.ts +24 -0
  60. package/src/features/storage/uploads/uploadQueue.spec.ts +118 -0
  61. package/src/features/storage/uploads/uploadQueue.ts +349 -0
  62. package/src/features/storage/uploads/useUploadQueue.ts +30 -0
  63. package/src/i18n/translations/en/common.json +33 -0
  64. package/src/i18n/translations/en/settings.json +56 -4
  65. package/src/i18n/translations/fr/common.json +33 -0
  66. package/src/i18n/translations/fr/settings.json +56 -4
  67. package/src/index.css +2 -1
  68. package/src/index.ts +2 -0
  69. package/src/lib/z-index.ts +9 -3
  70. package/src/routes/components/NavigationItemRoute.tsx +2 -1
  71. package/src/routes/routes.tsx +2 -13
  72. package/src/service-worker/register.ts +217 -101
  73. package/src/service-worker/sw-dev.ts +5 -1
  74. package/src/service-worker/sw.ts +5 -1
  75. package/src/shellui-target.d.ts +2 -0
@@ -3,7 +3,14 @@ export {
3
3
  getShellUILoginCompanyId,
4
4
  getShellUILoginDeviceId,
5
5
  } from './clientLoginContext';
6
+ export { buildAuthUrlWithNext } from './buildAuthUrlWithNext';
6
7
  export { buildSessionFromParams } from './buildSessionFromParams';
8
+ export {
9
+ AuthRequestError,
10
+ getAuthRequestErrorCode,
11
+ inferAccessPendingErrorCode,
12
+ isAccessPendingErrorCode,
13
+ } from './authRequestError';
7
14
  export { clearStoredAuthSession } from './clearStoredAuthSession';
8
15
  export { decodeJwtPayload } from './decodeJwtPayload';
9
16
  export { formatProviderLabel } from './formatProviderLabel';
@@ -13,6 +20,7 @@ export { getPreferredBackendProvider } from './getPreferredBackendProvider';
13
20
  export { getProviderVisual } from './getProviderVisual';
14
21
  export { isLoginMethod } from './isLoginMethod';
15
22
  export { isSessionExpired } from './isSessionExpired';
23
+ export { isTokenAutoRefreshDisabled } from './isTokenAutoRefreshDisabled';
16
24
  export { normalizeAuthSettings } from './normalizeAuthSettings';
17
25
  export { normalizeNextPath } from './normalizeNextPath';
18
26
  export { normalizeRedirectPath } from './normalizeRedirectPath';
@@ -0,0 +1,71 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { isTokenAutoRefreshDisabled } from './isTokenAutoRefreshDisabled';
3
+
4
+ const createStorageMock = (value: string | null) => {
5
+ let stored = value;
6
+ return {
7
+ getItem: vi.fn((key: string) => (key === 'shellui:settings' ? stored : null)),
8
+ setItem: vi.fn((_key: string, next: string) => {
9
+ stored = next;
10
+ }),
11
+ removeItem: vi.fn(() => {
12
+ stored = null;
13
+ }),
14
+ clear: vi.fn(() => {
15
+ stored = null;
16
+ }),
17
+ key: vi.fn(() => null),
18
+ length: 0,
19
+ } as unknown as Storage;
20
+ };
21
+
22
+ describe('isTokenAutoRefreshDisabled', () => {
23
+ beforeEach(() => {
24
+ Object.defineProperty(globalThis, 'localStorage', {
25
+ configurable: true,
26
+ value: createStorageMock(null),
27
+ });
28
+ });
29
+
30
+ it('returns false when settings are missing', () => {
31
+ expect(isTokenAutoRefreshDisabled()).toBe(false);
32
+ });
33
+
34
+ it('returns false when the flag is unset or false', () => {
35
+ Object.defineProperty(globalThis, 'localStorage', {
36
+ configurable: true,
37
+ value: createStorageMock(JSON.stringify({ developerFeatures: { enabled: true } })),
38
+ });
39
+ expect(isTokenAutoRefreshDisabled()).toBe(false);
40
+
41
+ Object.defineProperty(globalThis, 'localStorage', {
42
+ configurable: true,
43
+ value: createStorageMock(
44
+ JSON.stringify({
45
+ developerFeatures: { enabled: true, disableTokenAutoRefresh: false },
46
+ }),
47
+ ),
48
+ });
49
+ expect(isTokenAutoRefreshDisabled()).toBe(false);
50
+ });
51
+
52
+ it('returns true when the develop flag is enabled', () => {
53
+ Object.defineProperty(globalThis, 'localStorage', {
54
+ configurable: true,
55
+ value: createStorageMock(
56
+ JSON.stringify({
57
+ developerFeatures: { enabled: true, disableTokenAutoRefresh: true },
58
+ }),
59
+ ),
60
+ });
61
+ expect(isTokenAutoRefreshDisabled()).toBe(true);
62
+ });
63
+
64
+ it('returns false when localStorage JSON is invalid', () => {
65
+ Object.defineProperty(globalThis, 'localStorage', {
66
+ configurable: true,
67
+ value: createStorageMock('{not-json'),
68
+ });
69
+ expect(isTokenAutoRefreshDisabled()).toBe(false);
70
+ });
71
+ });
@@ -0,0 +1,18 @@
1
+ const SETTINGS_STORAGE_KEY = 'shellui:settings';
2
+
3
+ /**
4
+ * Reads the Develop-panel flag that skips background (and restore) token refresh
5
+ * so expired access tokens can be exercised locally.
6
+ */
7
+ export const isTokenAutoRefreshDisabled = (): boolean => {
8
+ try {
9
+ const stored = localStorage.getItem(SETTINGS_STORAGE_KEY);
10
+ if (!stored) return false;
11
+ const parsed = JSON.parse(stored) as {
12
+ developerFeatures?: { disableTokenAutoRefresh?: boolean };
13
+ };
14
+ return parsed.developerFeatures?.disableTokenAutoRefresh === true;
15
+ } catch {
16
+ return false;
17
+ }
18
+ };
@@ -27,7 +27,7 @@ export function ConfigProvider(props: ConfigProviderProps): ReturnType<typeof cr
27
27
  const [config] = useState<ShellUIConfig>(() => {
28
28
  try {
29
29
  const resolved = shelluiConfig ?? ({} as ShellUIConfig);
30
- if (typeof window !== 'undefined' && resolved.runtime === 'tauri') {
30
+ if (typeof window !== 'undefined' && __SHELLUI_TARGET__ === 'tauri') {
31
31
  (window as Window & { __SHELLUI_TAURI__?: boolean }).__SHELLUI_TAURI__ = true;
32
32
  }
33
33
  if (process.env.NODE_ENV === 'development' && !configLogged) {
@@ -26,6 +26,8 @@ export interface NavigationItem {
26
26
  requiresAuth?: boolean;
27
27
  /** When true, this item is available only when Settings > Advanced > Developer features is enabled. */
28
28
  requiresDevMode?: boolean;
29
+ /** When true, this item is available only to staff users (`isStaff`). */
30
+ requiresStaff?: boolean;
29
31
  /** When true, hide this item on mobile (bottom nav). Has no effect if hidden is true. */
30
32
  hiddenOnMobile?: boolean;
31
33
  /** When true, hide this item on desktop (sidebar). Has no effect if hidden is true. */
@@ -189,9 +191,6 @@ export interface LegalDocumentsConfig {
189
191
  dataProcessingAgreement?: string;
190
192
  }
191
193
 
192
- /** When set to 'tauri', disables service worker and hides its settings (Tauri uses a different caching system). */
193
- export type RuntimeType = 'browser' | 'tauri';
194
-
195
194
  /** Supported backend providers for auth/API communication. */
196
195
  export type BackendType = 'shellui' | 'supabase';
197
196
 
@@ -224,13 +223,44 @@ export interface BackendConfig {
224
223
  companyId?: string | number;
225
224
  }
226
225
 
226
+ /**
227
+ * Optional storage-service wiring for the shell and admin panel.
228
+ * When set, admin shows the Storage sidebar (files explorer, statistics, Django admin).
229
+ * Settings → Storage (quota) appears when `url` is set, unless `showInSettings` is false.
230
+ * ShellUI will also use this for the SDK file API (`shellui.storage`).
231
+ */
232
+ export interface StorageConfig {
233
+ /** Base URL of storage-service (e.g. `http://localhost:8001`). */
234
+ url: string;
235
+ /** Files explorer app URL embedded under Admin → Storage → Files (e.g. `http://localhost:5175/`). */
236
+ filesUrl?: string;
237
+ /**
238
+ * When false, hide Settings → Storage even if `url` is set.
239
+ * Admin Storage is unaffected. Default: true.
240
+ */
241
+ showInSettings?: boolean;
242
+ }
243
+
244
+ /**
245
+ * Custom navigation section for the staff administration panel.
246
+ * Admin app URL remains `backend.adminUrl` / `backend.adminPathname`.
247
+ * v1 is a flat list only (no nested groups).
248
+ */
249
+ export interface AdministrationConfig {
250
+ /** Section title shown in the admin sidebar below Dashboard. */
251
+ title: string | LocalizedString;
252
+ /**
253
+ * Flat list of navigation items (same shape as top-level `navigation` items).
254
+ * Order is preserved in the admin sidebar.
255
+ */
256
+ navigation: NavigationItem[];
257
+ }
258
+
227
259
  export interface ShellUIConfig {
228
260
  port?: number;
229
261
  title?: string;
230
262
  /** App version string (e.g. "1.2.0"). Shown in Settings > System > Update app. */
231
263
  version?: string;
232
- /** Set to 'tauri' when the app runs inside Tauri so service worker is disabled and hidden. */
233
- runtime?: RuntimeType;
234
264
  /** Favicon path (e.g. '/favicon.svg'). Used for the document link rel="icon". */
235
265
  favicon?: string;
236
266
  /** App icon path (e.g. '/favicon.svg'). Displayed before title/logo in sidebar header. */
@@ -243,6 +273,17 @@ export interface ShellUIConfig {
243
273
  /** When set, opening the app at "/" redirects to this path (e.g. "/playground"). */
244
274
  start_url?: string;
245
275
  navigation?: (NavigationItem | NavigationGroup)[];
276
+ /**
277
+ * Custom navigation for the staff admin panel (below Dashboard).
278
+ * Propagated to the admin iframe via SDK settings. See Administration docs.
279
+ */
280
+ administration?: AdministrationConfig;
281
+ /**
282
+ * Storage-service connection. Propagated to iframes via SDK settings.
283
+ * Enables Admin → Storage when `url` is set. Settings → Storage (quota) is shown
284
+ * when `url` is set unless `storage.showInSettings` is false.
285
+ */
286
+ storage?: StorageConfig;
246
287
  themes?: ThemeDefinition[]; // Custom themes to register
247
288
  defaultTheme?: string; // Default theme name to use
248
289
  /** Sentry error reporting. Load from env (e.g. SENTRY_DSN). Only active in production builds. */
@@ -1,10 +1,10 @@
1
1
  import { lazy, Suspense, type LazyExoticComponent, type ComponentType } from 'react';
2
2
  import type { LayoutType, NavigationItem, NavigationGroup } from '../config/types';
3
3
  import { useSettings } from '../settings/SettingsContext';
4
- import { SonnerProvider } from '../sonner/SonnerContext';
5
4
  import { ModalProvider } from '../modal/ModalContext';
6
5
  import { DrawerProvider } from '../drawer/DrawerContext';
7
6
  import { OverlayShell } from './OverlayShell';
7
+ import { StoragePickerProvider } from '../storage/StoragePickerContext';
8
8
  import { LayoutFallback } from './LayoutFallback';
9
9
 
10
10
  const SidebarLayout = lazy(() =>
@@ -61,13 +61,13 @@ export function AppLayout({
61
61
  return (
62
62
  <ModalProvider>
63
63
  <DrawerProvider>
64
- <SonnerProvider>
64
+ <StoragePickerProvider>
65
65
  <OverlayShell>
66
66
  <Suspense fallback={<LayoutFallback />}>
67
67
  {children ? children : <LayoutComponent {...layoutProps} />}
68
68
  </Suspense>
69
69
  </OverlayShell>
70
- </SonnerProvider>
70
+ </StoragePickerProvider>
71
71
  </DrawerProvider>
72
72
  </ModalProvider>
73
73
  );
@@ -5,22 +5,25 @@ import { shellui } from '@shellui/sdk';
5
5
  import type { NavigationItem } from '../config/types';
6
6
  import { Dialog, DialogContent, DialogTitle, DialogDescription } from '../../components/ui/dialog';
7
7
  import { Drawer, DrawerContent } from '../../components/ui/drawer';
8
- import { Toaster } from '../../components/ui/sonner';
9
8
  import { ContentView } from '../../components/ContentView';
10
9
  import { useModal } from '../modal/ModalContext';
11
10
  import { useDrawer } from '../drawer/DrawerContext';
11
+ import { useStoragePicker } from '../storage/StoragePickerContext';
12
12
  import { useNavigationItems } from '../../routes/hooks/useNavigationItems';
13
- import { getNavPathPrefix, resolveLocalizedString } from './utils';
13
+ import { useConfig } from '../config/useConfig';
14
+ import { resolveLocalizedString } from './utils';
15
+ import { resolveSdkNavigatePath } from './resolveSdkNavigatePath';
14
16
 
15
17
  interface OverlayShellProps {
16
18
  children: ReactNode;
17
19
  }
18
20
 
19
- /** Renders modal, drawer and toaster overlays and handles SHELLUI_OPEN_MODAL / SHELLUI_NAVIGATE. */
21
+ /** Renders modal and drawer overlays and handles SHELLUI_OPEN_MODAL / SHELLUI_NAVIGATE. */
20
22
  export const OverlayShell = ({ children }: OverlayShellProps) => {
21
23
  const location = useLocation();
22
24
  const navigate = useNavigate();
23
25
  const { navigationItems } = useNavigationItems();
26
+ const { config } = useConfig();
24
27
  const { isOpen, modalUrl, closeModal } = useModal();
25
28
  const {
26
29
  isOpen: isDrawerOpen,
@@ -29,6 +32,7 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
29
32
  size: drawerSize,
30
33
  closeDrawer,
31
34
  } = useDrawer();
35
+ const { isOpen: isPickerOpen, closePicker } = useStoragePicker();
32
36
  const { t, i18n } = useTranslation('common');
33
37
  const currentLanguage = i18n.language || 'en';
34
38
 
@@ -39,9 +43,10 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
39
43
  if (locationKeyRef.current !== currentKey) {
40
44
  closeModal();
41
45
  closeDrawer();
46
+ closePicker();
42
47
  locationKeyRef.current = currentKey;
43
48
  }
44
- }, [location.pathname, location.search, location.hash, closeModal, closeDrawer]);
49
+ }, [location.pathname, location.search, location.hash, closeModal, closeDrawer, closePicker]);
45
50
 
46
51
  useEffect(() => {
47
52
  const cleanup = shellui.addMessageListener('SHELLUI_OPEN_MODAL', () => {
@@ -59,27 +64,9 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
59
64
  closeModal();
60
65
  closeDrawer();
61
66
 
62
- let pathname: string;
63
-
64
- if (rawUrl.startsWith('http://') || rawUrl.startsWith('https://')) {
65
- try {
66
- pathname = new URL(rawUrl).pathname;
67
- } catch {
68
- pathname = rawUrl.startsWith('/') ? rawUrl : `/${rawUrl}`;
69
- }
70
- } else {
71
- pathname = rawUrl.startsWith('/') ? rawUrl : `/${rawUrl}`;
72
- }
73
-
74
- const isHomepage = pathname === '/' || pathname === '';
75
- const isAllowed =
76
- isHomepage ||
77
- navigationItems.some((item) => {
78
- const pathPrefix = getNavPathPrefix(item);
79
- return pathname === pathPrefix || pathname.startsWith(`${pathPrefix}/`);
80
- });
81
- if (isAllowed) {
82
- navigate(pathname || '/');
67
+ const resolvedPath = resolveSdkNavigatePath(rawUrl, config, navigationItems);
68
+ if (resolvedPath) {
69
+ navigate(resolvedPath);
83
70
  } else {
84
71
  shellui.toast({
85
72
  type: 'error',
@@ -90,13 +77,16 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
90
77
  }
91
78
  });
92
79
  return () => cleanup();
93
- }, [navigate, closeModal, closeDrawer, navigationItems, t]);
80
+ }, [navigate, closeModal, closeDrawer, config, navigationItems, t]);
94
81
  return (
95
82
  <>
96
83
  {children}
97
84
  <Dialog
98
85
  open={isOpen}
99
- onOpenChange={(open) => !open && closeModal()}
86
+ onOpenChange={(open) => {
87
+ if (!open && isPickerOpen) return;
88
+ if (!open) closeModal();
89
+ }}
100
90
  >
101
91
  <DialogContent className="max-w-4xl w-full h-[80vh] max-h-[680px] flex flex-col p-0 overflow-hidden">
102
92
  {modalUrl ? (
@@ -179,7 +169,6 @@ export const OverlayShell = ({ children }: OverlayShellProps) => {
179
169
  )}
180
170
  </DrawerContent>
181
171
  </Drawer>
182
- <Toaster />
183
172
  </>
184
173
  );
185
174
  };
@@ -0,0 +1,55 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import urls from '../../../constants/urls';
3
+ import { DEFAULT_ADMIN_URL } from '../../admin/config';
4
+ import type { NavigationItem, ShellUIConfig } from '../../config/types';
5
+ import { resolveSdkNavigatePath } from './resolveSdkNavigatePath';
6
+
7
+ const navItems: NavigationItem[] = [
8
+ {
9
+ label: 'Docs',
10
+ path: 'docs',
11
+ url: 'https://docs.shellui.com',
12
+ },
13
+ {
14
+ label: 'Themes',
15
+ path: 'themes',
16
+ url: 'http://localhost:8000/app/#/themes',
17
+ useHashRouter: true,
18
+ },
19
+ ];
20
+
21
+ const config: ShellUIConfig = {
22
+ backend: {
23
+ type: 'shellui',
24
+ url: 'http://localhost:8000',
25
+ adminPathname: '/admin',
26
+ },
27
+ };
28
+
29
+ describe('resolveSdkNavigatePath', () => {
30
+ it('allows built-in shell routes', () => {
31
+ expect(resolveSdkNavigatePath('/admin', config, navItems)).toBe('/admin');
32
+ expect(resolveSdkNavigatePath(urls.login, config, navItems)).toBe(urls.login);
33
+ expect(resolveSdkNavigatePath(urls.settings, config, navItems)).toBe(urls.settings);
34
+ });
35
+
36
+ it('allows configured navigation paths', () => {
37
+ expect(resolveSdkNavigatePath('/docs', config, navItems)).toBe('/docs');
38
+ expect(resolveSdkNavigatePath('/themes/foo', config, navItems)).toBe('/themes/foo');
39
+ });
40
+
41
+ it('rejects external and absolute URLs', () => {
42
+ expect(resolveSdkNavigatePath(DEFAULT_ADMIN_URL, config, navItems)).toBeNull();
43
+ expect(resolveSdkNavigatePath(`${DEFAULT_ADMIN_URL}/#/users`, config, navItems)).toBeNull();
44
+ expect(resolveSdkNavigatePath('https://docs.shellui.com/page', config, navItems)).toBeNull();
45
+ expect(
46
+ resolveSdkNavigatePath('http://localhost:8000/app/#/themes/colors', config, navItems),
47
+ ).toBeNull();
48
+ expect(resolveSdkNavigatePath('https://evil.example.com', config, navItems)).toBeNull();
49
+ expect(resolveSdkNavigatePath('//evil.example.com/path', config, navItems)).toBeNull();
50
+ });
51
+
52
+ it('rejects unconfigured relative paths', () => {
53
+ expect(resolveSdkNavigatePath('/not-configured', config, navItems)).toBeNull();
54
+ });
55
+ });
@@ -0,0 +1,68 @@
1
+ import urls from '../../constants/urls';
2
+ import type { NavigationItem, ShellUIConfig } from '../config/types';
3
+ import { getAdminPath } from '../admin/config';
4
+ import { getNavPathPrefix } from './utils';
5
+
6
+ const toAbsoluteUrl = (url: string): URL | null => {
7
+ try {
8
+ return new URL(
9
+ url,
10
+ typeof window !== 'undefined' ? window.location.origin : 'http://localhost',
11
+ );
12
+ } catch {
13
+ return null;
14
+ }
15
+ };
16
+
17
+ const normalizeShellPath = (value: string): string => {
18
+ const trimmed = value.trim();
19
+ if (!trimmed) return '/';
20
+ const withoutTrailing = trimmed.replace(/\/+$/, '');
21
+ return withoutTrailing || '/';
22
+ };
23
+
24
+ const matchesAllowedShellPath = (pathname: string, allowedPrefixes: string[]): boolean => {
25
+ const normalized = normalizeShellPath(pathname);
26
+ if (normalized === '/') return true;
27
+ return allowedPrefixes.some((prefix) => {
28
+ if (prefix === '/') return normalized === '/';
29
+ return normalized === prefix || normalized.startsWith(`${prefix}/`);
30
+ });
31
+ };
32
+
33
+ /** Shell path prefixes registered in the router (built-in routes, config navigation, admin). */
34
+ export function getAllowedShellPathPrefixes(
35
+ config: ShellUIConfig | undefined,
36
+ navigationItems: NavigationItem[],
37
+ ): string[] {
38
+ const builtIn = Object.values(urls) as string[];
39
+ const navPrefixes = navigationItems.map(getNavPathPrefix);
40
+ const adminPath = getAdminPath(config);
41
+ return [...new Set(['/', ...builtIn, adminPath, ...navPrefixes].map(normalizeShellPath))];
42
+ }
43
+
44
+ /**
45
+ * Resolve an SDK navigate URL to a shell router path.
46
+ * Only relative shell paths are accepted — external URLs are rejected.
47
+ */
48
+ export function resolveSdkNavigatePath(
49
+ rawUrl: string,
50
+ config: ShellUIConfig | undefined,
51
+ navigationItems: NavigationItem[],
52
+ ): string | null {
53
+ const trimmed = rawUrl.trim();
54
+ if (!trimmed) return null;
55
+
56
+ if (trimmed.startsWith('http://') || trimmed.startsWith('https://') || trimmed.startsWith('//')) {
57
+ return null;
58
+ }
59
+
60
+ const parsed = toAbsoluteUrl(trimmed);
61
+ if (!parsed) return null;
62
+
63
+ const allowedPrefixes = getAllowedShellPathPrefixes(config, navigationItems);
64
+ if (matchesAllowedShellPath(parsed.pathname, allowedPrefixes)) {
65
+ return `${parsed.pathname}${parsed.search}` || '/';
66
+ }
67
+ return null;
68
+ }
@@ -291,6 +291,23 @@ export const ChevronLeftIcon = () => (
291
291
  </svg>
292
292
  );
293
293
 
294
+ export const ChevronDownIcon = ({ className }: { className?: string }) => (
295
+ <svg
296
+ xmlns="http://www.w3.org/2000/svg"
297
+ width="16"
298
+ height="16"
299
+ viewBox="0 0 24 24"
300
+ fill="none"
301
+ stroke="currentColor"
302
+ strokeWidth="2"
303
+ strokeLinecap="round"
304
+ strokeLinejoin="round"
305
+ className={className}
306
+ >
307
+ <polyline points="6 9 12 15 18 9" />
308
+ </svg>
309
+ );
310
+
294
311
  export const ShieldIcon = () => (
295
312
  <svg
296
313
  xmlns="http://www.w3.org/2000/svg"
@@ -307,6 +324,24 @@ export const ShieldIcon = () => (
307
324
  </svg>
308
325
  );
309
326
 
327
+ export const AlertTriangleIcon = () => (
328
+ <svg
329
+ xmlns="http://www.w3.org/2000/svg"
330
+ width="16"
331
+ height="16"
332
+ viewBox="0 0 24 24"
333
+ fill="none"
334
+ stroke="currentColor"
335
+ strokeWidth="2"
336
+ strokeLinecap="round"
337
+ strokeLinejoin="round"
338
+ >
339
+ <path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" />
340
+ <path d="M12 9v4" />
341
+ <path d="M12 17h.01" />
342
+ </svg>
343
+ );
344
+
310
345
  export const HardDriveIcon = () => (
311
346
  <svg
312
347
  xmlns="http://www.w3.org/2000/svg"