@shellui/core 0.6.2 → 0.7.0-alpha.10

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 (85) hide show
  1. package/package.json +2 -2
  2. package/schemas/shellui.config.schema.json +147 -70
  3. package/src/app.tsx +2 -0
  4. package/src/components/ContentView.tsx +21 -30
  5. package/src/components/iframeUrlSafety.spec.ts +67 -0
  6. package/src/components/iframeUrlSafety.ts +50 -0
  7. package/src/components/ui/sidebar.tsx +11 -5
  8. package/src/features/admin/AdminView.tsx +9 -6
  9. package/src/features/auth/AuthProvider.tsx +49 -5
  10. package/src/features/auth/appBackend/AppBackendSessionHost.tsx +58 -0
  11. package/src/features/auth/appBackend/appBackendSessions.spec.ts +329 -0
  12. package/src/features/auth/appBackend/appBackendSessions.ts +443 -0
  13. package/src/features/auth/appBackend/childFrames.spec.ts +328 -0
  14. package/src/features/auth/appBackend/childFrames.ts +180 -0
  15. package/src/features/auth/appBackend/configSchema.spec.ts +41 -0
  16. package/src/features/auth/appBackend/frameAuth.ts +204 -0
  17. package/src/features/auth/appBackend/identity.spec.ts +201 -0
  18. package/src/features/auth/appBackend/identity.ts +173 -0
  19. package/src/features/auth/appBackend/silentSignIn.spec.ts +225 -0
  20. package/src/features/auth/appBackend/silentSignIn.ts +254 -0
  21. package/src/features/auth/appBackend/tokenExchange.spec.ts +98 -0
  22. package/src/features/auth/appBackend/tokenExchange.ts +76 -0
  23. package/src/features/auth/backends/shellui.spec.ts +51 -19
  24. package/src/features/auth/backends/shellui.ts +20 -5
  25. package/src/features/auth/backends/types.ts +7 -2
  26. package/src/features/auth/components/LoginView.tsx +40 -18
  27. package/src/features/auth/components/OAuthCallbackView.tsx +33 -4
  28. package/src/features/auth/utils/authRequestError.ts +3 -0
  29. package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +42 -1
  30. package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +23 -0
  31. package/src/features/auth/utils/canRestoreStoredSession.spec.ts +29 -0
  32. package/src/features/auth/utils/canRestoreStoredSession.ts +12 -0
  33. package/src/features/auth/utils/index.ts +16 -1
  34. package/src/features/auth/utils/loginCancelTarget.spec.ts +73 -0
  35. package/src/features/auth/utils/loginCancelTarget.ts +45 -0
  36. package/src/features/auth/utils/loginPanelFrame.spec.ts +24 -0
  37. package/src/features/auth/utils/loginPanelFrame.ts +14 -0
  38. package/src/features/auth/utils/resolveSdkLoginRedirectPath.spec.ts +41 -0
  39. package/src/features/auth/utils/resolveSdkLoginRedirectPath.ts +31 -0
  40. package/src/features/auth/utils/webPkce.spec.ts +119 -0
  41. package/src/features/auth/utils/webPkce.ts +169 -0
  42. package/src/features/chromeActions/computeActionInsets.ts +7 -4
  43. package/src/features/config/types.ts +70 -3
  44. package/src/features/layouts/appbar/AppBarLayout.tsx +63 -30
  45. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +12 -23
  46. package/src/features/layouts/chrome/ContentDragOverlay.tsx +5 -6
  47. package/src/features/layouts/chrome/DesktopChrome.tsx +37 -0
  48. package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +15 -4
  49. package/src/features/layouts/chrome/MacStrip.tsx +33 -0
  50. package/src/features/layouts/chrome/constants.ts +33 -8
  51. package/src/features/layouts/chrome/index.ts +8 -0
  52. package/src/features/layouts/chrome/stripDragMap.ts +35 -0
  53. package/src/features/layouts/chrome/stripNoDrag.spec.tsx +103 -0
  54. package/src/features/layouts/chrome/useScrollHideChrome.ts +3 -8
  55. package/src/features/layouts/filterNavigationForAuthState.spec.ts +5 -3
  56. package/src/features/layouts/floating/FloatingBottomDock.tsx +199 -20
  57. package/src/features/layouts/floating/FloatingLayout.tsx +13 -8
  58. package/src/features/layouts/floating/FloatingSidebar.tsx +144 -70
  59. package/src/features/layouts/floating/computeFloatingInsets.ts +22 -4
  60. package/src/features/layouts/floating/useFloatingChrome.ts +3 -1
  61. package/src/features/layouts/floating/useSoftKeyboard.spec.ts +39 -0
  62. package/src/features/layouts/floating/useSoftKeyboard.ts +82 -0
  63. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +38 -10
  64. package/src/features/layouts/sidebar/NavigationContent.tsx +14 -6
  65. package/src/features/layouts/sidebar/SidebarIcons.tsx +3 -9
  66. package/src/features/layouts/sidebar/SidebarInner.tsx +50 -39
  67. package/src/features/layouts/sidebar/SidebarLayout.tsx +8 -11
  68. package/src/features/layouts/utils.ts +4 -3
  69. package/src/features/layouts/windows/DesktopDots.tsx +76 -0
  70. package/src/features/layouts/windows/WindowsLayout.tsx +184 -125
  71. package/src/features/layouts/windows/deskDots.spec.ts +52 -0
  72. package/src/features/layouts/windows/deskDots.ts +314 -0
  73. package/src/features/settings/SettingsProvider.tsx +198 -29
  74. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +379 -4
  75. package/src/features/settings/utils/buildSettingsForPropagation.ts +65 -39
  76. package/src/features/theme/applyTheme.ts +8 -0
  77. package/src/features/theme/navContrast.spec.ts +49 -0
  78. package/src/features/theme/navContrast.ts +108 -0
  79. package/src/features/transfers/transferQueue.spec.ts +6 -2
  80. package/src/i18n/translations/en/common.json +27 -0
  81. package/src/i18n/translations/fr/common.json +27 -0
  82. package/src/index.css +935 -46
  83. package/src/index.ts +2 -0
  84. package/src/routes/hooks/useNavigationItems.ts +14 -3
  85. package/src/routes/hooks/withShellSearch.spec.ts +13 -0
@@ -1,5 +1,7 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
2
  import type { Settings } from '@shellui/sdk';
3
+ import type { AuthSession } from '../../auth/types';
4
+ import { frameAuthPropagationOptions } from '../../auth/appBackend/frameAuth';
3
5
  import type { ShellUIConfig } from '../../config/types';
4
6
  import { buildSettingsForPropagation } from './buildSettingsForPropagation';
5
7
 
@@ -285,25 +287,26 @@ describe('buildSettingsForPropagation', () => {
285
287
  expect(result.email).toEqual({ url: 'http://localhost:8003' });
286
288
  });
287
289
 
288
- it('uses the production email url when email is set without url', () => {
290
+ it('sends no email when email is set without url (no built-in default)', () => {
289
291
  const config = {
290
292
  email: {},
291
293
  } as ShellUIConfig;
292
294
 
293
295
  const result = buildSettingsForPropagation(baseSettings, config, 'en');
294
- expect(result.email).toEqual({ url: 'https://email.shellui.com' });
296
+ expect(result.email).toBeNull();
295
297
  });
296
298
 
297
- it('propagates showInAdmin false for email and keeps the default url', () => {
299
+ it('propagates showInAdmin false for email', () => {
298
300
  const config = {
299
301
  email: {
302
+ url: 'http://localhost:8003',
300
303
  showInAdmin: false,
301
304
  },
302
305
  } as ShellUIConfig;
303
306
 
304
307
  const result = buildSettingsForPropagation(baseSettings, config, 'en');
305
308
  expect(result.email).toEqual({
306
- url: 'https://email.shellui.com',
309
+ url: 'http://localhost:8003',
307
310
  showInAdmin: false,
308
311
  });
309
312
  });
@@ -319,4 +322,376 @@ describe('buildSettingsForPropagation', () => {
319
322
  const result = buildSettingsForPropagation(baseSettings, config, 'en');
320
323
  expect(result.email).toEqual({ url: 'https://email.shellui.com' });
321
324
  });
325
+
326
+ const shellToken = 'shell-access-token';
327
+ const foreignToken = 'foreign-access-token';
328
+ const shellUser = {
329
+ id: 'shell-user',
330
+ email: 'shell@example.com',
331
+ name: 'Shell User',
332
+ profilePicture: null,
333
+ authProvider: 'google',
334
+ isStaff: true,
335
+ };
336
+
337
+ const appConfig = {
338
+ backend: {
339
+ type: 'shellui' as const,
340
+ url: 'https://id.example.com/',
341
+ companyId: 1,
342
+ adminUrl: 'https://admin.example/',
343
+ login: { oauthProviders: ['google'] },
344
+ },
345
+ storage: { url: 'https://files-api.example', filesUrl: 'https://files.example/' },
346
+ email: { url: 'https://email.example' },
347
+ hosting: { url: 'https://hosting.example/', app: 'shell-app' },
348
+ navigation: [
349
+ {
350
+ label: 'Billing',
351
+ path: 'billing',
352
+ url: 'https://billing.example/',
353
+ safeForAuthToken: true,
354
+ },
355
+ {
356
+ label: 'Directory',
357
+ path: 'directory',
358
+ url: 'https://directory.example/',
359
+ safeForAuthToken: true,
360
+ backend: {
361
+ url: 'https://id.directory.example/',
362
+ companyId: 4,
363
+ provider: 'google',
364
+ },
365
+ },
366
+ {
367
+ label: 'Public directory',
368
+ path: 'public-directory',
369
+ url: 'https://public.example/',
370
+ backend: { url: 'https://id.public.example' },
371
+ },
372
+ ],
373
+ } as ShellUIConfig;
374
+
375
+ const foreignSession = {
376
+ accessToken: foreignToken,
377
+ refreshToken: 'foreign-refresh',
378
+ tokenType: 'bearer',
379
+ expiresAt: 4_000_000_000,
380
+ provider: 'google',
381
+ userId: 'foreign-user',
382
+ userEmail: 'foreign@example.com',
383
+ userName: 'Foreign User',
384
+ userAvatarUrl: null,
385
+ userIsStaff: false,
386
+ userIsCompanyOwner: true,
387
+ userGroups: ['directory'],
388
+ } satisfies AuthSession;
389
+
390
+ const propagate = (frameSrc: string, session: AuthSession | null = foreignSession) => {
391
+ const options = frameAuthPropagationOptions({
392
+ frameSrc,
393
+ config: appConfig,
394
+ shellAccessToken: shellToken,
395
+ getAppSession: () => session,
396
+ shellOrigin: 'https://shell.example',
397
+ });
398
+ return buildSettingsForPropagation(
399
+ { ...baseSettings, user: shellUser },
400
+ appConfig,
401
+ 'en',
402
+ options,
403
+ );
404
+ };
405
+
406
+ const shellServices = {
407
+ storage: { url: 'https://files-api.example', filesUrl: 'https://files.example/' },
408
+ email: { url: 'https://email.example' },
409
+ hosting: { url: 'https://hosting.example', app: 'shell-app' },
410
+ };
411
+
412
+ const expectNoShellServices = (result: ReturnType<typeof propagate>) => {
413
+ expect(result.storage).toBeNull();
414
+ expect(result.email).toBeNull();
415
+ expect(result.hosting).toBeNull();
416
+ const json = JSON.stringify(result);
417
+ expect(json).not.toContain('https://files-api.example');
418
+ expect(json).not.toContain('https://files.example');
419
+ expect(json).not.toContain('https://email.example');
420
+ expect(json).not.toContain('https://hosting.example');
421
+ expect(json).not.toContain('https://email.shellui.com');
422
+ };
423
+
424
+ it('falls back to the shell backend and token when the app has no override', () => {
425
+ const result = propagate('https://billing.example/');
426
+ expect(result.accessToken).toBe(shellToken);
427
+ expect(result.authBackendBaseUrl).toBe('https://id.example.com');
428
+ expect(result.user?.email).toBe('shell@example.com');
429
+ expect(result.storage).toEqual(shellServices.storage);
430
+ expect(result.email).toEqual(shellServices.email);
431
+ expect(result.hosting).toEqual(shellServices.hosting);
432
+ });
433
+
434
+ it('sends each foreign app its own backend URL and token', () => {
435
+ const result = propagate('https://directory.example/people');
436
+ expect(result.accessToken).toBe(foreignToken);
437
+ expect(result.authBackendBaseUrl).toBe('https://id.directory.example');
438
+ expect(result.user).toMatchObject({
439
+ id: 'foreign-user',
440
+ email: 'foreign@example.com',
441
+ groups: ['directory'],
442
+ });
443
+ expect(JSON.stringify(result)).not.toContain(shellToken);
444
+ expect(JSON.stringify(result)).not.toContain('shell@example.com');
445
+ expect(result).not.toHaveProperty('refreshToken');
446
+ expectNoShellServices(result);
447
+ });
448
+
449
+ it('sends a null token, not the shell token, when the foreign session is missing', () => {
450
+ const result = propagate('https://directory.example/', null);
451
+ expect(result.accessToken).toBeNull();
452
+ expect(result.authBackendBaseUrl).toBe('https://id.directory.example');
453
+ expect(result.user).toBeNull();
454
+ expect(JSON.stringify(result)).not.toContain(shellToken);
455
+ expectNoShellServices(result);
456
+ });
457
+
458
+ it('does not send either token to an untrusted app on another identity server', () => {
459
+ const result = propagate('https://public.example/');
460
+ expect(result.accessToken).toBeNull();
461
+ expect(result.authBackendBaseUrl).toBe('https://id.public.example');
462
+ expect(JSON.stringify(result)).not.toContain(shellToken);
463
+ expect(JSON.stringify(result)).not.toContain(foreignToken);
464
+ expectNoShellServices(result);
465
+ });
466
+
467
+ it('keeps the shell token for the built-in admin and storage frames', () => {
468
+ const admin = propagate('https://admin.example/#/users');
469
+ const files = propagate('https://files.example/company/docs');
470
+ expect(admin.accessToken).toBe(shellToken);
471
+ expect(admin.authBackendBaseUrl).toBe('https://id.example.com');
472
+ expect(files.accessToken).toBe(shellToken);
473
+ expect(files.authBackendBaseUrl).toBe('https://id.example.com');
474
+ expect(admin.storage).toEqual(shellServices.storage);
475
+ expect(admin.email).toEqual(shellServices.email);
476
+ expect(files.hosting).toEqual(shellServices.hosting);
477
+ });
478
+
479
+ it('keeps the shell token for shell settings even if a root item names another server', () => {
480
+ vi.stubGlobal('window', {
481
+ location: { origin: 'https://shell.example' },
482
+ matchMedia: () => ({ matches: false }),
483
+ });
484
+ const withRoot = {
485
+ ...appConfig,
486
+ navigation: [
487
+ ...(appConfig.navigation ?? []),
488
+ {
489
+ label: 'Home',
490
+ path: 'home',
491
+ url: 'https://shell.example/',
492
+ safeForAuthToken: true,
493
+ backend: { url: 'https://id.other.example' },
494
+ },
495
+ ],
496
+ } as ShellUIConfig;
497
+ const options = frameAuthPropagationOptions({
498
+ frameSrc: 'https://shell.example/__settings/storage',
499
+ config: withRoot,
500
+ shellAccessToken: shellToken,
501
+ getAppSession: () => foreignSession,
502
+ shellOrigin: 'https://shell.example',
503
+ });
504
+ const result = buildSettingsForPropagation(
505
+ { ...baseSettings, user: shellUser },
506
+ withRoot,
507
+ 'en',
508
+ options,
509
+ );
510
+ expect(result.accessToken).toBe(shellToken);
511
+ expect(result.authBackendBaseUrl).toBe('https://id.example.com');
512
+ expect(result.user?.email).toBe('shell@example.com');
513
+ expect(result.storage).toEqual(shellServices.storage);
514
+ expect(result.email).toEqual(shellServices.email);
515
+ expect(result.hosting).toEqual(shellServices.hosting);
516
+ });
517
+
518
+ it('sends a foreign app its own service URLs and not the shell URLs', () => {
519
+ const withServices = {
520
+ ...appConfig,
521
+ navigation: (appConfig.navigation ?? []).map((item) =>
522
+ item.path === 'directory'
523
+ ? {
524
+ ...item,
525
+ email: { url: 'https://email.directory.example/' },
526
+ storage: {
527
+ url: 'https://files-api.directory.example',
528
+ filesUrl: 'https://files.directory.example/',
529
+ },
530
+ hosting: { url: 'https://hosting.directory.example', showInAdmin: false },
531
+ }
532
+ : item,
533
+ ),
534
+ } as ShellUIConfig;
535
+ const options = frameAuthPropagationOptions({
536
+ frameSrc: 'https://directory.example/people',
537
+ config: withServices,
538
+ shellAccessToken: shellToken,
539
+ getAppSession: () => foreignSession,
540
+ shellOrigin: 'https://shell.example',
541
+ });
542
+ const result = buildSettingsForPropagation(
543
+ { ...baseSettings, user: shellUser },
544
+ withServices,
545
+ 'en',
546
+ options,
547
+ );
548
+ expect(result.storage).toEqual({
549
+ url: 'https://files-api.directory.example',
550
+ filesUrl: 'https://files.directory.example/',
551
+ });
552
+ expect(result.email).toEqual({ url: 'https://email.directory.example' });
553
+ expect(result.hosting).toEqual({
554
+ url: 'https://hosting.directory.example',
555
+ showInAdmin: false,
556
+ });
557
+ const json = JSON.stringify(result);
558
+ expect(json).not.toContain('https://files-api.example');
559
+ expect(json).not.toContain('https://email.example');
560
+ expect(json).not.toContain('https://hosting.example');
561
+ expect(json).not.toContain('https://email.shellui.com');
562
+ });
563
+
564
+ it('sends no email when a foreign app sets an empty email object', () => {
565
+ const withEmptyEmail = {
566
+ ...appConfig,
567
+ navigation: (appConfig.navigation ?? []).map((item) =>
568
+ item.path === 'directory' ? { ...item, email: {} } : item,
569
+ ),
570
+ } as ShellUIConfig;
571
+ const options = frameAuthPropagationOptions({
572
+ frameSrc: 'https://directory.example/',
573
+ config: withEmptyEmail,
574
+ shellAccessToken: shellToken,
575
+ getAppSession: () => foreignSession,
576
+ shellOrigin: 'https://shell.example',
577
+ });
578
+ const result = buildSettingsForPropagation(
579
+ { ...baseSettings, user: shellUser },
580
+ withEmptyEmail,
581
+ 'en',
582
+ options,
583
+ );
584
+ expect(result.email).toBeNull();
585
+ expect(result.storage).toBeNull();
586
+ expect(result.hosting).toBeNull();
587
+ const json = JSON.stringify(result);
588
+ expect(json).not.toContain('https://files-api.example');
589
+ expect(json).not.toContain('https://email.example');
590
+ expect(json).not.toContain('https://hosting.example');
591
+ });
592
+
593
+ it('replaces only the service an app sets when it keeps the shell backend', () => {
594
+ const withEmail = {
595
+ ...appConfig,
596
+ navigation: [
597
+ ...(appConfig.navigation ?? []),
598
+ {
599
+ label: 'Mail',
600
+ path: 'mail',
601
+ url: 'https://mail.example/',
602
+ safeForAuthToken: true,
603
+ email: {},
604
+ },
605
+ ],
606
+ } as ShellUIConfig;
607
+ const options = frameAuthPropagationOptions({
608
+ frameSrc: 'https://mail.example/',
609
+ config: withEmail,
610
+ shellAccessToken: shellToken,
611
+ getAppSession: () => foreignSession,
612
+ shellOrigin: 'https://shell.example',
613
+ });
614
+ const result = buildSettingsForPropagation(
615
+ { ...baseSettings, user: shellUser },
616
+ withEmail,
617
+ 'en',
618
+ options,
619
+ );
620
+ expect(result.accessToken).toBe(shellToken);
621
+ expect(result.authBackendBaseUrl).toBe('https://id.example.com');
622
+ expect(result.email).toBeNull();
623
+ expect(result.storage).toEqual(shellServices.storage);
624
+ expect(result.hosting).toEqual(shellServices.hosting);
625
+ });
626
+
627
+ it('keeps shell services when the item backend is the same server', () => {
628
+ const sameServer = {
629
+ ...appConfig,
630
+ navigation: [
631
+ ...(appConfig.navigation ?? []),
632
+ {
633
+ label: 'Same',
634
+ path: 'same',
635
+ url: 'https://same.example/',
636
+ safeForAuthToken: true,
637
+ backend: { url: 'https://id.example.com/', companyId: 1 },
638
+ },
639
+ ],
640
+ } as ShellUIConfig;
641
+ const options = frameAuthPropagationOptions({
642
+ frameSrc: 'https://same.example/',
643
+ config: sameServer,
644
+ shellAccessToken: shellToken,
645
+ getAppSession: () => foreignSession,
646
+ shellOrigin: 'https://shell.example',
647
+ });
648
+ const result = buildSettingsForPropagation(
649
+ { ...baseSettings, user: shellUser },
650
+ sameServer,
651
+ 'en',
652
+ options,
653
+ );
654
+ expect(result.accessToken).toBe(shellToken);
655
+ expect(result.storage).toEqual(shellServices.storage);
656
+ expect(result.email).toEqual(shellServices.email);
657
+ expect(result.hosting).toEqual(shellServices.hosting);
658
+ });
659
+
660
+ it('sends no service URLs when the named backend cannot be used', () => {
661
+ const invalid = {
662
+ ...appConfig,
663
+ navigation: [
664
+ ...(appConfig.navigation ?? []),
665
+ {
666
+ label: 'Broken',
667
+ path: 'broken',
668
+ url: 'https://broken.example/',
669
+ safeForAuthToken: true,
670
+ backend: { url: 'not-a-url' },
671
+ email: { url: 'https://email.broken.example' },
672
+ },
673
+ ],
674
+ } as ShellUIConfig;
675
+ const options = frameAuthPropagationOptions({
676
+ frameSrc: 'https://broken.example/',
677
+ config: invalid,
678
+ shellAccessToken: shellToken,
679
+ getAppSession: () => foreignSession,
680
+ shellOrigin: 'https://shell.example',
681
+ });
682
+ const result = buildSettingsForPropagation(
683
+ { ...baseSettings, user: shellUser },
684
+ invalid,
685
+ 'en',
686
+ options,
687
+ );
688
+ expect(result.accessToken).toBeNull();
689
+ expect(result.email).toEqual({ url: 'https://email.broken.example' });
690
+ expect(result.storage).toBeNull();
691
+ expect(result.hosting).toBeNull();
692
+ const json = JSON.stringify(result);
693
+ expect(json).not.toContain('https://files-api.example');
694
+ expect(json).not.toContain('https://hosting.example');
695
+ expect(json).not.toContain(shellToken);
696
+ });
322
697
  });
@@ -1,5 +1,11 @@
1
- import type { Settings, SettingsEmail, SettingsNavigationItem } from '@shellui/sdk';
2
- import type { ShellUIConfig } from '../../config/types';
1
+ import type {
2
+ Settings,
3
+ SettingsEmail,
4
+ SettingsHosting,
5
+ SettingsNavigationItem,
6
+ SettingsStorage,
7
+ } from '@shellui/sdk';
8
+ import type { EmailConfig, HostingConfig, ShellUIConfig, StorageConfig } from '../../config/types';
3
9
  import { flattenNavigationItems } from './flattenNavigationItems';
4
10
  import { getAvailableThemesForSettings } from './getAvailableThemesForSettings';
5
11
  import { getResolvedAppearanceForSettings } from './getResolvedAppearanceForSettings';
@@ -9,15 +15,34 @@ import {
9
15
  getPublishedLayoutChrome,
10
16
  } from '../../layouts/floating/layoutChromeStore';
11
17
 
12
- /** Production email-service origin. No trailing slash. */
13
- const DEFAULT_EMAIL_SERVICE_URL = 'https://email.shellui.com';
14
-
15
- const propagateEmail = (email: ShellUIConfig['email']): SettingsEmail | null => {
16
- if (!email) return null;
17
- const url = email.url?.trim().replace(/\/+$/, '') || DEFAULT_EMAIL_SERVICE_URL;
18
+ const propagateEmail = (email: EmailConfig | null | undefined): SettingsEmail | null => {
19
+ // No built-in default: email must come from config or the host app.
20
+ const url = email?.url?.trim().replace(/\/+$/, '') || null;
21
+ if (!url) return null;
18
22
  return {
19
23
  url,
20
- ...(email.showInAdmin === false ? { showInAdmin: false } : {}),
24
+ ...(email?.showInAdmin === false ? { showInAdmin: false } : {}),
25
+ };
26
+ };
27
+
28
+ const propagateStorage = (storage: StorageConfig | null | undefined): SettingsStorage | null => {
29
+ const storageUrl = storage?.url?.trim().replace(/\/+$/, '') || null;
30
+ if (!storageUrl) return null;
31
+ const filesUrl = storage?.filesUrl?.trim() || null;
32
+ return {
33
+ url: storageUrl,
34
+ ...(filesUrl ? { filesUrl } : {}),
35
+ };
36
+ };
37
+
38
+ const propagateHosting = (hosting: HostingConfig | null | undefined): SettingsHosting | null => {
39
+ const hostingUrl = hosting?.url?.trim().replace(/\/+$/, '') || null;
40
+ if (!hostingUrl) return null;
41
+ const app = hosting?.app?.trim() || null;
42
+ return {
43
+ url: hostingUrl,
44
+ ...(app ? { app } : {}),
45
+ ...(hosting?.showInAdmin === false ? { showInAdmin: false } : {}),
21
46
  };
22
47
  };
23
48
 
@@ -32,6 +57,22 @@ export const buildSettingsForPropagation = (
32
57
  options?: {
33
58
  includeAuthAccessToken?: boolean;
34
59
  accessToken?: string | null;
60
+ /**
61
+ * Identity base URL for this frame. When the key is set, it replaces the shell
62
+ * `backend` URL (`null` when that server is not a Shellui identity backend).
63
+ */
64
+ authBackendBaseUrl?: string | null;
65
+ /** User for this frame's identity server. When the key is set, it replaces `settings.user`. */
66
+ settingsUser?: Settings['user'];
67
+ /**
68
+ * Storage for this frame. When the key is set, it replaces the shell `storage`
69
+ * (`null` sends no storage URL).
70
+ */
71
+ storage?: StorageConfig | null;
72
+ /** Email for this frame. When the key is set, it replaces the shell `email`. */
73
+ email?: EmailConfig | null;
74
+ /** Hosting for this frame. When the key is set, it replaces the shell `hosting`. */
75
+ hosting?: HostingConfig | null;
35
76
  /** When false, omit layoutChrome (modal / drawer frames). Default true. */
36
77
  includeLayoutChrome?: boolean;
37
78
  /** Merge this frame's action-bar insets into layoutChrome. */
@@ -42,6 +83,7 @@ export const buildSettingsForPropagation = (
42
83
  let result: Settings = {
43
84
  ...settings,
44
85
  appearance: appearance ?? settings.appearance,
86
+ ...(options && 'settingsUser' in options ? { user: options.settingsUser ?? null } : {}),
45
87
  };
46
88
 
47
89
  if (options?.includeLayoutChrome !== false) {
@@ -101,41 +143,25 @@ export const buildSettingsForPropagation = (
101
143
  result = { ...result, administration: null };
102
144
  }
103
145
 
104
- const storageUrl = config?.storage?.url?.trim().replace(/\/+$/, '') || null;
105
- if (storageUrl) {
106
- const filesUrl = config.storage?.filesUrl?.trim() || null;
107
- result = {
108
- ...result,
109
- storage: {
110
- url: storageUrl,
111
- ...(filesUrl ? { filesUrl } : {}),
112
- },
113
- };
114
- } else {
115
- result = { ...result, storage: null };
116
- }
146
+ const storageSource = options && 'storage' in options ? options.storage : config?.storage;
147
+ const hostingSource = options && 'hosting' in options ? options.hosting : config?.hosting;
148
+ const emailSource = options && 'email' in options ? options.email : config?.email;
117
149
 
118
- const hostingUrl = config?.hosting?.url?.trim().replace(/\/+$/, '') || null;
119
- if (hostingUrl) {
120
- const app = config.hosting?.app?.trim() || null;
121
- result = {
122
- ...result,
123
- hosting: {
124
- url: hostingUrl,
125
- ...(app ? { app } : {}),
126
- ...(config.hosting?.showInAdmin === false ? { showInAdmin: false } : {}),
127
- },
128
- };
129
- } else {
130
- result = { ...result, hosting: null };
131
- }
132
-
133
- result = { ...result, email: propagateEmail(config?.email) };
150
+ result = {
151
+ ...result,
152
+ storage: propagateStorage(storageSource),
153
+ hosting: propagateHosting(hostingSource),
154
+ email: propagateEmail(emailSource),
155
+ };
134
156
 
135
- const authBackendBaseUrl =
157
+ const shellAuthBackendBaseUrl =
136
158
  config?.backend?.type === 'shellui' && config.backend.url?.trim()
137
159
  ? config.backend.url.trim().replace(/\/+$/, '')
138
160
  : null;
161
+ const authBackendBaseUrl =
162
+ options && 'authBackendBaseUrl' in options
163
+ ? (options.authBackendBaseUrl ?? null)
164
+ : shellAuthBackendBaseUrl;
139
165
 
140
166
  result = {
141
167
  ...result,
@@ -1,6 +1,7 @@
1
1
  import { toCssVarValue } from './color';
2
2
  import type { ThemeColorsMode, ThemeDefinition } from './types';
3
3
  import { isHomeScreenPwa, isTauriRuntime } from '../layouts/chrome/runtime';
4
+ import { isLowNavContrast, NAV_CONTRAST_ATTR } from './navContrast';
4
5
 
5
6
  const COLOR_VAR_MAP: Array<[keyof ThemeColorsMode, string]> = [
6
7
  ['background', '--background'],
@@ -95,6 +96,13 @@ export function applyTheme(theme: ThemeDefinition, isDark: boolean): void {
95
96
 
96
97
  root.style.setProperty('--radius', colors.radius);
97
98
 
99
+ // Solid active pill under 4.5:1 in this mode: chrome switches to a tinted pill.
100
+ if (isLowNavContrast(colors.sidebarPrimary, colors.sidebarPrimaryForeground)) {
101
+ root.setAttribute(NAV_CONTRAST_ATTR, 'low');
102
+ } else {
103
+ root.removeAttribute(NAV_CONTRAST_ATTR);
104
+ }
105
+
98
106
  // Browser-tab chrome only — see syncThemeColorMeta (skipped for PWA / Tauri).
99
107
  syncThemeColorMeta(toCssVarValue(colors.background) || (isDark ? '#000000' : '#ffffff'));
100
108
 
@@ -0,0 +1,49 @@
1
+ // @vitest-environment happy-dom
2
+ import { describe, expect, it } from 'vitest';
3
+ import { contrastRatio, isLowNavContrast, parseThemeColor } from './navContrast';
4
+ import { curatedThemes } from './themes';
5
+ import { applyTheme } from './applyTheme';
6
+
7
+ describe('navContrast', () => {
8
+ it('parses oklch, hex and hsl', () => {
9
+ expect(parseThemeColor('oklch(1 0 0)')).toEqual([1, 1, 1]);
10
+ expect(parseThemeColor('#000000')).toEqual([0, 0, 0]);
11
+ expect(parseThemeColor('0 0% 100%')?.map((n) => Math.round(n))).toEqual([1, 1, 1]);
12
+ expect(parseThemeColor('hsl(0 0% 0%)')).toEqual([0, 0, 0]);
13
+ expect(parseThemeColor('var(--x)')).toBeNull();
14
+ });
15
+
16
+ it('computes WCAG ratios', () => {
17
+ expect(contrastRatio('#000000', '#ffffff')).toBeCloseTo(21, 1);
18
+ expect(contrastRatio('nope', '#ffffff')).toBeNull();
19
+ expect(isLowNavContrast('nope', '#ffffff')).toBe(false);
20
+ });
21
+
22
+ it('keeps the solid pill on shellui and flags the low curated modes (37 from the audit, plus quantum-rose light at 4.497:1)', () => {
23
+ const low: string[] = [];
24
+ for (const theme of curatedThemes) {
25
+ for (const mode of ['light', 'dark'] as const) {
26
+ const c = theme.colors[mode];
27
+ if (isLowNavContrast(c.sidebarPrimary, c.sidebarPrimaryForeground)) {
28
+ low.push(`${theme.name}:${mode}`);
29
+ }
30
+ }
31
+ }
32
+ expect(low).not.toContain('shellui:light');
33
+ expect(low).not.toContain('shellui:dark');
34
+ expect(low).toContain('twitter:light');
35
+ expect(low).toContain('amber-minimal:dark');
36
+ expect(low).toContain('quantum-rose:light');
37
+ expect(low).toHaveLength(38);
38
+ });
39
+
40
+ it('applyTheme sets and clears the attribute on <html>', () => {
41
+ const twitter = curatedThemes.find((t) => t.name === 'twitter');
42
+ const shellui = curatedThemes.find((t) => t.name === 'shellui');
43
+ if (!twitter || !shellui) throw new Error('curated themes twitter and shellui are required');
44
+ applyTheme({ ...twitter, fontFiles: [] }, false);
45
+ expect(document.documentElement.getAttribute('data-shellui-nav-contrast')).toBe('low');
46
+ applyTheme({ ...shellui, fontFiles: [] }, false);
47
+ expect(document.documentElement.hasAttribute('data-shellui-nav-contrast')).toBe(false);
48
+ });
49
+ });