@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.
- package/package.json +2 -2
- package/schemas/shellui.config.schema.json +147 -70
- package/src/app.tsx +2 -0
- package/src/components/ContentView.tsx +21 -30
- package/src/components/iframeUrlSafety.spec.ts +67 -0
- package/src/components/iframeUrlSafety.ts +50 -0
- package/src/components/ui/sidebar.tsx +11 -5
- package/src/features/admin/AdminView.tsx +9 -6
- package/src/features/auth/AuthProvider.tsx +49 -5
- package/src/features/auth/appBackend/AppBackendSessionHost.tsx +58 -0
- package/src/features/auth/appBackend/appBackendSessions.spec.ts +329 -0
- package/src/features/auth/appBackend/appBackendSessions.ts +443 -0
- package/src/features/auth/appBackend/childFrames.spec.ts +328 -0
- package/src/features/auth/appBackend/childFrames.ts +180 -0
- package/src/features/auth/appBackend/configSchema.spec.ts +41 -0
- package/src/features/auth/appBackend/frameAuth.ts +204 -0
- package/src/features/auth/appBackend/identity.spec.ts +201 -0
- package/src/features/auth/appBackend/identity.ts +173 -0
- package/src/features/auth/appBackend/silentSignIn.spec.ts +225 -0
- package/src/features/auth/appBackend/silentSignIn.ts +254 -0
- package/src/features/auth/appBackend/tokenExchange.spec.ts +98 -0
- package/src/features/auth/appBackend/tokenExchange.ts +76 -0
- package/src/features/auth/backends/shellui.spec.ts +51 -19
- package/src/features/auth/backends/shellui.ts +20 -5
- package/src/features/auth/backends/types.ts +7 -2
- package/src/features/auth/components/LoginView.tsx +40 -18
- package/src/features/auth/components/OAuthCallbackView.tsx +33 -4
- package/src/features/auth/utils/authRequestError.ts +3 -0
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.spec.ts +42 -1
- package/src/features/auth/utils/buildOAuthSessionRedirectTo.ts +23 -0
- package/src/features/auth/utils/canRestoreStoredSession.spec.ts +29 -0
- package/src/features/auth/utils/canRestoreStoredSession.ts +12 -0
- package/src/features/auth/utils/index.ts +16 -1
- package/src/features/auth/utils/loginCancelTarget.spec.ts +73 -0
- package/src/features/auth/utils/loginCancelTarget.ts +45 -0
- package/src/features/auth/utils/loginPanelFrame.spec.ts +24 -0
- package/src/features/auth/utils/loginPanelFrame.ts +14 -0
- package/src/features/auth/utils/resolveSdkLoginRedirectPath.spec.ts +41 -0
- package/src/features/auth/utils/resolveSdkLoginRedirectPath.ts +31 -0
- package/src/features/auth/utils/webPkce.spec.ts +119 -0
- package/src/features/auth/utils/webPkce.ts +169 -0
- package/src/features/chromeActions/computeActionInsets.ts +7 -4
- package/src/features/config/types.ts +70 -3
- package/src/features/layouts/appbar/AppBarLayout.tsx +63 -30
- package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +12 -23
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +5 -6
- package/src/features/layouts/chrome/DesktopChrome.tsx +37 -0
- package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +15 -4
- package/src/features/layouts/chrome/MacStrip.tsx +33 -0
- package/src/features/layouts/chrome/constants.ts +33 -8
- package/src/features/layouts/chrome/index.ts +8 -0
- package/src/features/layouts/chrome/stripDragMap.ts +35 -0
- package/src/features/layouts/chrome/stripNoDrag.spec.tsx +103 -0
- package/src/features/layouts/chrome/useScrollHideChrome.ts +3 -8
- package/src/features/layouts/filterNavigationForAuthState.spec.ts +5 -3
- package/src/features/layouts/floating/FloatingBottomDock.tsx +199 -20
- package/src/features/layouts/floating/FloatingLayout.tsx +13 -8
- package/src/features/layouts/floating/FloatingSidebar.tsx +144 -70
- package/src/features/layouts/floating/computeFloatingInsets.ts +22 -4
- package/src/features/layouts/floating/useFloatingChrome.ts +3 -1
- package/src/features/layouts/floating/useSoftKeyboard.spec.ts +39 -0
- package/src/features/layouts/floating/useSoftKeyboard.ts +82 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +38 -10
- package/src/features/layouts/sidebar/NavigationContent.tsx +14 -6
- package/src/features/layouts/sidebar/SidebarIcons.tsx +3 -9
- package/src/features/layouts/sidebar/SidebarInner.tsx +50 -39
- package/src/features/layouts/sidebar/SidebarLayout.tsx +8 -11
- package/src/features/layouts/utils.ts +4 -3
- package/src/features/layouts/windows/DesktopDots.tsx +76 -0
- package/src/features/layouts/windows/WindowsLayout.tsx +184 -125
- package/src/features/layouts/windows/deskDots.spec.ts +52 -0
- package/src/features/layouts/windows/deskDots.ts +314 -0
- package/src/features/settings/SettingsProvider.tsx +198 -29
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +379 -4
- package/src/features/settings/utils/buildSettingsForPropagation.ts +65 -39
- package/src/features/theme/applyTheme.ts +8 -0
- package/src/features/theme/navContrast.spec.ts +49 -0
- package/src/features/theme/navContrast.ts +108 -0
- package/src/features/transfers/transferQueue.spec.ts +6 -2
- package/src/i18n/translations/en/common.json +27 -0
- package/src/i18n/translations/fr/common.json +27 -0
- package/src/index.css +935 -46
- package/src/index.ts +2 -0
- package/src/routes/hooks/useNavigationItems.ts +14 -3
- package/src/routes/hooks/withShellSearch.spec.ts +13 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
|
|
6
|
+
const schemaPath = resolve(
|
|
7
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
8
|
+
'../../../../schemas/shellui.config.schema.json',
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
describe('shellui.config schema app backend', () => {
|
|
12
|
+
const schema = JSON.parse(readFileSync(schemaPath, 'utf8')) as {
|
|
13
|
+
definitions: Record<
|
|
14
|
+
string,
|
|
15
|
+
{
|
|
16
|
+
properties?: Record<string, unknown>;
|
|
17
|
+
required?: string[];
|
|
18
|
+
additionalProperties?: boolean;
|
|
19
|
+
}
|
|
20
|
+
>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
it('adds an optional per-app backend and keeps existing item fields', () => {
|
|
24
|
+
const navigationItem = schema.definitions.NavigationItem;
|
|
25
|
+
const appBackend = schema.definitions.AppBackendConfig;
|
|
26
|
+
expect(navigationItem.additionalProperties).toBe(false);
|
|
27
|
+
expect(navigationItem.required).toEqual(['label', 'path', 'url']);
|
|
28
|
+
expect(navigationItem.properties?.backend).toBeTruthy();
|
|
29
|
+
expect(navigationItem.properties?.email).toBeTruthy();
|
|
30
|
+
expect(navigationItem.properties?.storage).toBeTruthy();
|
|
31
|
+
expect(navigationItem.properties?.hosting).toBeTruthy();
|
|
32
|
+
expect(navigationItem.properties?.safeForAuthToken).toBeTruthy();
|
|
33
|
+
expect(appBackend.additionalProperties).toBe(false);
|
|
34
|
+
expect(appBackend.required).toEqual(['url']);
|
|
35
|
+
expect(appBackend.properties?.url).toBeTruthy();
|
|
36
|
+
expect(appBackend.properties?.type).toBeTruthy();
|
|
37
|
+
expect(appBackend.properties?.companyId).toBeTruthy();
|
|
38
|
+
expect(appBackend.properties?.provider).toBeTruthy();
|
|
39
|
+
expect(appBackend.properties?.publishableKey).toBeTruthy();
|
|
40
|
+
});
|
|
41
|
+
});
|