@shellui/core 0.7.0-alpha.5 → 0.7.0-alpha.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shellui/core",
3
- "version": "0.7.0-alpha.5",
3
+ "version": "0.7.0-alpha.7",
4
4
  "description": "Shellui Core - Core React application runtime",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -73,7 +73,7 @@
73
73
  "workbox-routing": "^7.4.0",
74
74
  "workbox-strategies": "^7.4.0",
75
75
  "workbox-window": "^7.4.0",
76
- "@shellui/sdk": "0.7.0-alpha.5"
76
+ "@shellui/sdk": "0.7.0-alpha.7"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "react": "^18.0.0 || ^19.0.0",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "email": {
81
81
  "$ref": "#/definitions/EmailConfig",
82
- "description": "Email-service connection. Propagated to iframes via SDK settings. When `email` is set and `url` is omitted, the shell sends `https://email.shellui.com`. `showInAdmin: false` hides Admin → Email."
82
+ "description": "Email-service connection. Propagated to iframes via SDK settings. Without `url`, the shell sends no email service (`null`). `showInAdmin: false` hides Admin → Email."
83
83
  },
84
84
  "theme": {
85
85
  "$ref": "#/definitions/ThemeRef",
@@ -328,7 +328,7 @@
328
328
  },
329
329
  "provider": {
330
330
  "type": "string",
331
- "description": "OAuth provider for silent sign-in, such as `google`. When omitted, the shell uses the first `backend.login.oauthProviders` entry."
331
+ "description": "`upstream`: the shell gets the app session by OAuth token exchange (RFC 8693), trading its own access token at this server. Recommended for Shellui regions. Any other value, such as `google`, is the OAuth provider for silent sign-in. When omitted, the shell uses the first `backend.login.oauthProviders` entry."
332
332
  }
333
333
  },
334
334
  "required": ["url"],
@@ -356,6 +356,13 @@
356
356
  "type": "string"
357
357
  },
358
358
  "description": "Exact origins of identity servers a child may sign in to, such as `https://id.eu.shellui.com`. The shell keeps a separate session per server and never sends its own token to a child. Omit to give children no token."
359
+ },
360
+ "serviceOrigins": {
361
+ "type": "array",
362
+ "items": {
363
+ "type": "string"
364
+ },
365
+ "description": "Exact origins of service URLs (email, storage, files, hosting) a host may pass to a child with `ShelluiFrame` or `createAppFrame`, such as `https://storage.eu.shellui.com`. No wildcards. A URL outside this list, or a missing one, reaches the child as `null`. Omit to send children no service URLs."
359
366
  }
360
367
  },
361
368
  "required": ["origins"],
@@ -367,7 +374,7 @@
367
374
  "properties": {
368
375
  "url": {
369
376
  "type": "string",
370
- "description": "Base URL of email-service. Default: `https://email.shellui.com` when `email` is set and this is omitted. Local: `http://localhost:8003`."
377
+ "description": "Base URL of email-service. Required for apps to get email. There is no built-in default. Local: `http://localhost:8003`."
371
378
  },
372
379
  "showInAdmin": {
373
380
  "type": "boolean",
@@ -375,7 +382,7 @@
375
382
  }
376
383
  },
377
384
  "additionalProperties": false,
378
- "description": "Optional email-service wiring for Admin → Email and iframe apps. When `email` is set and `url` is omitted, the shell uses `https://email.shellui.com`."
385
+ "description": "Optional email-service wiring for Admin → Email and iframe apps. The shell never invents a URL: without `url`, apps get no email service."
379
386
  },
380
387
  "StorageConfig": {
381
388
  "type": "object",
@@ -170,3 +170,159 @@ describe('childFrameAuthPropagationOptions', () => {
170
170
  expect(options.settingsUser).toBeNull();
171
171
  });
172
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
+ });
@@ -11,8 +11,16 @@ export type ChildFrameEntry = {
11
11
  frameId: string;
12
12
  url: string;
13
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[];
14
18
  };
15
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
+
16
24
  export type ChildFrameRegistration =
17
25
  | { ok: true; entry: ChildFrameEntry }
18
26
  | { ok: false; reason: string };
@@ -45,6 +53,32 @@ function originList(values: unknown): Set<string> {
45
53
  return out;
46
54
  }
47
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
+
48
82
  /**
49
83
  * Check a `SHELLUI_CHILD_FRAME_REGISTER` message. `from` must be exactly one hop:
50
84
  * a child app cannot register frames by sending the message through its host.
@@ -59,7 +93,7 @@ export function validateChildFrameRegistration(input: {
59
93
  if (from.length !== 1) return { ok: false, reason: 'not sent by a direct app frame' };
60
94
  if (!input.hostSrc) return { ok: false, reason: 'unknown host frame' };
61
95
  const payload = input.payload as
62
- | { frameId?: unknown; url?: unknown; backend?: unknown }
96
+ | { frameId?: unknown; url?: unknown; backend?: unknown; services?: unknown }
63
97
  | null
64
98
  | undefined;
65
99
  const frameId = typeof payload?.frameId === 'string' ? payload.frameId.trim() : '';
@@ -102,9 +136,18 @@ export function validateChildFrameRegistration(input: {
102
136
  if (!identity) return { ok: false, reason: 'child identity server is invalid' };
103
137
  }
104
138
 
139
+ const { services, rejected } = resolveChildFrameServices(payload?.services, rules.serviceOrigins);
140
+
105
141
  return {
106
142
  ok: true,
107
- entry: { hostUuid: from[0], frameId, url: payload?.url as string, identity },
143
+ entry: {
144
+ hostUuid: from[0],
145
+ frameId,
146
+ url: payload?.url as string,
147
+ identity,
148
+ services,
149
+ rejectedServices: rejected,
150
+ },
108
151
  };
109
152
  }
110
153
 
@@ -174,13 +174,16 @@ export function frameAuthPropagationOptions(input: {
174
174
  /**
175
175
  * Auth fields for a child app hosted inside an embedded app (`createAppFrame`).
176
176
  * The shell token is never sent. With no allowed identity server the child gets
177
- * no token, no user and no service URLs.
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`.
178
179
  */
179
180
  export function childFrameAuthPropagationOptions(input: {
180
181
  identity: ResolvedAppBackend | null;
181
182
  getAppSession: (key: string) => AuthSession | null;
183
+ services?: Partial<Record<'email' | 'storage' | 'files' | 'hosting', string | null>> | null;
182
184
  }): FrameAuthPropagationOptions {
183
185
  const { identity, getAppSession } = input;
186
+ const allowed = input.services ?? {};
184
187
  const session = identity ? getAppSession(identity.key) : null;
185
188
  return toPropagationOptions({
186
189
  includeAuthAccessToken: Boolean(identity),
@@ -189,6 +192,13 @@ export function childFrameAuthPropagationOptions(input: {
189
192
  authBackendBaseUrl: identity?.type === 'shellui' ? identity.url : null,
190
193
  overrideUser: true,
191
194
  settingsUser: settingsUserFromSession(session),
192
- services: serviceOverrides(null, true),
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
+ },
193
203
  });
194
204
  }
@@ -252,6 +252,13 @@ export interface ChildFramesConfig {
252
252
  * and never sends its own token to a child. Omit to give children no token.
253
253
  */
254
254
  backendOrigins?: string[];
255
+ /**
256
+ * Exact origins of service URLs (email, storage, hosting) a host may pass to
257
+ * a child with `ShelluiFrame` or `createAppFrame`, such as
258
+ * `https://storage.eu.shellui.com`. No wildcards. A URL outside this list, or
259
+ * a missing one, reaches the child as `null`. Omit to send children no service URLs.
260
+ */
261
+ serviceOrigins?: string[];
255
262
  }
256
263
 
257
264
  /**
@@ -268,7 +275,9 @@ export interface AppBackendConfig {
268
275
  /** Public key when `type` is `supabase`. */
269
276
  publishableKey?: string;
270
277
  /**
271
- * OAuth provider for silent sign-in, such as `google`.
278
+ * `upstream`: the shell gets the app session by OAuth token exchange (RFC 8693),
279
+ * trading its own access token at this server. Recommended for Shellui regions.
280
+ * Any other value, such as `google`, is the OAuth provider for silent sign-in.
272
281
  * When omitted, the shell uses the first `backend.login.oauthProviders` entry.
273
282
  */
274
283
  provider?: string;
@@ -357,12 +366,12 @@ export interface HostingConfig {
357
366
 
358
367
  /**
359
368
  * Optional email-service wiring for Admin → Email and iframe apps.
360
- * When `email` is set and `url` is omitted, the shell uses `https://email.shellui.com`.
369
+ * The shell never invents a URL: without `url`, apps get no email service.
361
370
  */
362
371
  export interface EmailConfig {
363
372
  /**
364
373
  * Base URL of email-service.
365
- * Default: `https://email.shellui.com` when `email` is set and this is omitted.
374
+ * Required for apps to get email. There is no built-in default.
366
375
  * Local: `http://localhost:8003`.
367
376
  */
368
377
  url?: string;
@@ -447,7 +456,7 @@ export interface ShellUIConfig {
447
456
  hosting?: HostingConfig;
448
457
  /**
449
458
  * Email-service connection. Propagated to iframes via SDK settings.
450
- * When `email` is set and `url` is omitted, the shell sends `https://email.shellui.com`.
459
+ * Without `url`, the shell sends no email service (`null`).
451
460
  * `showInAdmin: false` hides Admin → Email.
452
461
  */
453
462
  email?: EmailConfig;
@@ -244,6 +244,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
244
244
  ...childFrameAuthPropagationOptions({
245
245
  identity: entry?.identity ?? null,
246
246
  getAppSession: getAppBackendSession,
247
+ services: entry?.services ?? null,
247
248
  }),
248
249
  includeLayoutChrome: false,
249
250
  frameUuid: path[path.length - 1],
@@ -688,6 +689,13 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
688
689
  }
689
690
  addChildFrame(result.entry);
690
691
  const { entry } = result;
692
+ if (entry.rejectedServices.length) {
693
+ // Keys only: the URLs themselves stay out of the log.
694
+ logger.warn('Dropped child app service URLs not in childFrames.serviceOrigins', {
695
+ origin: safeOrigin(entry.url),
696
+ services: entry.rejectedServices,
697
+ });
698
+ }
691
699
  logger.info('Child app frame registered', {
692
700
  origin: safeOrigin(entry.url),
693
701
  identity: entry.identity?.url ?? null,
@@ -287,25 +287,26 @@ describe('buildSettingsForPropagation', () => {
287
287
  expect(result.email).toEqual({ url: 'http://localhost:8003' });
288
288
  });
289
289
 
290
- it('uses the production email url when email is set without url', () => {
290
+ it('sends no email when email is set without url (no built-in default)', () => {
291
291
  const config = {
292
292
  email: {},
293
293
  } as ShellUIConfig;
294
294
 
295
295
  const result = buildSettingsForPropagation(baseSettings, config, 'en');
296
- expect(result.email).toEqual({ url: 'https://email.shellui.com' });
296
+ expect(result.email).toBeNull();
297
297
  });
298
298
 
299
- it('propagates showInAdmin false for email and keeps the default url', () => {
299
+ it('propagates showInAdmin false for email', () => {
300
300
  const config = {
301
301
  email: {
302
+ url: 'http://localhost:8003',
302
303
  showInAdmin: false,
303
304
  },
304
305
  } as ShellUIConfig;
305
306
 
306
307
  const result = buildSettingsForPropagation(baseSettings, config, 'en');
307
308
  expect(result.email).toEqual({
308
- url: 'https://email.shellui.com',
309
+ url: 'http://localhost:8003',
309
310
  showInAdmin: false,
310
311
  });
311
312
  });
@@ -560,7 +561,7 @@ describe('buildSettingsForPropagation', () => {
560
561
  expect(json).not.toContain('https://email.shellui.com');
561
562
  });
562
563
 
563
- it('uses the default email URL when a foreign app sets an empty email object', () => {
564
+ it('sends no email when a foreign app sets an empty email object', () => {
564
565
  const withEmptyEmail = {
565
566
  ...appConfig,
566
567
  navigation: (appConfig.navigation ?? []).map((item) =>
@@ -580,7 +581,7 @@ describe('buildSettingsForPropagation', () => {
580
581
  'en',
581
582
  options,
582
583
  );
583
- expect(result.email).toEqual({ url: 'https://email.shellui.com' });
584
+ expect(result.email).toBeNull();
584
585
  expect(result.storage).toBeNull();
585
586
  expect(result.hosting).toBeNull();
586
587
  const json = JSON.stringify(result);
@@ -618,7 +619,7 @@ describe('buildSettingsForPropagation', () => {
618
619
  );
619
620
  expect(result.accessToken).toBe(shellToken);
620
621
  expect(result.authBackendBaseUrl).toBe('https://id.example.com');
621
- expect(result.email).toEqual({ url: 'https://email.shellui.com' });
622
+ expect(result.email).toBeNull();
622
623
  expect(result.storage).toEqual(shellServices.storage);
623
624
  expect(result.hosting).toEqual(shellServices.hosting);
624
625
  });
@@ -15,15 +15,13 @@ import {
15
15
  getPublishedLayoutChrome,
16
16
  } from '../../layouts/floating/layoutChromeStore';
17
17
 
18
- /** Production email-service origin. No trailing slash. */
19
- const DEFAULT_EMAIL_SERVICE_URL = 'https://email.shellui.com';
20
-
21
18
  const propagateEmail = (email: EmailConfig | null | undefined): SettingsEmail | null => {
22
- if (!email) return null;
23
- const url = email.url?.trim().replace(/\/+$/, '') || DEFAULT_EMAIL_SERVICE_URL;
19
+ // No built-in default: email must come from config or the host app.
20
+ const url = email?.url?.trim().replace(/\/+$/, '') || null;
21
+ if (!url) return null;
24
22
  return {
25
23
  url,
26
- ...(email.showInAdmin === false ? { showInAdmin: false } : {}),
24
+ ...(email?.showInAdmin === false ? { showInAdmin: false } : {}),
27
25
  };
28
26
  };
29
27