@shellui/core 0.7.0-alpha.1 → 0.7.0-alpha.11

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 (94) hide show
  1. package/package.json +2 -2
  2. package/schemas/shellui.config.schema.json +37 -4
  3. package/src/components/ContentView.tsx +19 -8
  4. package/src/components/ui/drawer.tsx +47 -30
  5. package/src/components/ui/sheet.tsx +18 -12
  6. package/src/components/ui/sidebar.tsx +25 -11
  7. package/src/components/ui/tooltip.tsx +4 -2
  8. package/src/features/admin/AdminView.tsx +9 -6
  9. package/src/features/auth/AuthProvider.tsx +25 -4
  10. package/src/features/auth/appBackend/appBackendSessions.spec.ts +134 -0
  11. package/src/features/auth/appBackend/appBackendSessions.ts +168 -17
  12. package/src/features/auth/appBackend/childFrames.spec.ts +328 -0
  13. package/src/features/auth/appBackend/childFrames.ts +180 -0
  14. package/src/features/auth/appBackend/frameAuth.ts +47 -10
  15. package/src/features/auth/appBackend/silentSignIn.spec.ts +18 -0
  16. package/src/features/auth/appBackend/silentSignIn.ts +15 -1
  17. package/src/features/auth/appBackend/tokenExchange.spec.ts +98 -0
  18. package/src/features/auth/appBackend/tokenExchange.ts +76 -0
  19. package/src/features/auth/components/LoginButton.spec.tsx +155 -0
  20. package/src/features/auth/components/LoginButton.tsx +52 -27
  21. package/src/features/auth/components/LoginButtonIcons.tsx +4 -8
  22. package/src/features/auth/components/OAuthCallbackView.tsx +7 -5
  23. package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +42 -1
  24. package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +23 -0
  25. package/src/features/auth/utils/canRestoreStoredSession.spec.ts +29 -0
  26. package/src/features/auth/utils/canRestoreStoredSession.ts +12 -0
  27. package/src/features/auth/utils/index.ts +7 -1
  28. package/src/features/auth/utils/resolveSdkLoginRedirectPath.spec.ts +41 -0
  29. package/src/features/auth/utils/resolveSdkLoginRedirectPath.ts +31 -0
  30. package/src/features/auth/utils/webPkce.spec.ts +23 -0
  31. package/src/features/auth/utils/webPkce.ts +23 -6
  32. package/src/features/chromeActions/ChromeActionsHost.tsx +5 -1
  33. package/src/features/chromeActions/computeActionInsets.ts +7 -4
  34. package/src/features/config/types.ts +30 -4
  35. package/src/features/layouts/OverlayShell.tsx +58 -40
  36. package/src/features/layouts/appbar/AppBarItemIcon.spec.tsx +45 -0
  37. package/src/features/layouts/appbar/AppBarItemIcon.tsx +19 -0
  38. package/src/features/layouts/appbar/AppBarLayout.tsx +115 -110
  39. package/src/features/layouts/appbar/appBarOverflow.spec.ts +27 -0
  40. package/src/features/layouts/appbar/appBarOverflow.ts +42 -0
  41. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +13 -24
  42. package/src/features/layouts/chrome/ContentDragOverlay.tsx +5 -6
  43. package/src/features/layouts/chrome/DesktopChrome.tsx +37 -0
  44. package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +15 -4
  45. package/src/features/layouts/chrome/MacStrip.tsx +33 -0
  46. package/src/features/layouts/chrome/constants.ts +36 -8
  47. package/src/features/layouts/chrome/index.ts +8 -0
  48. package/src/features/layouts/chrome/stripDragMap.ts +35 -0
  49. package/src/features/layouts/chrome/stripNoDrag.spec.tsx +103 -0
  50. package/src/features/layouts/chrome/useScrollHideChrome.ts +3 -8
  51. package/src/features/layouts/chrome/viewport.ts +11 -4
  52. package/src/features/layouts/filterNavigationForAuthState.spec.ts +5 -3
  53. package/src/features/layouts/floating/FloatingBottomDock.tsx +263 -43
  54. package/src/features/layouts/floating/FloatingLayout.tsx +14 -8
  55. package/src/features/layouts/floating/FloatingSidebar.tsx +165 -73
  56. package/src/features/layouts/floating/computeFloatingInsets.ts +22 -4
  57. package/src/features/layouts/floating/moreSections.spec.ts +28 -0
  58. package/src/features/layouts/floating/moreSections.ts +31 -0
  59. package/src/features/layouts/floating/useFloatingChrome.ts +3 -1
  60. package/src/features/layouts/floating/useSoftKeyboard.spec.ts +39 -0
  61. package/src/features/layouts/floating/useSoftKeyboard.ts +82 -0
  62. package/src/features/layouts/fullscreen/FullscreenLayout.spec.tsx +68 -0
  63. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +47 -10
  64. package/src/features/layouts/sidebar/NavigationContent.tsx +17 -9
  65. package/src/features/layouts/sidebar/SidebarIcons.tsx +70 -9
  66. package/src/features/layouts/sidebar/SidebarInner.spec.tsx +109 -0
  67. package/src/features/layouts/sidebar/SidebarInner.tsx +94 -43
  68. package/src/features/layouts/sidebar/SidebarLayout.tsx +24 -17
  69. package/src/features/layouts/utils.ts +4 -3
  70. package/src/features/layouts/windows/DesktopDots.tsx +76 -0
  71. package/src/features/layouts/windows/WindowsLayout.tsx +251 -161
  72. package/src/features/layouts/windows/deskDots.spec.ts +54 -0
  73. package/src/features/layouts/windows/deskDots.ts +314 -0
  74. package/src/features/overlays/ResponsiveModal.tsx +5 -3
  75. package/src/features/overlays/overlaySize.spec.ts +56 -16
  76. package/src/features/overlays/overlaySize.ts +114 -31
  77. package/src/features/overlays/phoneDrawerAnchoring.spec.ts +187 -0
  78. package/src/features/overlays/useOverlayReportedSize.ts +8 -3
  79. package/src/features/settings/SettingsProvider.tsx +158 -2
  80. package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +8 -7
  81. package/src/features/settings/utils/buildSettingsForPropagation.ts +4 -6
  82. package/src/features/theme/applyTheme.ts +8 -0
  83. package/src/features/theme/navContrast.spec.ts +49 -0
  84. package/src/features/theme/navContrast.ts +108 -0
  85. package/src/features/transfers/transferQueue.spec.ts +6 -2
  86. package/src/i18n/translations/en/common.json +26 -0
  87. package/src/i18n/translations/fr/common.json +26 -0
  88. package/src/index.css +1145 -77
  89. package/src/index.ts +1 -0
  90. package/src/routes/hooks/useNavigationItems.ts +14 -3
  91. package/src/routes/hooks/withShellSearch.spec.ts +13 -0
  92. package/src/service-worker/devCaches.spec.ts +32 -0
  93. package/src/service-worker/devCaches.ts +27 -0
  94. package/src/service-worker/sw-dev.ts +23 -23
@@ -0,0 +1,328 @@
1
+ import { afterEach, describe, expect, it } from 'vitest';
2
+ import type { ShellUIConfig } from '../../config/types';
3
+ import {
4
+ addChildFrame,
5
+ clearChildFrames,
6
+ findChildFrame,
7
+ listChildFrames,
8
+ removeChildFrame,
9
+ validateChildFrameRegistration,
10
+ } from './childFrames';
11
+ import { childFrameAuthPropagationOptions } from './frameAuth';
12
+ import type { AuthSession } from '../types';
13
+
14
+ const config: ShellUIConfig = {
15
+ backend: { type: 'shellui', url: 'https://id.example.com', companyId: 1 },
16
+ navigation: [
17
+ {
18
+ label: 'Dashboard',
19
+ path: '',
20
+ url: 'https://dashboard.example.com/',
21
+ safeForAuthToken: true,
22
+ childFrames: {
23
+ origins: ['https://admin.example.com', 'https://*.example.com', '*'],
24
+ backendOrigins: ['https://id.eu.example.com'],
25
+ },
26
+ },
27
+ { label: 'Other', path: 'other', url: 'https://other.example.com/' },
28
+ ],
29
+ };
30
+
31
+ const host = 'https://dashboard.example.com/';
32
+ const good = {
33
+ frameId: 'child-1',
34
+ url: 'https://admin.example.com/companies?x=1',
35
+ backend: { url: 'https://id.eu.example.com', companyId: 'abc' },
36
+ };
37
+
38
+ afterEach(() => clearChildFrames());
39
+
40
+ describe('validateChildFrameRegistration', () => {
41
+ it('accepts an allowed child and backend', () => {
42
+ const result = validateChildFrameRegistration({
43
+ from: ['h1'],
44
+ hostSrc: host,
45
+ payload: good,
46
+ config,
47
+ });
48
+ expect(result.ok).toBe(true);
49
+ if (!result.ok) return;
50
+ expect(result.entry.hostUuid).toBe('h1');
51
+ expect(result.entry.identity?.url).toBe('https://id.eu.example.com');
52
+ expect(result.entry.identity?.companyId).toBe('abc');
53
+ });
54
+
55
+ it('rejects a message relayed from deeper than one hop', () => {
56
+ const result = validateChildFrameRegistration({
57
+ from: ['h1', 'child'],
58
+ hostSrc: host,
59
+ payload: good,
60
+ config,
61
+ });
62
+ expect(result).toEqual({ ok: false, reason: 'not sent by a direct app frame' });
63
+ });
64
+
65
+ it('rejects hosts without childFrames', () => {
66
+ const result = validateChildFrameRegistration({
67
+ from: ['h1'],
68
+ hostSrc: 'https://other.example.com/',
69
+ payload: good,
70
+ config,
71
+ });
72
+ expect(result.ok).toBe(false);
73
+ });
74
+
75
+ it('only matches exact origins, never wildcards', () => {
76
+ for (const url of [
77
+ 'https://evil.example.com/',
78
+ 'https://admin.example.com.evil.io/',
79
+ 'javascript:alert(1)',
80
+ ]) {
81
+ const result = validateChildFrameRegistration({
82
+ from: ['h1'],
83
+ hostSrc: host,
84
+ payload: { ...good, url },
85
+ config,
86
+ });
87
+ expect(result.ok).toBe(false);
88
+ }
89
+ });
90
+
91
+ it('rejects a backend that is not allowlisted', () => {
92
+ const result = validateChildFrameRegistration({
93
+ from: ['h1'],
94
+ hostSrc: host,
95
+ payload: { ...good, backend: { url: 'https://id.example.com' } },
96
+ config,
97
+ });
98
+ expect(result).toEqual({ ok: false, reason: 'child identity server is not allowed' });
99
+ });
100
+
101
+ it('accepts a child without backend and gives it no identity', () => {
102
+ const result = validateChildFrameRegistration({
103
+ from: ['h1'],
104
+ hostSrc: host,
105
+ payload: { ...good, backend: null },
106
+ config,
107
+ });
108
+ expect(result.ok && result.entry.identity).toBeNull();
109
+ });
110
+ });
111
+
112
+ describe('child frame registry', () => {
113
+ it('finds by host and child path, and drops entries for gone hosts', () => {
114
+ const result = validateChildFrameRegistration({
115
+ from: ['h1'],
116
+ hostSrc: host,
117
+ payload: good,
118
+ config,
119
+ });
120
+ if (!result.ok) throw new Error(result.reason);
121
+ addChildFrame(result.entry);
122
+ expect(findChildFrame(['h1', 'child-1'])).toBe(result.entry);
123
+ expect(findChildFrame(['h1'])).toBeNull();
124
+ expect(findChildFrame(['h2', 'child-1'])).toBeNull();
125
+ expect(listChildFrames(() => false)).toEqual([]);
126
+ expect(findChildFrame(['h1', 'child-1'])).toBeNull();
127
+ addChildFrame(result.entry);
128
+ removeChildFrame('h1', 'child-1');
129
+ expect(findChildFrame(['h1', 'child-1'])).toBeNull();
130
+ });
131
+ });
132
+
133
+ describe('childFrameAuthPropagationOptions', () => {
134
+ const session = {
135
+ accessToken: 'regional-token',
136
+ refreshToken: 'r',
137
+ expiresAt: 9999999999,
138
+ userId: 'u1',
139
+ userEmail: 'a@b.c',
140
+ userName: 'A',
141
+ } as AuthSession;
142
+
143
+ it('sends the regional session and backend, and no shared services', () => {
144
+ const result = validateChildFrameRegistration({
145
+ from: ['h1'],
146
+ hostSrc: host,
147
+ payload: good,
148
+ config,
149
+ });
150
+ if (!result.ok) throw new Error(result.reason);
151
+ const options = childFrameAuthPropagationOptions({
152
+ identity: result.entry.identity,
153
+ getAppSession: (key) => (key === result.entry.identity?.key ? session : null),
154
+ });
155
+ expect(options.accessToken).toBe('regional-token');
156
+ expect(options.authBackendBaseUrl).toBe('https://id.eu.example.com');
157
+ expect(options.settingsUser?.id).toBe('u1');
158
+ expect(options.storage).toBeNull();
159
+ expect(options.email).toBeNull();
160
+ expect(options.hosting).toBeNull();
161
+ });
162
+
163
+ it('sends no token when the child has no identity', () => {
164
+ const options = childFrameAuthPropagationOptions({
165
+ identity: null,
166
+ getAppSession: () => session,
167
+ });
168
+ expect(options.accessToken).toBeNull();
169
+ expect(options.includeAuthAccessToken).toBe(false);
170
+ expect(options.settingsUser).toBeNull();
171
+ });
172
+ });
173
+
174
+ describe('child frame service URLs', () => {
175
+ const withServices: ShellUIConfig = {
176
+ ...config,
177
+ navigation: [
178
+ {
179
+ label: 'Dashboard',
180
+ path: '',
181
+ url: 'https://dashboard.example.com/',
182
+ childFrames: {
183
+ origins: ['https://admin.example.com'],
184
+ backendOrigins: ['https://id.eu.example.com'],
185
+ serviceOrigins: [
186
+ 'https://email.eu.example.com',
187
+ 'https://storage.eu.example.com',
188
+ 'https://files.example.com',
189
+ 'https://*.example.com',
190
+ '*',
191
+ ],
192
+ },
193
+ },
194
+ ],
195
+ };
196
+ const register = (services: unknown, cfg: ShellUIConfig = withServices) =>
197
+ validateChildFrameRegistration({
198
+ from: ['h1'],
199
+ hostSrc: host,
200
+ payload: { ...good, services },
201
+ config: cfg,
202
+ });
203
+
204
+ it('forwards allowed service URLs to the child settings', () => {
205
+ const result = register({
206
+ email: 'https://email.eu.example.com/',
207
+ storage: 'https://storage.eu.example.com',
208
+ });
209
+ expect(result.ok).toBe(true);
210
+ if (!result.ok) return;
211
+ expect(result.entry.services).toEqual({
212
+ email: 'https://email.eu.example.com',
213
+ storage: 'https://storage.eu.example.com',
214
+ files: null,
215
+ hosting: null,
216
+ });
217
+ expect(result.entry.rejectedServices).toEqual([]);
218
+ const options = childFrameAuthPropagationOptions({
219
+ identity: result.entry.identity,
220
+ getAppSession: () => null,
221
+ services: result.entry.services,
222
+ });
223
+ expect(options.email).toEqual({ url: 'https://email.eu.example.com' });
224
+ expect(options.storage).toEqual({ url: 'https://storage.eu.example.com' });
225
+ expect(options.hosting).toBeNull();
226
+ });
227
+
228
+ it('drops a service URL whose origin is not allowed', () => {
229
+ const result = register({
230
+ storage: 'https://evil.example.org',
231
+ hosting: 'javascript:alert(1)',
232
+ });
233
+ expect(result.ok).toBe(true);
234
+ if (!result.ok) return;
235
+ expect(result.entry.services).toEqual({
236
+ email: null,
237
+ storage: null,
238
+ files: null,
239
+ hosting: null,
240
+ });
241
+ expect(result.entry.rejectedServices).toEqual(['storage', 'hosting']);
242
+ });
243
+
244
+ it('forwards an allowed files URL as storage.filesUrl', () => {
245
+ const result = register({
246
+ storage: 'https://storage.eu.example.com',
247
+ files: 'https://files.example.com/',
248
+ });
249
+ expect(result.ok).toBe(true);
250
+ if (!result.ok) return;
251
+ expect(result.entry.services.files).toBe('https://files.example.com');
252
+ const options = childFrameAuthPropagationOptions({
253
+ identity: result.entry.identity,
254
+ getAppSession: () => null,
255
+ services: result.entry.services,
256
+ });
257
+ expect(options.storage).toEqual({
258
+ url: 'https://storage.eu.example.com',
259
+ filesUrl: 'https://files.example.com',
260
+ });
261
+ });
262
+
263
+ it('drops a files URL whose origin is not allowed, or without storage', () => {
264
+ const rejected = register({
265
+ storage: 'https://storage.eu.example.com',
266
+ files: 'https://files.evil.example.org',
267
+ });
268
+ expect(rejected.ok).toBe(true);
269
+ if (!rejected.ok) return;
270
+ expect(rejected.entry.rejectedServices).toEqual(['files']);
271
+ expect(
272
+ childFrameAuthPropagationOptions({
273
+ identity: null,
274
+ getAppSession: () => null,
275
+ services: rejected.entry.services,
276
+ }).storage,
277
+ ).toEqual({ url: 'https://storage.eu.example.com' });
278
+ const alone = register({ files: 'https://files.example.com' });
279
+ if (!alone.ok) throw new Error('expected ok');
280
+ expect(
281
+ childFrameAuthPropagationOptions({
282
+ identity: null,
283
+ getAppSession: () => null,
284
+ services: alone.entry.services,
285
+ }).storage,
286
+ ).toBeNull();
287
+ });
288
+
289
+ it('never matches a wildcard entry', () => {
290
+ const result = register({ hosting: 'https://hosting.example.com' });
291
+ expect(result.ok).toBe(true);
292
+ if (!result.ok) return;
293
+ expect(result.entry.services.hosting).toBeNull();
294
+ expect(result.entry.rejectedServices).toEqual(['hosting']);
295
+ });
296
+
297
+ it('sends null for missing services, without falling back to the shell', () => {
298
+ const shellWithServices: ShellUIConfig = {
299
+ ...withServices,
300
+ email: { url: 'https://email.example.com' },
301
+ storage: { url: 'https://storage.example.com' },
302
+ hosting: { url: 'https://hosting.example.com' },
303
+ };
304
+ const result = register(undefined, shellWithServices);
305
+ expect(result.ok).toBe(true);
306
+ if (!result.ok) return;
307
+ expect(result.entry.services).toEqual({
308
+ email: null,
309
+ storage: null,
310
+ files: null,
311
+ hosting: null,
312
+ });
313
+ const options = childFrameAuthPropagationOptions({
314
+ identity: result.entry.identity,
315
+ getAppSession: () => null,
316
+ services: result.entry.services,
317
+ });
318
+ expect(options).toMatchObject({ email: null, storage: null, hosting: null });
319
+ });
320
+
321
+ it('drops every service URL when serviceOrigins is not configured', () => {
322
+ const result = register({ email: 'https://email.eu.example.com' }, config);
323
+ expect(result.ok).toBe(true);
324
+ if (!result.ok) return;
325
+ expect(result.entry.services.email).toBeNull();
326
+ expect(result.entry.rejectedServices).toEqual(['email']);
327
+ });
328
+ });
@@ -0,0 +1,180 @@
1
+ import type { ShellUIConfig } from '../../config/types';
2
+ import {
3
+ resolveAppBackendConfig,
4
+ resolveFrameNavigationItem,
5
+ type ResolvedAppBackend,
6
+ } from './identity';
7
+
8
+ /** A child app hosted by an embedded app, as accepted by the shell. */
9
+ export type ChildFrameEntry = {
10
+ hostUuid: string;
11
+ frameId: string;
12
+ url: string;
13
+ identity: ResolvedAppBackend | null;
14
+ /** Host-supplied service URLs that passed `childFrames.serviceOrigins`. Others are `null`. */
15
+ services: ChildFrameServices;
16
+ /** Service keys dropped because the URL was invalid or its origin not allowed. */
17
+ rejectedServices: ChildFrameServiceKey[];
18
+ };
19
+
20
+ export type ChildFrameServiceKey = 'email' | 'storage' | 'files' | 'hosting';
21
+ export type ChildFrameServices = Record<ChildFrameServiceKey, string | null>;
22
+ const SERVICE_KEYS: readonly ChildFrameServiceKey[] = ['email', 'storage', 'files', 'hosting'];
23
+
24
+ export type ChildFrameRegistration =
25
+ | { ok: true; entry: ChildFrameEntry }
26
+ | { ok: false; reason: string };
27
+
28
+ const entries = new Map<string, ChildFrameEntry>();
29
+
30
+ function entryKey(hostUuid: string, frameId: string): string {
31
+ return `${hostUuid}\n${frameId}`;
32
+ }
33
+
34
+ function exactOrigin(value: unknown): string | null {
35
+ if (typeof value !== 'string') return null;
36
+ try {
37
+ const url = new URL(value);
38
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return null;
39
+ return url.origin;
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+
45
+ function originList(values: unknown): Set<string> {
46
+ const out = new Set<string>();
47
+ if (!Array.isArray(values)) return out;
48
+ for (const value of values) {
49
+ // Only exact origins count. A path, wildcard or `*` never matches.
50
+ const origin = exactOrigin(value);
51
+ if (origin && origin === `${value}`.trim().replace(/\/$/, '')) out.add(origin);
52
+ }
53
+ return out;
54
+ }
55
+
56
+ /**
57
+ * Keep each host-supplied service URL only when it is http(s) and its origin is
58
+ * exactly in `allowed`. Missing or rejected values become `null`: the child never
59
+ * falls back to the shell's own services or to a built-in default.
60
+ */
61
+ export function resolveChildFrameServices(
62
+ input: unknown,
63
+ allowedOrigins: unknown,
64
+ ): { services: ChildFrameServices; rejected: ChildFrameServiceKey[] } {
65
+ const allowed = originList(allowedOrigins);
66
+ const raw = (input && typeof input === 'object' ? input : {}) as Record<string, unknown>;
67
+ const services: ChildFrameServices = { email: null, storage: null, files: null, hosting: null };
68
+ const rejected: ChildFrameServiceKey[] = [];
69
+ for (const key of SERVICE_KEYS) {
70
+ const value = raw[key];
71
+ if (value === undefined || value === null || value === '') continue;
72
+ const origin = exactOrigin(value);
73
+ if (origin && allowed.has(origin)) {
74
+ services[key] = `${value}`.trim().replace(/\/+$/, '');
75
+ } else {
76
+ rejected.push(key);
77
+ }
78
+ }
79
+ return { services, rejected };
80
+ }
81
+
82
+ /**
83
+ * Check a `SHELLUI_CHILD_FRAME_REGISTER` message. `from` must be exactly one hop:
84
+ * a child app cannot register frames by sending the message through its host.
85
+ */
86
+ export function validateChildFrameRegistration(input: {
87
+ from: readonly string[] | undefined;
88
+ hostSrc: string | null | undefined;
89
+ payload: unknown;
90
+ config?: ShellUIConfig;
91
+ }): ChildFrameRegistration {
92
+ const from = (input.from ?? []).filter(Boolean);
93
+ if (from.length !== 1) return { ok: false, reason: 'not sent by a direct app frame' };
94
+ if (!input.hostSrc) return { ok: false, reason: 'unknown host frame' };
95
+ const payload = input.payload as
96
+ | { frameId?: unknown; url?: unknown; backend?: unknown; services?: unknown }
97
+ | null
98
+ | undefined;
99
+ const frameId = typeof payload?.frameId === 'string' ? payload.frameId.trim() : '';
100
+ if (!frameId) return { ok: false, reason: 'missing frameId' };
101
+ const childOrigin = exactOrigin(payload?.url);
102
+ if (!childOrigin) return { ok: false, reason: 'child URL is not http(s)' };
103
+
104
+ const item = resolveFrameNavigationItem(input.hostSrc, input.config);
105
+ const rules = item?.childFrames;
106
+ if (!rules) return { ok: false, reason: 'host app may not embed apps' };
107
+ if (!originList(rules.origins).has(childOrigin)) {
108
+ return { ok: false, reason: 'child origin is not allowed' };
109
+ }
110
+
111
+ let identity: ResolvedAppBackend | null = null;
112
+ const backend = payload?.backend as
113
+ | { url?: unknown; companyId?: unknown; type?: unknown; provider?: unknown }
114
+ | null
115
+ | undefined;
116
+ if (backend) {
117
+ const backendOrigin = exactOrigin(backend.url);
118
+ if (!backendOrigin || !originList(rules.backendOrigins).has(backendOrigin)) {
119
+ return { ok: false, reason: 'child identity server is not allowed' };
120
+ }
121
+ const companyId =
122
+ typeof backend.companyId === 'string' || typeof backend.companyId === 'number'
123
+ ? backend.companyId
124
+ : undefined;
125
+ const type =
126
+ backend.type === 'shellui' || backend.type === 'supabase' ? backend.type : undefined;
127
+ identity = resolveAppBackendConfig(
128
+ {
129
+ url: backend.url as string,
130
+ ...(companyId !== undefined ? { companyId } : {}),
131
+ ...(type ? { type } : {}),
132
+ ...(typeof backend.provider === 'string' ? { provider: backend.provider } : {}),
133
+ },
134
+ input.config,
135
+ );
136
+ if (!identity) return { ok: false, reason: 'child identity server is invalid' };
137
+ }
138
+
139
+ const { services, rejected } = resolveChildFrameServices(payload?.services, rules.serviceOrigins);
140
+
141
+ return {
142
+ ok: true,
143
+ entry: {
144
+ hostUuid: from[0],
145
+ frameId,
146
+ url: payload?.url as string,
147
+ identity,
148
+ services,
149
+ rejectedServices: rejected,
150
+ },
151
+ };
152
+ }
153
+
154
+ export function addChildFrame(entry: ChildFrameEntry): void {
155
+ entries.set(entryKey(entry.hostUuid, entry.frameId), entry);
156
+ }
157
+
158
+ export function removeChildFrame(hostUuid: string, frameId: string): void {
159
+ entries.delete(entryKey(hostUuid, frameId));
160
+ }
161
+
162
+ /** The registered child for a `from` path such as `[host, child, ...]`. */
163
+ export function findChildFrame(path: readonly string[]): ChildFrameEntry | null {
164
+ if (path.length < 2) return null;
165
+ return entries.get(entryKey(path[0], path[1])) ?? null;
166
+ }
167
+
168
+ /** Children whose host frame is still registered. Others are dropped. */
169
+ export function listChildFrames(isHostKnown: (uuid: string) => boolean): ChildFrameEntry[] {
170
+ const out: ChildFrameEntry[] = [];
171
+ for (const [key, entry] of entries) {
172
+ if (!isHostKnown(entry.hostUuid)) entries.delete(key);
173
+ else out.push(entry);
174
+ }
175
+ return out;
176
+ }
177
+
178
+ export function clearChildFrames(): void {
179
+ entries.clear();
180
+ }
@@ -140,14 +140,7 @@ export function resolveFrameAuthDelivery(input: {
140
140
  );
141
141
  }
142
142
 
143
- /** Options for `buildSettingsForPropagation`. Shell frames omit the override keys. */
144
- export function frameAuthPropagationOptions(input: {
145
- frameSrc: string;
146
- config?: ShellUIConfig;
147
- shellAccessToken: string | null;
148
- getAppSession: (key: string) => AuthSession | null;
149
- shellOrigin?: string | null;
150
- }): {
143
+ export type FrameAuthPropagationOptions = {
151
144
  includeAuthAccessToken: boolean;
152
145
  accessToken: string | null;
153
146
  authBackendBaseUrl?: string | null;
@@ -155,8 +148,9 @@ export function frameAuthPropagationOptions(input: {
155
148
  storage?: StorageConfig | null;
156
149
  email?: EmailConfig | null;
157
150
  hosting?: HostingConfig | null;
158
- } {
159
- const delivery = resolveFrameAuthDelivery(input);
151
+ };
152
+
153
+ function toPropagationOptions(delivery: FrameAuthDelivery): FrameAuthPropagationOptions {
160
154
  return {
161
155
  includeAuthAccessToken: delivery.includeAuthAccessToken,
162
156
  accessToken: delivery.accessToken,
@@ -165,3 +159,46 @@ export function frameAuthPropagationOptions(input: {
165
159
  ...delivery.services,
166
160
  };
167
161
  }
162
+
163
+ /** Options for `buildSettingsForPropagation`. Shell frames omit the override keys. */
164
+ export function frameAuthPropagationOptions(input: {
165
+ frameSrc: string;
166
+ config?: ShellUIConfig;
167
+ shellAccessToken: string | null;
168
+ getAppSession: (key: string) => AuthSession | null;
169
+ shellOrigin?: string | null;
170
+ }): FrameAuthPropagationOptions {
171
+ return toPropagationOptions(resolveFrameAuthDelivery(input));
172
+ }
173
+
174
+ /**
175
+ * Auth fields for a child app hosted inside an embedded app (`createAppFrame`).
176
+ * The shell token is never sent. With no allowed identity server the child gets
177
+ * no token and no user. Service URLs are the ones the host passed and the shell
178
+ * allowed (`childFrames.serviceOrigins`); any other service is `null`.
179
+ */
180
+ export function childFrameAuthPropagationOptions(input: {
181
+ identity: ResolvedAppBackend | null;
182
+ getAppSession: (key: string) => AuthSession | null;
183
+ services?: Partial<Record<'email' | 'storage' | 'files' | 'hosting', string | null>> | null;
184
+ }): FrameAuthPropagationOptions {
185
+ const { identity, getAppSession } = input;
186
+ const allowed = input.services ?? {};
187
+ const session = identity ? getAppSession(identity.key) : null;
188
+ return toPropagationOptions({
189
+ includeAuthAccessToken: Boolean(identity),
190
+ accessToken: session?.accessToken ?? null,
191
+ overrideAuthBackend: true,
192
+ authBackendBaseUrl: identity?.type === 'shellui' ? identity.url : null,
193
+ overrideUser: true,
194
+ settingsUser: settingsUserFromSession(session),
195
+ services: {
196
+ email: allowed.email ? { url: allowed.email } : null,
197
+ // The files app URL rides on storage and is dropped when storage is not allowed.
198
+ storage: allowed.storage
199
+ ? { url: allowed.storage, ...(allowed.files ? { filesUrl: allowed.files } : {}) }
200
+ : null,
201
+ hosting: allowed.hosting ? { url: allowed.hosting } : null,
202
+ },
203
+ });
204
+ }
@@ -10,6 +10,24 @@ import {
10
10
  } from './silentSignIn';
11
11
 
12
12
  describe('buildSilentAuthorizeUrl', () => {
13
+ it('uses the federation entry for a regional identity server', () => {
14
+ const url = new URL(
15
+ buildSilentAuthorizeUrl({
16
+ backendUrl: 'https://id.eu.example/',
17
+ provider: 'upstream',
18
+ redirectTo: 'https://shell.example/login/callback?shellui_silent=1',
19
+ codeChallenge: 'challenge-value',
20
+ companyId: 7,
21
+ }),
22
+ );
23
+ expect(`${url.origin}${url.pathname}`).toBe('https://id.eu.example/oauth/silent-signin');
24
+ expect(url.searchParams.get('company_id')).toBe('7');
25
+ expect(url.searchParams.get('code_challenge')).toBe('challenge-value');
26
+ expect(url.searchParams.get('redirect_to')).toBe(
27
+ 'https://shell.example/login/callback?shellui_silent=1',
28
+ );
29
+ });
30
+
13
31
  it('uses PKCE, prompt=none, and code delivery without a shell token', () => {
14
32
  const shellToken = 'shell-access-token.should.not.appear';
15
33
  const url = new URL(
@@ -92,6 +92,9 @@ export function publishSilentAuthCallbackResult(win: Window = window): boolean {
92
92
  return true;
93
93
  }
94
94
 
95
+ /** Provider name of a regional identity server's trusted upstream (identity federation). */
96
+ export const FEDERATION_PROVIDER = 'upstream';
97
+
95
98
  export function buildSilentAuthorizeUrl(input: {
96
99
  backendUrl: string;
97
100
  provider: string;
@@ -101,7 +104,18 @@ export function buildSilentAuthorizeUrl(input: {
101
104
  clientTimezone?: string;
102
105
  clientDeviceId?: string;
103
106
  }): string {
104
- const authorizeUrl = new URL(`${input.backendUrl.replace(/\/+$/, '')}/api/v1/authorize`);
107
+ const base = input.backendUrl.replace(/\/+$/, '');
108
+ if (input.provider === FEDERATION_PROVIDER) {
109
+ // A regional identity server signs in through its trusted upstream (global identity).
110
+ // It has its own prompt=none entry and returns the usual PKCE code to `redirect_to`.
111
+ const federated = new URL(`${base}/oauth/silent-signin`);
112
+ federated.searchParams.set('redirect_to', input.redirectTo);
113
+ federated.searchParams.set('code_challenge', input.codeChallenge);
114
+ const federatedCompany = getShellUILoginCompanyId(input.companyId);
115
+ if (federatedCompany) federated.searchParams.set('company_id', federatedCompany);
116
+ return federated.toString();
117
+ }
118
+ const authorizeUrl = new URL(`${base}/api/v1/authorize`);
105
119
  authorizeUrl.searchParams.set('provider', input.provider);
106
120
  authorizeUrl.searchParams.set('redirect_to', input.redirectTo);
107
121
  authorizeUrl.searchParams.set('code_challenge', input.codeChallenge);