@shellui/core 0.6.2 → 0.7.0-alpha.2
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 +116 -72
- package/src/app.tsx +2 -0
- package/src/components/ContentView.tsx +2 -22
- package/src/components/iframeUrlSafety.spec.ts +67 -0
- package/src/components/iframeUrlSafety.ts +50 -0
- package/src/features/auth/AuthProvider.tsx +24 -1
- package/src/features/auth/appBackend/AppBackendSessionHost.tsx +58 -0
- package/src/features/auth/appBackend/appBackendSessions.spec.ts +195 -0
- package/src/features/auth/appBackend/appBackendSessions.ts +292 -0
- package/src/features/auth/appBackend/configSchema.spec.ts +41 -0
- package/src/features/auth/appBackend/frameAuth.ts +167 -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 +207 -0
- package/src/features/auth/appBackend/silentSignIn.ts +240 -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/index.ts +14 -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/webPkce.spec.ts +119 -0
- package/src/features/auth/utils/webPkce.ts +169 -0
- package/src/features/config/types.ts +41 -0
- package/src/features/settings/SettingsProvider.tsx +45 -32
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +374 -0
- package/src/features/settings/utils/buildSettingsForPropagation.ts +61 -33
- package/src/i18n/translations/en/common.json +2 -0
- package/src/i18n/translations/fr/common.json +2 -0
- package/src/index.ts +1 -0
|
@@ -19,7 +19,12 @@ import {
|
|
|
19
19
|
import { SettingsContext } from './SettingsContext';
|
|
20
20
|
import { useConfig } from '../config/useConfig';
|
|
21
21
|
import { useAuth } from '../auth/hooks/useAuth';
|
|
22
|
-
import {
|
|
22
|
+
import { frameAuthPropagationOptions } from '../auth/appBackend/frameAuth';
|
|
23
|
+
import {
|
|
24
|
+
getAppBackendSession,
|
|
25
|
+
refreshAppBackendSessionIfDue,
|
|
26
|
+
subscribeAppBackendSessions,
|
|
27
|
+
} from '../auth/appBackend/appBackendSessions';
|
|
23
28
|
import { isMainLayoutFrame } from '../layouts/floating/layoutChromeStore';
|
|
24
29
|
import { defaultTheme } from '../theme/themes';
|
|
25
30
|
import {
|
|
@@ -192,26 +197,29 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
192
197
|
return defaultSettings;
|
|
193
198
|
});
|
|
194
199
|
|
|
195
|
-
const isTrustedFrameForAuthTokenCallback = useCallback(
|
|
196
|
-
(frameSrc: string): boolean => isTrustedFrameForAuthToken(frameSrc, config),
|
|
197
|
-
[config],
|
|
198
|
-
);
|
|
199
|
-
|
|
200
200
|
const accessTokenRef = useRef<string | null>(session?.accessToken ?? null);
|
|
201
201
|
accessTokenRef.current = session?.accessToken ?? null;
|
|
202
202
|
|
|
203
|
+
const authOptionsForFrame = useCallback(
|
|
204
|
+
(frameSrc: string) =>
|
|
205
|
+
frameAuthPropagationOptions({
|
|
206
|
+
frameSrc,
|
|
207
|
+
config,
|
|
208
|
+
shellAccessToken: accessTokenRef.current,
|
|
209
|
+
getAppSession: getAppBackendSession,
|
|
210
|
+
}),
|
|
211
|
+
[config],
|
|
212
|
+
);
|
|
213
|
+
|
|
203
214
|
const propagateSettingsToIframes = useCallback(
|
|
204
215
|
(baseSettings: Settings) => {
|
|
205
216
|
const iframes = shellui.frameRegistry.getLiveIframes();
|
|
206
217
|
if (iframes.length === 0) return;
|
|
207
218
|
const lang = baseSettings.language?.code || 'en';
|
|
208
|
-
const accessToken = accessTokenRef.current;
|
|
209
219
|
for (const [uuid, iframe] of iframes) {
|
|
210
220
|
const frameSrc = iframe?.src ?? '';
|
|
211
|
-
const includeAuthAccessToken = isTrustedFrameForAuthTokenCallback(frameSrc);
|
|
212
221
|
const settingsToPropagate = buildSettingsForPropagation(baseSettings, config, lang, {
|
|
213
|
-
|
|
214
|
-
accessToken,
|
|
222
|
+
...authOptionsForFrame(frameSrc),
|
|
215
223
|
includeLayoutChrome: isMainLayoutFrame(iframe),
|
|
216
224
|
frameUuid: uuid,
|
|
217
225
|
});
|
|
@@ -222,19 +230,17 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
222
230
|
});
|
|
223
231
|
}
|
|
224
232
|
},
|
|
225
|
-
[
|
|
233
|
+
[authOptionsForFrame, config],
|
|
226
234
|
);
|
|
227
235
|
|
|
228
236
|
const pushSettingsToFrame = useCallback(
|
|
229
237
|
(iframeUuid: string, frameSrc: string, baseSettings: Settings) => {
|
|
230
238
|
const lang = baseSettings.language?.code || 'en';
|
|
231
|
-
const includeAuthAccessToken = isTrustedFrameForAuthTokenCallback(frameSrc);
|
|
232
239
|
const iframe = shellui.frameRegistry
|
|
233
240
|
.getAllIframes()
|
|
234
241
|
.find(([uuid]) => uuid === iframeUuid)?.[1];
|
|
235
242
|
const settingsToPropagate = buildSettingsForPropagation(baseSettings, config, lang, {
|
|
236
|
-
|
|
237
|
-
accessToken: accessTokenRef.current,
|
|
243
|
+
...authOptionsForFrame(frameSrc),
|
|
238
244
|
includeLayoutChrome: isMainLayoutFrame(iframe),
|
|
239
245
|
frameUuid: iframeUuid,
|
|
240
246
|
});
|
|
@@ -244,7 +250,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
244
250
|
to: [iframeUuid],
|
|
245
251
|
});
|
|
246
252
|
},
|
|
247
|
-
[
|
|
253
|
+
[authOptionsForFrame, config],
|
|
248
254
|
);
|
|
249
255
|
|
|
250
256
|
const applyHandoffToken = useCallback((token: string | null | undefined) => {
|
|
@@ -256,6 +262,13 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
256
262
|
return deliverSessionHandoff(() => propagateSettingsToIframes(base));
|
|
257
263
|
}, [propagateSettingsToIframes]);
|
|
258
264
|
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
return subscribeAppBackendSessions(() => {
|
|
267
|
+
if (typeof window === 'undefined' || window.parent !== window) return;
|
|
268
|
+
handoffSettingsToIframes();
|
|
269
|
+
});
|
|
270
|
+
}, [handoffSettingsToIframes]);
|
|
271
|
+
|
|
259
272
|
// When the shell rotates the JWT, `authUser` often does not change, so the user-sync effect
|
|
260
273
|
// above skips — still push `SHELLUI_SETTINGS` so trusted iframes get the new `accessToken`.
|
|
261
274
|
// The follow-up turn covers an app that subscribes after the first post.
|
|
@@ -482,28 +495,30 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
482
495
|
// not the JWT that died while the tab was hidden.
|
|
483
496
|
const token = await refreshFrameAccessTokenIfNeeded();
|
|
484
497
|
applyHandoffToken(token);
|
|
498
|
+
const requestingPath = (message.from ?? []).filter(Boolean);
|
|
499
|
+
const [firstHopIframeUuid] = requestingPath;
|
|
500
|
+
const requestingFrame = firstHopIframeUuid
|
|
501
|
+
? shellui.frameRegistry
|
|
502
|
+
.getAllIframes()
|
|
503
|
+
.find(([uuid]) => uuid === firstHopIframeUuid)?.[1]
|
|
504
|
+
: undefined;
|
|
505
|
+
if (requestingFrame?.src) {
|
|
506
|
+
await refreshAppBackendSessionIfDue(requestingFrame.src, config);
|
|
507
|
+
}
|
|
485
508
|
|
|
486
509
|
const send = () => {
|
|
487
510
|
const currentSettings = settingsRef.current ?? defaultSettings;
|
|
488
|
-
const requestingPath = (message.from ?? []).filter(Boolean);
|
|
489
511
|
|
|
490
512
|
if (requestingPath.length > 0) {
|
|
491
|
-
const [firstHopIframeUuid] = requestingPath;
|
|
492
|
-
const frame = shellui.frameRegistry
|
|
493
|
-
.getAllIframes()
|
|
494
|
-
.find(([uuid]) => uuid === firstHopIframeUuid)?.[1];
|
|
495
513
|
const lang = currentSettings.language?.code || 'en';
|
|
496
|
-
const
|
|
497
|
-
? isTrustedFrameForAuthTokenCallback(frame.src ?? '')
|
|
498
|
-
: false;
|
|
514
|
+
const frameSrc = requestingFrame?.src ?? '';
|
|
499
515
|
const settingsToPropagate = buildSettingsForPropagation(
|
|
500
516
|
currentSettings,
|
|
501
517
|
config,
|
|
502
518
|
lang,
|
|
503
519
|
{
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
includeLayoutChrome: isMainLayoutFrame(frame),
|
|
520
|
+
...authOptionsForFrame(frameSrc),
|
|
521
|
+
includeLayoutChrome: isMainLayoutFrame(requestingFrame),
|
|
507
522
|
frameUuid: firstHopIframeUuid,
|
|
508
523
|
},
|
|
509
524
|
);
|
|
@@ -565,12 +580,10 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
565
580
|
void (async () => {
|
|
566
581
|
const token = await refreshFrameAccessTokenIfNeeded();
|
|
567
582
|
applyHandoffToken(token);
|
|
583
|
+
const frameSrc = iframe?.src ?? '';
|
|
584
|
+
if (frameSrc) await refreshAppBackendSessionIfDue(frameSrc, config);
|
|
568
585
|
deliverSessionHandoff(() =>
|
|
569
|
-
pushSettingsToFrame(
|
|
570
|
-
iframeUuid,
|
|
571
|
-
iframe?.src ?? '',
|
|
572
|
-
settingsRef.current ?? defaultSettings,
|
|
573
|
-
),
|
|
586
|
+
pushSettingsToFrame(iframeUuid, frameSrc, settingsRef.current ?? defaultSettings),
|
|
574
587
|
);
|
|
575
588
|
})();
|
|
576
589
|
},
|
|
@@ -583,8 +596,8 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|
|
583
596
|
cleanupInitialized();
|
|
584
597
|
};
|
|
585
598
|
}, [
|
|
599
|
+
authOptionsForFrame,
|
|
586
600
|
config,
|
|
587
|
-
isTrustedFrameForAuthTokenCallback,
|
|
588
601
|
applyHandoffToken,
|
|
589
602
|
propagateSettingsToIframes,
|
|
590
603
|
pushSettingsToFrame,
|
|
@@ -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
|
|
|
@@ -319,4 +321,376 @@ describe('buildSettingsForPropagation', () => {
|
|
|
319
321
|
const result = buildSettingsForPropagation(baseSettings, config, 'en');
|
|
320
322
|
expect(result.email).toEqual({ url: 'https://email.shellui.com' });
|
|
321
323
|
});
|
|
324
|
+
|
|
325
|
+
const shellToken = 'shell-access-token';
|
|
326
|
+
const foreignToken = 'foreign-access-token';
|
|
327
|
+
const shellUser = {
|
|
328
|
+
id: 'shell-user',
|
|
329
|
+
email: 'shell@example.com',
|
|
330
|
+
name: 'Shell User',
|
|
331
|
+
profilePicture: null,
|
|
332
|
+
authProvider: 'google',
|
|
333
|
+
isStaff: true,
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const appConfig = {
|
|
337
|
+
backend: {
|
|
338
|
+
type: 'shellui' as const,
|
|
339
|
+
url: 'https://id.example.com/',
|
|
340
|
+
companyId: 1,
|
|
341
|
+
adminUrl: 'https://admin.example/',
|
|
342
|
+
login: { oauthProviders: ['google'] },
|
|
343
|
+
},
|
|
344
|
+
storage: { url: 'https://files-api.example', filesUrl: 'https://files.example/' },
|
|
345
|
+
email: { url: 'https://email.example' },
|
|
346
|
+
hosting: { url: 'https://hosting.example/', app: 'shell-app' },
|
|
347
|
+
navigation: [
|
|
348
|
+
{
|
|
349
|
+
label: 'Billing',
|
|
350
|
+
path: 'billing',
|
|
351
|
+
url: 'https://billing.example/',
|
|
352
|
+
safeForAuthToken: true,
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
label: 'Directory',
|
|
356
|
+
path: 'directory',
|
|
357
|
+
url: 'https://directory.example/',
|
|
358
|
+
safeForAuthToken: true,
|
|
359
|
+
backend: {
|
|
360
|
+
url: 'https://id.directory.example/',
|
|
361
|
+
companyId: 4,
|
|
362
|
+
provider: 'google',
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
label: 'Public directory',
|
|
367
|
+
path: 'public-directory',
|
|
368
|
+
url: 'https://public.example/',
|
|
369
|
+
backend: { url: 'https://id.public.example' },
|
|
370
|
+
},
|
|
371
|
+
],
|
|
372
|
+
} as ShellUIConfig;
|
|
373
|
+
|
|
374
|
+
const foreignSession = {
|
|
375
|
+
accessToken: foreignToken,
|
|
376
|
+
refreshToken: 'foreign-refresh',
|
|
377
|
+
tokenType: 'bearer',
|
|
378
|
+
expiresAt: 4_000_000_000,
|
|
379
|
+
provider: 'google',
|
|
380
|
+
userId: 'foreign-user',
|
|
381
|
+
userEmail: 'foreign@example.com',
|
|
382
|
+
userName: 'Foreign User',
|
|
383
|
+
userAvatarUrl: null,
|
|
384
|
+
userIsStaff: false,
|
|
385
|
+
userIsCompanyOwner: true,
|
|
386
|
+
userGroups: ['directory'],
|
|
387
|
+
} satisfies AuthSession;
|
|
388
|
+
|
|
389
|
+
const propagate = (frameSrc: string, session: AuthSession | null = foreignSession) => {
|
|
390
|
+
const options = frameAuthPropagationOptions({
|
|
391
|
+
frameSrc,
|
|
392
|
+
config: appConfig,
|
|
393
|
+
shellAccessToken: shellToken,
|
|
394
|
+
getAppSession: () => session,
|
|
395
|
+
shellOrigin: 'https://shell.example',
|
|
396
|
+
});
|
|
397
|
+
return buildSettingsForPropagation(
|
|
398
|
+
{ ...baseSettings, user: shellUser },
|
|
399
|
+
appConfig,
|
|
400
|
+
'en',
|
|
401
|
+
options,
|
|
402
|
+
);
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
const shellServices = {
|
|
406
|
+
storage: { url: 'https://files-api.example', filesUrl: 'https://files.example/' },
|
|
407
|
+
email: { url: 'https://email.example' },
|
|
408
|
+
hosting: { url: 'https://hosting.example', app: 'shell-app' },
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const expectNoShellServices = (result: ReturnType<typeof propagate>) => {
|
|
412
|
+
expect(result.storage).toBeNull();
|
|
413
|
+
expect(result.email).toBeNull();
|
|
414
|
+
expect(result.hosting).toBeNull();
|
|
415
|
+
const json = JSON.stringify(result);
|
|
416
|
+
expect(json).not.toContain('https://files-api.example');
|
|
417
|
+
expect(json).not.toContain('https://files.example');
|
|
418
|
+
expect(json).not.toContain('https://email.example');
|
|
419
|
+
expect(json).not.toContain('https://hosting.example');
|
|
420
|
+
expect(json).not.toContain('https://email.shellui.com');
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
it('falls back to the shell backend and token when the app has no override', () => {
|
|
424
|
+
const result = propagate('https://billing.example/');
|
|
425
|
+
expect(result.accessToken).toBe(shellToken);
|
|
426
|
+
expect(result.authBackendBaseUrl).toBe('https://id.example.com');
|
|
427
|
+
expect(result.user?.email).toBe('shell@example.com');
|
|
428
|
+
expect(result.storage).toEqual(shellServices.storage);
|
|
429
|
+
expect(result.email).toEqual(shellServices.email);
|
|
430
|
+
expect(result.hosting).toEqual(shellServices.hosting);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('sends each foreign app its own backend URL and token', () => {
|
|
434
|
+
const result = propagate('https://directory.example/people');
|
|
435
|
+
expect(result.accessToken).toBe(foreignToken);
|
|
436
|
+
expect(result.authBackendBaseUrl).toBe('https://id.directory.example');
|
|
437
|
+
expect(result.user).toMatchObject({
|
|
438
|
+
id: 'foreign-user',
|
|
439
|
+
email: 'foreign@example.com',
|
|
440
|
+
groups: ['directory'],
|
|
441
|
+
});
|
|
442
|
+
expect(JSON.stringify(result)).not.toContain(shellToken);
|
|
443
|
+
expect(JSON.stringify(result)).not.toContain('shell@example.com');
|
|
444
|
+
expect(result).not.toHaveProperty('refreshToken');
|
|
445
|
+
expectNoShellServices(result);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('sends a null token, not the shell token, when the foreign session is missing', () => {
|
|
449
|
+
const result = propagate('https://directory.example/', null);
|
|
450
|
+
expect(result.accessToken).toBeNull();
|
|
451
|
+
expect(result.authBackendBaseUrl).toBe('https://id.directory.example');
|
|
452
|
+
expect(result.user).toBeNull();
|
|
453
|
+
expect(JSON.stringify(result)).not.toContain(shellToken);
|
|
454
|
+
expectNoShellServices(result);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('does not send either token to an untrusted app on another identity server', () => {
|
|
458
|
+
const result = propagate('https://public.example/');
|
|
459
|
+
expect(result.accessToken).toBeNull();
|
|
460
|
+
expect(result.authBackendBaseUrl).toBe('https://id.public.example');
|
|
461
|
+
expect(JSON.stringify(result)).not.toContain(shellToken);
|
|
462
|
+
expect(JSON.stringify(result)).not.toContain(foreignToken);
|
|
463
|
+
expectNoShellServices(result);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it('keeps the shell token for the built-in admin and storage frames', () => {
|
|
467
|
+
const admin = propagate('https://admin.example/#/users');
|
|
468
|
+
const files = propagate('https://files.example/company/docs');
|
|
469
|
+
expect(admin.accessToken).toBe(shellToken);
|
|
470
|
+
expect(admin.authBackendBaseUrl).toBe('https://id.example.com');
|
|
471
|
+
expect(files.accessToken).toBe(shellToken);
|
|
472
|
+
expect(files.authBackendBaseUrl).toBe('https://id.example.com');
|
|
473
|
+
expect(admin.storage).toEqual(shellServices.storage);
|
|
474
|
+
expect(admin.email).toEqual(shellServices.email);
|
|
475
|
+
expect(files.hosting).toEqual(shellServices.hosting);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it('keeps the shell token for shell settings even if a root item names another server', () => {
|
|
479
|
+
vi.stubGlobal('window', {
|
|
480
|
+
location: { origin: 'https://shell.example' },
|
|
481
|
+
matchMedia: () => ({ matches: false }),
|
|
482
|
+
});
|
|
483
|
+
const withRoot = {
|
|
484
|
+
...appConfig,
|
|
485
|
+
navigation: [
|
|
486
|
+
...(appConfig.navigation ?? []),
|
|
487
|
+
{
|
|
488
|
+
label: 'Home',
|
|
489
|
+
path: 'home',
|
|
490
|
+
url: 'https://shell.example/',
|
|
491
|
+
safeForAuthToken: true,
|
|
492
|
+
backend: { url: 'https://id.other.example' },
|
|
493
|
+
},
|
|
494
|
+
],
|
|
495
|
+
} as ShellUIConfig;
|
|
496
|
+
const options = frameAuthPropagationOptions({
|
|
497
|
+
frameSrc: 'https://shell.example/__settings/storage',
|
|
498
|
+
config: withRoot,
|
|
499
|
+
shellAccessToken: shellToken,
|
|
500
|
+
getAppSession: () => foreignSession,
|
|
501
|
+
shellOrigin: 'https://shell.example',
|
|
502
|
+
});
|
|
503
|
+
const result = buildSettingsForPropagation(
|
|
504
|
+
{ ...baseSettings, user: shellUser },
|
|
505
|
+
withRoot,
|
|
506
|
+
'en',
|
|
507
|
+
options,
|
|
508
|
+
);
|
|
509
|
+
expect(result.accessToken).toBe(shellToken);
|
|
510
|
+
expect(result.authBackendBaseUrl).toBe('https://id.example.com');
|
|
511
|
+
expect(result.user?.email).toBe('shell@example.com');
|
|
512
|
+
expect(result.storage).toEqual(shellServices.storage);
|
|
513
|
+
expect(result.email).toEqual(shellServices.email);
|
|
514
|
+
expect(result.hosting).toEqual(shellServices.hosting);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it('sends a foreign app its own service URLs and not the shell URLs', () => {
|
|
518
|
+
const withServices = {
|
|
519
|
+
...appConfig,
|
|
520
|
+
navigation: (appConfig.navigation ?? []).map((item) =>
|
|
521
|
+
item.path === 'directory'
|
|
522
|
+
? {
|
|
523
|
+
...item,
|
|
524
|
+
email: { url: 'https://email.directory.example/' },
|
|
525
|
+
storage: {
|
|
526
|
+
url: 'https://files-api.directory.example',
|
|
527
|
+
filesUrl: 'https://files.directory.example/',
|
|
528
|
+
},
|
|
529
|
+
hosting: { url: 'https://hosting.directory.example', showInAdmin: false },
|
|
530
|
+
}
|
|
531
|
+
: item,
|
|
532
|
+
),
|
|
533
|
+
} as ShellUIConfig;
|
|
534
|
+
const options = frameAuthPropagationOptions({
|
|
535
|
+
frameSrc: 'https://directory.example/people',
|
|
536
|
+
config: withServices,
|
|
537
|
+
shellAccessToken: shellToken,
|
|
538
|
+
getAppSession: () => foreignSession,
|
|
539
|
+
shellOrigin: 'https://shell.example',
|
|
540
|
+
});
|
|
541
|
+
const result = buildSettingsForPropagation(
|
|
542
|
+
{ ...baseSettings, user: shellUser },
|
|
543
|
+
withServices,
|
|
544
|
+
'en',
|
|
545
|
+
options,
|
|
546
|
+
);
|
|
547
|
+
expect(result.storage).toEqual({
|
|
548
|
+
url: 'https://files-api.directory.example',
|
|
549
|
+
filesUrl: 'https://files.directory.example/',
|
|
550
|
+
});
|
|
551
|
+
expect(result.email).toEqual({ url: 'https://email.directory.example' });
|
|
552
|
+
expect(result.hosting).toEqual({
|
|
553
|
+
url: 'https://hosting.directory.example',
|
|
554
|
+
showInAdmin: false,
|
|
555
|
+
});
|
|
556
|
+
const json = JSON.stringify(result);
|
|
557
|
+
expect(json).not.toContain('https://files-api.example');
|
|
558
|
+
expect(json).not.toContain('https://email.example');
|
|
559
|
+
expect(json).not.toContain('https://hosting.example');
|
|
560
|
+
expect(json).not.toContain('https://email.shellui.com');
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
it('uses the default email URL when a foreign app sets an empty email object', () => {
|
|
564
|
+
const withEmptyEmail = {
|
|
565
|
+
...appConfig,
|
|
566
|
+
navigation: (appConfig.navigation ?? []).map((item) =>
|
|
567
|
+
item.path === 'directory' ? { ...item, email: {} } : item,
|
|
568
|
+
),
|
|
569
|
+
} as ShellUIConfig;
|
|
570
|
+
const options = frameAuthPropagationOptions({
|
|
571
|
+
frameSrc: 'https://directory.example/',
|
|
572
|
+
config: withEmptyEmail,
|
|
573
|
+
shellAccessToken: shellToken,
|
|
574
|
+
getAppSession: () => foreignSession,
|
|
575
|
+
shellOrigin: 'https://shell.example',
|
|
576
|
+
});
|
|
577
|
+
const result = buildSettingsForPropagation(
|
|
578
|
+
{ ...baseSettings, user: shellUser },
|
|
579
|
+
withEmptyEmail,
|
|
580
|
+
'en',
|
|
581
|
+
options,
|
|
582
|
+
);
|
|
583
|
+
expect(result.email).toEqual({ url: 'https://email.shellui.com' });
|
|
584
|
+
expect(result.storage).toBeNull();
|
|
585
|
+
expect(result.hosting).toBeNull();
|
|
586
|
+
const json = JSON.stringify(result);
|
|
587
|
+
expect(json).not.toContain('https://files-api.example');
|
|
588
|
+
expect(json).not.toContain('https://email.example');
|
|
589
|
+
expect(json).not.toContain('https://hosting.example');
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
it('replaces only the service an app sets when it keeps the shell backend', () => {
|
|
593
|
+
const withEmail = {
|
|
594
|
+
...appConfig,
|
|
595
|
+
navigation: [
|
|
596
|
+
...(appConfig.navigation ?? []),
|
|
597
|
+
{
|
|
598
|
+
label: 'Mail',
|
|
599
|
+
path: 'mail',
|
|
600
|
+
url: 'https://mail.example/',
|
|
601
|
+
safeForAuthToken: true,
|
|
602
|
+
email: {},
|
|
603
|
+
},
|
|
604
|
+
],
|
|
605
|
+
} as ShellUIConfig;
|
|
606
|
+
const options = frameAuthPropagationOptions({
|
|
607
|
+
frameSrc: 'https://mail.example/',
|
|
608
|
+
config: withEmail,
|
|
609
|
+
shellAccessToken: shellToken,
|
|
610
|
+
getAppSession: () => foreignSession,
|
|
611
|
+
shellOrigin: 'https://shell.example',
|
|
612
|
+
});
|
|
613
|
+
const result = buildSettingsForPropagation(
|
|
614
|
+
{ ...baseSettings, user: shellUser },
|
|
615
|
+
withEmail,
|
|
616
|
+
'en',
|
|
617
|
+
options,
|
|
618
|
+
);
|
|
619
|
+
expect(result.accessToken).toBe(shellToken);
|
|
620
|
+
expect(result.authBackendBaseUrl).toBe('https://id.example.com');
|
|
621
|
+
expect(result.email).toEqual({ url: 'https://email.shellui.com' });
|
|
622
|
+
expect(result.storage).toEqual(shellServices.storage);
|
|
623
|
+
expect(result.hosting).toEqual(shellServices.hosting);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it('keeps shell services when the item backend is the same server', () => {
|
|
627
|
+
const sameServer = {
|
|
628
|
+
...appConfig,
|
|
629
|
+
navigation: [
|
|
630
|
+
...(appConfig.navigation ?? []),
|
|
631
|
+
{
|
|
632
|
+
label: 'Same',
|
|
633
|
+
path: 'same',
|
|
634
|
+
url: 'https://same.example/',
|
|
635
|
+
safeForAuthToken: true,
|
|
636
|
+
backend: { url: 'https://id.example.com/', companyId: 1 },
|
|
637
|
+
},
|
|
638
|
+
],
|
|
639
|
+
} as ShellUIConfig;
|
|
640
|
+
const options = frameAuthPropagationOptions({
|
|
641
|
+
frameSrc: 'https://same.example/',
|
|
642
|
+
config: sameServer,
|
|
643
|
+
shellAccessToken: shellToken,
|
|
644
|
+
getAppSession: () => foreignSession,
|
|
645
|
+
shellOrigin: 'https://shell.example',
|
|
646
|
+
});
|
|
647
|
+
const result = buildSettingsForPropagation(
|
|
648
|
+
{ ...baseSettings, user: shellUser },
|
|
649
|
+
sameServer,
|
|
650
|
+
'en',
|
|
651
|
+
options,
|
|
652
|
+
);
|
|
653
|
+
expect(result.accessToken).toBe(shellToken);
|
|
654
|
+
expect(result.storage).toEqual(shellServices.storage);
|
|
655
|
+
expect(result.email).toEqual(shellServices.email);
|
|
656
|
+
expect(result.hosting).toEqual(shellServices.hosting);
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
it('sends no service URLs when the named backend cannot be used', () => {
|
|
660
|
+
const invalid = {
|
|
661
|
+
...appConfig,
|
|
662
|
+
navigation: [
|
|
663
|
+
...(appConfig.navigation ?? []),
|
|
664
|
+
{
|
|
665
|
+
label: 'Broken',
|
|
666
|
+
path: 'broken',
|
|
667
|
+
url: 'https://broken.example/',
|
|
668
|
+
safeForAuthToken: true,
|
|
669
|
+
backend: { url: 'not-a-url' },
|
|
670
|
+
email: { url: 'https://email.broken.example' },
|
|
671
|
+
},
|
|
672
|
+
],
|
|
673
|
+
} as ShellUIConfig;
|
|
674
|
+
const options = frameAuthPropagationOptions({
|
|
675
|
+
frameSrc: 'https://broken.example/',
|
|
676
|
+
config: invalid,
|
|
677
|
+
shellAccessToken: shellToken,
|
|
678
|
+
getAppSession: () => foreignSession,
|
|
679
|
+
shellOrigin: 'https://shell.example',
|
|
680
|
+
});
|
|
681
|
+
const result = buildSettingsForPropagation(
|
|
682
|
+
{ ...baseSettings, user: shellUser },
|
|
683
|
+
invalid,
|
|
684
|
+
'en',
|
|
685
|
+
options,
|
|
686
|
+
);
|
|
687
|
+
expect(result.accessToken).toBeNull();
|
|
688
|
+
expect(result.email).toEqual({ url: 'https://email.broken.example' });
|
|
689
|
+
expect(result.storage).toBeNull();
|
|
690
|
+
expect(result.hosting).toBeNull();
|
|
691
|
+
const json = JSON.stringify(result);
|
|
692
|
+
expect(json).not.toContain('https://files-api.example');
|
|
693
|
+
expect(json).not.toContain('https://hosting.example');
|
|
694
|
+
expect(json).not.toContain(shellToken);
|
|
695
|
+
});
|
|
322
696
|
});
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
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';
|
|
@@ -12,7 +18,7 @@ import {
|
|
|
12
18
|
/** Production email-service origin. No trailing slash. */
|
|
13
19
|
const DEFAULT_EMAIL_SERVICE_URL = 'https://email.shellui.com';
|
|
14
20
|
|
|
15
|
-
const propagateEmail = (email:
|
|
21
|
+
const propagateEmail = (email: EmailConfig | null | undefined): SettingsEmail | null => {
|
|
16
22
|
if (!email) return null;
|
|
17
23
|
const url = email.url?.trim().replace(/\/+$/, '') || DEFAULT_EMAIL_SERVICE_URL;
|
|
18
24
|
return {
|
|
@@ -21,6 +27,27 @@ const propagateEmail = (email: ShellUIConfig['email']): SettingsEmail | null =>
|
|
|
21
27
|
};
|
|
22
28
|
};
|
|
23
29
|
|
|
30
|
+
const propagateStorage = (storage: StorageConfig | null | undefined): SettingsStorage | null => {
|
|
31
|
+
const storageUrl = storage?.url?.trim().replace(/\/+$/, '') || null;
|
|
32
|
+
if (!storageUrl) return null;
|
|
33
|
+
const filesUrl = storage?.filesUrl?.trim() || null;
|
|
34
|
+
return {
|
|
35
|
+
url: storageUrl,
|
|
36
|
+
...(filesUrl ? { filesUrl } : {}),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const propagateHosting = (hosting: HostingConfig | null | undefined): SettingsHosting | null => {
|
|
41
|
+
const hostingUrl = hosting?.url?.trim().replace(/\/+$/, '') || null;
|
|
42
|
+
if (!hostingUrl) return null;
|
|
43
|
+
const app = hosting?.app?.trim() || null;
|
|
44
|
+
return {
|
|
45
|
+
url: hostingUrl,
|
|
46
|
+
...(app ? { app } : {}),
|
|
47
|
+
...(hosting?.showInAdmin === false ? { showInAdmin: false } : {}),
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
24
51
|
/**
|
|
25
52
|
* Build settings for propagation to iframes: inject navigation, full theme object,
|
|
26
53
|
* and list of available themes so apps can render theme pickers.
|
|
@@ -32,6 +59,22 @@ export const buildSettingsForPropagation = (
|
|
|
32
59
|
options?: {
|
|
33
60
|
includeAuthAccessToken?: boolean;
|
|
34
61
|
accessToken?: string | null;
|
|
62
|
+
/**
|
|
63
|
+
* Identity base URL for this frame. When the key is set, it replaces the shell
|
|
64
|
+
* `backend` URL (`null` when that server is not a Shellui identity backend).
|
|
65
|
+
*/
|
|
66
|
+
authBackendBaseUrl?: string | null;
|
|
67
|
+
/** User for this frame's identity server. When the key is set, it replaces `settings.user`. */
|
|
68
|
+
settingsUser?: Settings['user'];
|
|
69
|
+
/**
|
|
70
|
+
* Storage for this frame. When the key is set, it replaces the shell `storage`
|
|
71
|
+
* (`null` sends no storage URL).
|
|
72
|
+
*/
|
|
73
|
+
storage?: StorageConfig | null;
|
|
74
|
+
/** Email for this frame. When the key is set, it replaces the shell `email`. */
|
|
75
|
+
email?: EmailConfig | null;
|
|
76
|
+
/** Hosting for this frame. When the key is set, it replaces the shell `hosting`. */
|
|
77
|
+
hosting?: HostingConfig | null;
|
|
35
78
|
/** When false, omit layoutChrome (modal / drawer frames). Default true. */
|
|
36
79
|
includeLayoutChrome?: boolean;
|
|
37
80
|
/** Merge this frame's action-bar insets into layoutChrome. */
|
|
@@ -42,6 +85,7 @@ export const buildSettingsForPropagation = (
|
|
|
42
85
|
let result: Settings = {
|
|
43
86
|
...settings,
|
|
44
87
|
appearance: appearance ?? settings.appearance,
|
|
88
|
+
...(options && 'settingsUser' in options ? { user: options.settingsUser ?? null } : {}),
|
|
45
89
|
};
|
|
46
90
|
|
|
47
91
|
if (options?.includeLayoutChrome !== false) {
|
|
@@ -101,41 +145,25 @@ export const buildSettingsForPropagation = (
|
|
|
101
145
|
result = { ...result, administration: null };
|
|
102
146
|
}
|
|
103
147
|
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
result = {
|
|
108
|
-
...result,
|
|
109
|
-
storage: {
|
|
110
|
-
url: storageUrl,
|
|
111
|
-
...(filesUrl ? { filesUrl } : {}),
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
} else {
|
|
115
|
-
result = { ...result, storage: null };
|
|
116
|
-
}
|
|
117
|
-
|
|
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
|
-
}
|
|
148
|
+
const storageSource = options && 'storage' in options ? options.storage : config?.storage;
|
|
149
|
+
const hostingSource = options && 'hosting' in options ? options.hosting : config?.hosting;
|
|
150
|
+
const emailSource = options && 'email' in options ? options.email : config?.email;
|
|
132
151
|
|
|
133
|
-
result = {
|
|
152
|
+
result = {
|
|
153
|
+
...result,
|
|
154
|
+
storage: propagateStorage(storageSource),
|
|
155
|
+
hosting: propagateHosting(hostingSource),
|
|
156
|
+
email: propagateEmail(emailSource),
|
|
157
|
+
};
|
|
134
158
|
|
|
135
|
-
const
|
|
159
|
+
const shellAuthBackendBaseUrl =
|
|
136
160
|
config?.backend?.type === 'shellui' && config.backend.url?.trim()
|
|
137
161
|
? config.backend.url.trim().replace(/\/+$/, '')
|
|
138
162
|
: null;
|
|
163
|
+
const authBackendBaseUrl =
|
|
164
|
+
options && 'authBackendBaseUrl' in options
|
|
165
|
+
? (options.authBackendBaseUrl ?? null)
|
|
166
|
+
: shellAuthBackendBaseUrl;
|
|
139
167
|
|
|
140
168
|
result = {
|
|
141
169
|
...result,
|
|
@@ -63,6 +63,8 @@
|
|
|
63
63
|
"walletLoginFailed": "Unable to complete Ethereum wallet login.",
|
|
64
64
|
"signInCouldNotContinue": "Sign-in could not continue.",
|
|
65
65
|
"magicLinkStaffDisabled": "Staff accounts can't sign in with an email link. Sign in with your usual sign-in method instead.",
|
|
66
|
+
"magicLinkOtherBrowser": "Open this link in the browser where you requested it, or request a new one.",
|
|
67
|
+
"pkceFailed": "Sign-in could not be verified. Start signing in again from this browser.",
|
|
66
68
|
"magicLinkMethod": "magic link",
|
|
67
69
|
"redirectNotAllowedHint": " Add this origin in shellui-auth (Django admin or shellui-admin → Company → Login redirect URLs), for example: {{origin}}."
|
|
68
70
|
},
|