@egen-civitas/esm-embed-host 0.4.0 → 0.5.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @egen-civitas/esm-embed-host
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 721c7f8: Droits d'iframe négociés et voie unique SDK.
8
+
9
+ - **protocole** : bloc `iframe` (`sandbox[]`, `allow[]`) dans la déclaration `egen-config.json` (demande) et dans le plafond approuvé ; listes blanches strictes (`IFRAME_SANDBOX_TOKENS`, `IFRAME_ALLOW_TOKENS`, jamais de `allow-top-navigation*`) ; `validateIframeRights`, `effectiveIframe` (demande ∩ plafond), `sanitizeIframeRights` ; `config` publique validée (≤ 8 Ko) ; `ApprovedGrants` accepte `iframe`. **Breaking** : `SUPPORTED_PROTOCOLS` ne contient plus que `2` (le protocole 1 / pont 1.1 est retiré) ; `negotiateProtocol(1)` → `null`.
10
+ - **hôte** : option `iframe` (droits effectifs) qui étend le socle et pose les attributs `sandbox` et `allow`, avec revalidation par liste blanche. **Breaking** : l'option `sandbox` est remplacée par `iframe` ; l'option `legacy` et le pont 1.1 (`handleLegacy`, `legacySend`) sont retirés ; la poignée de main ne propose plus que le protocole 2.
11
+ - **testing** : `createTestHost` accepte `manifestIframe` et expose `iframe` (droits effectifs) ; `egen-embed-check` valide la forme `iframe`, rappelle l'approbation requise et signale les permissions sensibles ; le simulateur applique les droits d'iframe.
12
+ - **client** : documentation (les droits se demandent dans `egen-config.json`), le manifeste s'appelle désormais `egen-config.json`.
13
+
14
+ ### Patch Changes
15
+
16
+ - 721c7f8: Retrait du paquet `@egen-civitas/esm-nextjs-utils` (pont 1.1 et script `egen-bridge.js`) : le SDK `esm-embed-client` est l'unique voie d'intégration d'une app embarquée. Les versions déjà publiées de `esm-nextjs-utils` doivent être marquées dépréciées sur npm (`npm deprecate`).
17
+ - Updated dependencies [721c7f8]
18
+ - @egen-civitas/esm-embed-protocol@0.5.0
19
+
3
20
  ## 0.4.0
4
21
 
5
22
  ### Minor Changes
package/README.md CHANGED
@@ -1,19 +1,22 @@
1
1
  # @egen-civitas/esm-embed-host
2
2
 
3
3
  Hôte (côté Shell/Core) des applications **embarquées** : iframe sécurisée, poignée de main v2, application des grants,
4
- fournisseurs de capacités, navigation partagée Core ↔ app, et compatibilité du pont 1.1 (`esm-nextjs-utils`).
4
+ fournisseurs de capacités, navigation partagée Core ↔ app. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
5
5
  Spécification : `docs/integration-apps/17-sdk-embed-protocole-v2.md` du dépôt Core.
6
6
 
7
7
  ```ts
8
- import { effectiveGrants } from '@egen-civitas/esm-embed-protocol';
8
+ import { effectiveGrants, effectiveIframe } from '@egen-civitas/esm-embed-protocol';
9
9
  import { createEmbedHost } from '@egen-civitas/esm-embed-host';
10
10
 
11
- const grants = effectiveGrants(manifest.capabilities, { notifications: {}, events: { publish: ['app.studio.*'] } });
11
+ const approved = { notifications: {}, events: { publish: ['app.studio.*'] }, iframe: { sandbox: ['allow-downloads'], allow: ['clipboard-write'] } };
12
+ const grants = effectiveGrants(manifest.capabilities, approved);
13
+ const iframe = effectiveIframe(manifest.iframe, approved.iframe); // droits d'iframe effectifs (demande ∩ plafond)
12
14
 
13
15
  const host = createEmbedHost({
14
16
  moduleName: manifest.name,
15
17
  src: manifest.url,
16
18
  grants,
19
+ iframe,
17
20
  navigation: { route: manifest.route, mode: manifest.navigation.mode },
18
21
  providers: {
19
22
  locale: { get, subscribe }, // services dont le Core est la source
@@ -27,5 +30,6 @@ host.mount(container); // …; host.destroy() au démontage
27
30
 
28
31
  - **Moindre privilège** : la table d'appels de la connexion ne contient que les capacités accordées **et** servies. Une capacité accordée sans fournisseur est refusée (`UNAVAILABLE`).
29
32
  - **Règle d'or** : le Core ne relaie ni identité/session, ni droits, ni thème, ni appels API authentifiés (ils viennent de Keycloak, des backends, du service de thèmes). Aucun jeton ne transite.
30
- - **Pont 1.1** : une app qui ne parle pas le protocole 2 continue de fonctionner (`ready`, `location`, `navigate`, `resize`, `title`, langue) — sans session. Désactivable : `legacy: false`.
33
+ - **Droits d'iframe négociés** : le socle (`allow-scripts allow-same-origin allow-forms allow-popups`) s'applique à toute app ; `iframe` (droits effectifs) ne peut que l'étendre (`allow-downloads`, `allow-modals`, `clipboard-*`, `fullscreen`…). L'hôte revalide chaque jeton par liste blanche et pose `sandbox` et `allow`. `allow-same-origin` + `allow-scripts` sur la même origine que le Shell est signalé (bac à sable sans effet).
34
+ - **Voie unique** : le pont 1.1 (`{ egen: 1 }`) est retiré ; ses messages sont ignorés. Une app doit adopter `@egen-civitas/esm-embed-client`.
31
35
  - `HostConnection` est indépendante du DOM (testable avec le vrai client, voir `src/__tests__/harness.ts`).
@@ -210,8 +210,7 @@ import { availableCapabilities, createCapabilityTable } from './table.js';
210
210
  kind: 'hello',
211
211
  nonce: this.nonce,
212
212
  protocols: [
213
- EGEN_EMBED_PROTOCOL,
214
- 1
213
+ EGEN_EMBED_PROTOCOL
215
214
  ],
216
215
  hostVersion: this.o.hostVersion
217
216
  }));
@@ -229,8 +228,7 @@ import { availableCapabilities, createCapabilityTable } from './table.js';
229
228
  kind: 'hello',
230
229
  nonce: this.nonce,
231
230
  protocols: [
232
- EGEN_EMBED_PROTOCOL,
233
- 1
231
+ EGEN_EMBED_PROTOCOL
234
232
  ],
235
233
  hostVersion: this.o.hostVersion
236
234
  }));
package/dist/host.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type Limits } from '@egen-civitas/esm-embed-protocol';
1
+ import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type IframeRights, type Limits } from '@egen-civitas/esm-embed-protocol';
2
2
  import { HostConnection } from './connection.js';
3
3
  import { type NavigationOptions } from './navigation.js';
4
4
  import type { HostProviders } from './providers.js';
5
5
  export interface EmbedHostOptions {
6
- /** Nom du module (= `name` du manifeste). */
6
+ /** Nom du module (= `name` de `egen-config.json`). */
7
7
  moduleName: string;
8
8
  /** URL de base de l'application embarquée. */
9
9
  src: string;
@@ -12,8 +12,11 @@ export interface EmbedHostOptions {
12
12
  /** Grants effectifs (`effectiveGrants(manifeste.capabilities, approuvés)`). */
13
13
  grants: EffectiveGrants;
14
14
  providers: HostProviders;
15
- /** Attribut `sandbox` (défaut : scripts, même origine, formulaires, popups). */
16
- sandbox?: string;
15
+ /**
16
+ * Droits d'iframe EFFECTIFS (`effectiveIframe(manifeste.iframe, approuvés.iframe)`) : ils étendent le socle
17
+ * (`allow-scripts allow-same-origin allow-forms allow-popups`). Les jetons hors liste blanche sont écartés.
18
+ */
19
+ iframe?: IframeRights;
17
20
  title?: string;
18
21
  minHeight?: number;
19
22
  /** Navigation partagée Core ↔ app (URL du Core = source de vérité). Absent ou `none` : opaque. */
@@ -22,8 +25,6 @@ export interface EmbedHostOptions {
22
25
  onNavigate?: (to: string) => void;
23
26
  limits?: Partial<Limits>;
24
27
  hostVersion?: string;
25
- /** Accepter aussi les apps qui parlent encore le pont 1.1 (défaut : oui). */
26
- legacy?: boolean;
27
28
  window?: Window;
28
29
  onConnect?(granted: CapabilityGranted[], denied: CapabilityDenied[]): void;
29
30
  onClose?(reason: string): void;
@@ -38,7 +39,7 @@ export interface EmbedHost {
38
39
  }
39
40
  /**
40
41
  * Hôte d'une app embarquée : iframe sécurisée, poignée de main v2 (`HostConnection`), navigation partagée,
41
- * événements de cycle de vie, et pont 1.1 pour les apps qui ne parlent pas encore le protocole 2.
42
+ * événements de cycle de vie. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
42
43
  * Sécurité : messages acceptés seulement de l'iframe elle-même ET de l'origine autorisée ; envoi toujours avec une origine explicite.
43
44
  */
44
45
  export declare function createEmbedHost(opts: EmbedHostOptions): EmbedHost;
@@ -1 +1 @@
1
- {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA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,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,CAAC,OAAO,EAAE,iBAAiB,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;IAC3E,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,KAAK,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,2IAA2I;IAC3I,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,IAAI,IAAI,CAAC;CACjB;AAKD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,CA0IjE"}
package/dist/host.js CHANGED
@@ -1,3 +1,11 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_without_holes(arr) {
7
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
8
+ }
1
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
10
  try {
3
11
  var info = gen[key](arg);
@@ -40,6 +48,12 @@ function _define_property(obj, key, value) {
40
48
  }
41
49
  return obj;
42
50
  }
51
+ function _iterable_to_array(iter) {
52
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
+ }
54
+ function _non_iterable_spread() {
55
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
43
57
  function _object_spread(target) {
44
58
  for(var i = 1; i < arguments.length; i++){
45
59
  var source = arguments[i] != null ? arguments[i] : {};
@@ -79,6 +93,17 @@ function _object_spread_props(target, source) {
79
93
  }
80
94
  return target;
81
95
  }
96
+ function _to_consumable_array(arr) {
97
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
98
+ }
99
+ function _unsupported_iterable_to_array(o, minLen) {
100
+ if (!o) return;
101
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
102
+ var n = Object.prototype.toString.call(o).slice(8, -1);
103
+ if (n === "Object" && o.constructor) n = o.constructor.name;
104
+ if (n === "Map" || n === "Set") return Array.from(n);
105
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
106
+ }
82
107
  function _ts_generator(thisArg, body) {
83
108
  var f, y, t, _ = {
84
109
  label: 0,
@@ -178,16 +203,22 @@ function _ts_generator(thisArg, body) {
178
203
  };
179
204
  }
180
205
  }
206
+ import { sanitizeIframeRights } from '@egen-civitas/esm-embed-protocol';
181
207
  import { createBus } from './bus.js';
182
208
  import { HostConnection } from './connection.js';
183
209
  import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensitive, toAppPath, toCorePath, normalizeAppPath } from './navigation.js';
184
- var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups';
210
+ /** Socle d'isolation appliqué à toute app embarquée ; les droits négociés (`iframe`) ne peuvent que l'étendre. */ var BASE_SANDBOX = [
211
+ 'allow-scripts',
212
+ 'allow-same-origin',
213
+ 'allow-forms',
214
+ 'allow-popups'
215
+ ];
185
216
  /**
186
217
  * Hôte d'une app embarquée : iframe sécurisée, poignée de main v2 (`HostConnection`), navigation partagée,
187
- * événements de cycle de vie, et pont 1.1 pour les apps qui ne parlent pas encore le protocole 2.
218
+ * événements de cycle de vie. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
188
219
  * Sécurité : messages acceptés seulement de l'iframe elle-même ET de l'origine autorisée ; envoi toujours avec une origine explicite.
189
220
  */ export function createEmbedHost(opts) {
190
- var _opts_window, _opts_navigation_mode, _opts_navigation_mode1, _currentCorePath, _toAppPath, _opts_allowedOrigin, _opts_sandbox, _opts_title, _opts_minHeight;
221
+ var _opts_window, _opts_navigation_mode, _opts_navigation_mode1, _currentCorePath, _toAppPath, _opts_allowedOrigin, _opts_title, _opts_minHeight;
191
222
  var win = (_opts_window = opts.window) !== null && _opts_window !== void 0 ? _opts_window : window;
192
223
  var doc = win.document;
193
224
  var nav = opts.navigation && ((_opts_navigation_mode = opts.navigation.mode) !== null && _opts_navigation_mode !== void 0 ? _opts_navigation_mode : 'history') !== 'none' ? _object_spread_props(_object_spread({}, opts.navigation), {
@@ -208,7 +239,8 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
208
239
  var src = nav ? buildEmbedSrc(opts.src, initialAppPath, nav.mode) : opts.src;
209
240
  var origin = (_opts_allowedOrigin = opts.allowedOrigin) !== null && _opts_allowedOrigin !== void 0 ? _opts_allowedOrigin : new URL(src, win.location.href).origin;
210
241
  if (origin === '*' || origin === 'null') throw new Error('allowedOrigin invalide : une origine explicite est requise.');
211
- var sandbox = (_opts_sandbox = opts.sandbox) !== null && _opts_sandbox !== void 0 ? _opts_sandbox : DEFAULT_SANDBOX;
242
+ var rights = sanitizeIframeRights(opts.iframe);
243
+ var sandbox = _to_consumable_array(new Set(_to_consumable_array(BASE_SANDBOX).concat(_to_consumable_array(rights.sandbox)))).join(' ');
212
244
  if (origin === win.location.origin && /allow-scripts/.test(sandbox) && /allow-same-origin/.test(sandbox)) {
213
245
  console.warn("[egen] ".concat(opts.moduleName, " : application embarqu\xe9e de m\xeame origine que le Shell avec \xab allow-scripts allow-same-origin \xbb : le bac \xe0 sable est sans effet. H\xe9berger l'application sur une autre origine (sous-domaine)."));
214
246
  }
@@ -216,6 +248,7 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
216
248
  iframe.src = src;
217
249
  iframe.title = (_opts_title = opts.title) !== null && _opts_title !== void 0 ? _opts_title : opts.moduleName;
218
250
  iframe.setAttribute('sandbox', sandbox);
251
+ if (rights.allow.length) iframe.setAttribute('allow', rights.allow.join('; '));
219
252
  iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
220
253
  iframe.setAttribute('data-egen-fill', '');
221
254
  iframe.style.cssText = "width:100%;border:0;display:block;min-height:".concat((_opts_minHeight = opts.minHeight) !== null && _opts_minHeight !== void 0 ? _opts_minHeight : 400, "px");
@@ -223,20 +256,11 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
223
256
  var allowLocation = createRateLimiter();
224
257
  var stop = [];
225
258
  var seq = 0;
226
- var legacySeen = false;
227
- var legacyReady = false;
228
259
  var postRaw = function postRaw(message, transfer) {
229
260
  var _iframe_contentWindow;
230
261
  return (_iframe_contentWindow = iframe.contentWindow) === null || _iframe_contentWindow === void 0 ? void 0 : _iframe_contentWindow.postMessage(message, origin, transfer);
231
262
  };
232
- var legacySend = function legacySend(message) {
233
- return postRaw({
234
- egen: 1,
235
- moduleName: opts.moduleName,
236
- message: message
237
- });
238
- };
239
- /** Page courante annoncée par l'app → URL du Core (partagé entre le protocole 2 et le pont 1.1). */ var reportLocation = function reportLocation(path, o) {
263
+ /** Page courante annoncée par l'app → URL du Core. */ var reportLocation = function reportLocation(path, o) {
240
264
  if (!nav || !allowLocation()) return;
241
265
  if (typeof (o === null || o === void 0 ? void 0 : o.title) === 'string') {
242
266
  var _nav_onTitle;
@@ -279,137 +303,14 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
279
303
  onConnect: opts.onConnect,
280
304
  onClose: opts.onClose
281
305
  });
282
- /**
283
- * Pont 1.1 : compatibilité des apps qui ne parlent pas encore le protocole 2. La session n'est PLUS transmise (règle d'or,
284
- * doc 17 §2) : une app obtient son identité auprès de Keycloak. Seuls restent la langue, la navigation, le titre et la hauteur.
285
- */ var handleLegacy = function handleLegacy(data) {
286
- return _async_to_generator(function() {
287
- var msg, _, _win_i18next, locale, _tmp, _controls_navigate, _controls_resize;
288
- return _ts_generator(this, function(_state) {
289
- switch(_state.label){
290
- case 0:
291
- if (opts.legacy === false || connection.connected) return [
292
- 2
293
- ];
294
- if (!data || data.egen !== 1 || data.moduleName !== opts.moduleName || !data.message || typeof data.message.kind !== 'string') return [
295
- 2
296
- ];
297
- msg = data.message;
298
- _ = msg.kind;
299
- switch(_){
300
- case 'ready':
301
- return [
302
- 3,
303
- 1
304
- ];
305
- case 'navigate':
306
- return [
307
- 3,
308
- 5
309
- ];
310
- case 'resize':
311
- return [
312
- 3,
313
- 6
314
- ];
315
- case 'title':
316
- return [
317
- 3,
318
- 7
319
- ];
320
- case 'location':
321
- return [
322
- 3,
323
- 8
324
- ];
325
- }
326
- return [
327
- 3,
328
- 9
329
- ];
330
- case 1:
331
- legacySeen = true;
332
- legacyReady = true;
333
- if (!opts.providers.locale) return [
334
- 3,
335
- 3
336
- ];
337
- return [
338
- 4,
339
- opts.providers.locale.get()
340
- ];
341
- case 2:
342
- _tmp = _state.sent();
343
- return [
344
- 3,
345
- 4
346
- ];
347
- case 3:
348
- _tmp = (_win_i18next = win.i18next) === null || _win_i18next === void 0 ? void 0 : _win_i18next.language;
349
- _state.label = 4;
350
- case 4:
351
- locale = _tmp;
352
- legacySend({
353
- kind: 'init',
354
- payload: {
355
- moduleName: opts.moduleName,
356
- locale: locale,
357
- spaBase: spaBase(),
358
- navigation: nav ? {
359
- mode: nav.mode,
360
- route: nav.route
361
- } : undefined
362
- }
363
- });
364
- return [
365
- 3,
366
- 9
367
- ];
368
- case 5:
369
- (_controls_navigate = controls.navigate) === null || _controls_navigate === void 0 ? void 0 : _controls_navigate.call(controls, msg.to);
370
- return [
371
- 3,
372
- 9
373
- ];
374
- case 6:
375
- (_controls_resize = controls.resize) === null || _controls_resize === void 0 ? void 0 : _controls_resize.call(controls, msg.height);
376
- return [
377
- 3,
378
- 9
379
- ];
380
- case 7:
381
- if (typeof msg.title === 'string') iframe.title = msg.title.slice(0, 200);
382
- return [
383
- 3,
384
- 9
385
- ];
386
- case 8:
387
- legacySeen = true;
388
- reportLocation(msg.path, {
389
- replace: !!msg.replace,
390
- title: msg.title
391
- });
392
- return [
393
- 3,
394
- 9
395
- ];
396
- case 9:
397
- return [
398
- 2
399
- ];
400
- }
401
- });
402
- })();
403
- };
404
306
  var onMessage = function onMessage(event) {
405
307
  if (event.source !== iframe.contentWindow || event.origin !== origin) return;
406
- if (!connection.handle(event.data)) void handleLegacy(event.data);
308
+ connection.handle(event.data);
407
309
  };
408
310
  return {
409
311
  iframe: iframe,
410
312
  connection: connection,
411
313
  mount: function mount(container) {
412
- var _p_locale;
413
314
  win.addEventListener('message', onMessage);
414
315
  stop.push(function() {
415
316
  return win.removeEventListener('message', onMessage);
@@ -432,11 +333,6 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
432
333
  path: appPath,
433
334
  seq: ++seq
434
335
  });
435
- else if (legacySeen) legacySend({
436
- kind: 'goto',
437
- path: appPath,
438
- seq: ++seq
439
- });
440
336
  else iframe.src = buildEmbedSrc(opts.src, appPath, nav.mode);
441
337
  };
442
338
  win.addEventListener('single-spa:routing-event', onCoreLocation);
@@ -463,14 +359,6 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
463
359
  win.removeEventListener('focus', onFocus);
464
360
  win.removeEventListener('blur', onBlur);
465
361
  });
466
- // Pont 1.1 : la langue est poussée après `ready`.
467
- var p = opts.providers;
468
- if ((_p_locale = p.locale) === null || _p_locale === void 0 ? void 0 : _p_locale.subscribe) stop.push(p.locale.subscribe(function(l) {
469
- return legacyReady && !connection.connected && l && legacySend({
470
- kind: 'locale',
471
- locale: l
472
- });
473
- }));
474
362
  container.appendChild(iframe);
475
363
  },
476
364
  canLeave: function canLeave() {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Navigation partagée Shell ↔ application embarquée (protocole 1.1, additif).
2
+ * Navigation partagée Shell ↔ application embarquée (capacité `navigation` du protocole 2).
3
3
  *
4
4
  * L'URL du Core reste la source de vérité, comme pour une app interne : `<base>/<route>/<chemin-de-l'app>?q#h`.
5
5
  * Ce module ne contient que des fonctions pures (aucun accès au DOM), testées isolément.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Navigation partagée Shell ↔ application embarquée (protocole 1.1, additif).
2
+ * Navigation partagée Shell ↔ application embarquée (capacité `navigation` du protocole 2).
3
3
  *
4
4
  * L'URL du Core reste la source de vérité, comme pour une app interne : `<base>/<route>/<chemin-de-l'app>?q#h`.
5
5
  * Ce module ne contient que des fonctions pures (aucun accès au DOM), testées isolément.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egen-civitas/esm-embed-host",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Hôte (côté Shell/Core) des applications embarquées : iframe sécurisée, poignée de main v2, grants, fournisseurs de capacités, navigation partagée, compatibilité du pont 1.1.",
6
6
  "type": "module",
@@ -57,7 +57,7 @@
57
57
  "access": "public"
58
58
  },
59
59
  "devDependencies": {
60
- "@egen-civitas/esm-embed-client": "^0.3.0",
60
+ "@egen-civitas/esm-embed-client": "^0.3.1",
61
61
  "@swc/cli": "0.8.1",
62
62
  "@swc/core": "1.15.21",
63
63
  "@types/node": "^20",
@@ -69,6 +69,6 @@
69
69
  "vitest": "^4.1.2"
70
70
  },
71
71
  "dependencies": {
72
- "@egen-civitas/esm-embed-protocol": "^0.4.0"
72
+ "@egen-civitas/esm-embed-protocol": "^0.5.0"
73
73
  }
74
74
  }
package/src/connection.ts CHANGED
@@ -47,7 +47,7 @@ export class HostConnection {
47
47
  this.reset();
48
48
  this.nonce = createNonce();
49
49
  this.state = 'hello';
50
- this.o.post(wrapHandshake(this.o.moduleName, { kind: 'hello', nonce: this.nonce, protocols: [EGEN_EMBED_PROTOCOL, 1], hostVersion: this.o.hostVersion }));
50
+ this.o.post(wrapHandshake(this.o.moduleName, { kind: 'hello', nonce: this.nonce, protocols: [EGEN_EMBED_PROTOCOL], hostVersion: this.o.hostVersion }));
51
51
  }
52
52
 
53
53
  /** Traite un message de poignée de main v2 ; `true` si le message est de la famille v2 (consommé). */
@@ -57,7 +57,7 @@ export class HostConnection {
57
57
  const m = env.message;
58
58
  if (m.kind === 'probe') {
59
59
  if (this.state === 'idle') this.hello();
60
- else if (this.state === 'hello' && this.nonce) this.o.post(wrapHandshake(this.o.moduleName, { kind: 'hello', nonce: this.nonce, protocols: [EGEN_EMBED_PROTOCOL, 1], hostVersion: this.o.hostVersion }));
60
+ else if (this.state === 'hello' && this.nonce) this.o.post(wrapHandshake(this.o.moduleName, { kind: 'hello', nonce: this.nonce, protocols: [EGEN_EMBED_PROTOCOL], hostVersion: this.o.hostVersion }));
61
61
  } else if (m.kind === 'connect' && this.state === 'hello') {
62
62
  const c = parseConnect(m);
63
63
  if (!c || c.nonce !== this.nonce || negotiateProtocol(c.protocol, [EGEN_EMBED_PROTOCOL]) === null) return true;
package/src/host.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type Limits } from '@egen-civitas/esm-embed-protocol';
1
+ import { sanitizeIframeRights, type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type IframeRights, type Limits } from '@egen-civitas/esm-embed-protocol';
2
2
  import { createBus } from './bus.js';
3
3
  import { HostConnection } from './connection.js';
4
4
  import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensitive, toAppPath, toCorePath, normalizeAppPath, type NavigationOptions } from './navigation.js';
@@ -6,7 +6,7 @@ import type { HostProviders, Unsub } from './providers.js';
6
6
  import type { HostControls } from './table.js';
7
7
 
8
8
  export interface EmbedHostOptions {
9
- /** Nom du module (= `name` du manifeste). */
9
+ /** Nom du module (= `name` de `egen-config.json`). */
10
10
  moduleName: string;
11
11
  /** URL de base de l'application embarquée. */
12
12
  src: string;
@@ -15,8 +15,11 @@ export interface EmbedHostOptions {
15
15
  /** Grants effectifs (`effectiveGrants(manifeste.capabilities, approuvés)`). */
16
16
  grants: EffectiveGrants;
17
17
  providers: HostProviders;
18
- /** Attribut `sandbox` (défaut : scripts, même origine, formulaires, popups). */
19
- sandbox?: string;
18
+ /**
19
+ * Droits d'iframe EFFECTIFS (`effectiveIframe(manifeste.iframe, approuvés.iframe)`) : ils étendent le socle
20
+ * (`allow-scripts allow-same-origin allow-forms allow-popups`). Les jetons hors liste blanche sont écartés.
21
+ */
22
+ iframe?: IframeRights;
20
23
  title?: string;
21
24
  minHeight?: number;
22
25
  /** Navigation partagée Core ↔ app (URL du Core = source de vérité). Absent ou `none` : opaque. */
@@ -25,8 +28,6 @@ export interface EmbedHostOptions {
25
28
  onNavigate?: (to: string) => void;
26
29
  limits?: Partial<Limits>;
27
30
  hostVersion?: string;
28
- /** Accepter aussi les apps qui parlent encore le pont 1.1 (défaut : oui). */
29
- legacy?: boolean;
30
31
  window?: Window;
31
32
  onConnect?(granted: CapabilityGranted[], denied: CapabilityDenied[]): void;
32
33
  onClose?(reason: string): void;
@@ -41,11 +42,12 @@ export interface EmbedHost {
41
42
  destroy(): void;
42
43
  }
43
44
 
44
- const DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups';
45
+ /** Socle d'isolation appliqué à toute app embarquée ; les droits négociés (`iframe`) ne peuvent que l'étendre. */
46
+ const BASE_SANDBOX = ['allow-scripts', 'allow-same-origin', 'allow-forms', 'allow-popups'];
45
47
 
46
48
  /**
47
49
  * Hôte d'une app embarquée : iframe sécurisée, poignée de main v2 (`HostConnection`), navigation partagée,
48
- * événements de cycle de vie, et pont 1.1 pour les apps qui ne parlent pas encore le protocole 2.
50
+ * événements de cycle de vie. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
49
51
  * Sécurité : messages acceptés seulement de l'iframe elle-même ET de l'origine autorisée ; envoi toujours avec une origine explicite.
50
52
  */
51
53
  export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
@@ -63,7 +65,8 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
63
65
  const src = nav ? buildEmbedSrc(opts.src, initialAppPath, nav.mode) : opts.src;
64
66
  const origin = opts.allowedOrigin ?? new URL(src, win.location.href).origin;
65
67
  if (origin === '*' || origin === 'null') throw new Error('allowedOrigin invalide : une origine explicite est requise.');
66
- const sandbox = opts.sandbox ?? DEFAULT_SANDBOX;
68
+ const rights = sanitizeIframeRights(opts.iframe);
69
+ const sandbox = [...new Set([...BASE_SANDBOX, ...rights.sandbox])].join(' ');
67
70
  if (origin === win.location.origin && /allow-scripts/.test(sandbox) && /allow-same-origin/.test(sandbox)) {
68
71
  console.warn(`[egen] ${opts.moduleName} : application embarquée de même origine que le Shell avec « allow-scripts allow-same-origin » : le bac à sable est sans effet. Héberger l'application sur une autre origine (sous-domaine).`);
69
72
  }
@@ -72,6 +75,7 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
72
75
  iframe.src = src;
73
76
  iframe.title = opts.title ?? opts.moduleName;
74
77
  iframe.setAttribute('sandbox', sandbox);
78
+ if (rights.allow.length) iframe.setAttribute('allow', rights.allow.join('; '));
75
79
  iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
76
80
  iframe.setAttribute('data-egen-fill', '');
77
81
  iframe.style.cssText = `width:100%;border:0;display:block;min-height:${opts.minHeight ?? 400}px`;
@@ -80,13 +84,10 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
80
84
  const allowLocation = createRateLimiter();
81
85
  const stop: Unsub[] = [];
82
86
  let seq = 0;
83
- let legacySeen = false;
84
- let legacyReady = false;
85
87
 
86
88
  const postRaw = (message: unknown, transfer?: Transferable[]) => iframe.contentWindow?.postMessage(message, origin, transfer);
87
- const legacySend = (message: unknown) => postRaw({ egen: 1, moduleName: opts.moduleName, message });
88
89
 
89
- /** Page courante annoncée par l'app → URL du Core (partagé entre le protocole 2 et le pont 1.1). */
90
+ /** Page courante annoncée par l'app → URL du Core. */
90
91
  const reportLocation = (path: unknown, o?: { replace?: boolean; title?: string }) => {
91
92
  if (!nav || !allowLocation()) return;
92
93
  if (typeof o?.title === 'string') {
@@ -124,41 +125,9 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
124
125
  onClose: opts.onClose,
125
126
  });
126
127
 
127
- /**
128
- * Pont 1.1 : compatibilité des apps qui ne parlent pas encore le protocole 2. La session n'est PLUS transmise (règle d'or,
129
- * doc 17 §2) : une app obtient son identité auprès de Keycloak. Seuls restent la langue, la navigation, le titre et la hauteur.
130
- */
131
- const handleLegacy = async (data: any) => {
132
- if (opts.legacy === false || connection.connected) return;
133
- if (!data || data.egen !== 1 || data.moduleName !== opts.moduleName || !data.message || typeof data.message.kind !== 'string') return;
134
- const msg = data.message;
135
- switch (msg.kind) {
136
- case 'ready': {
137
- legacySeen = true;
138
- legacyReady = true;
139
- const locale = opts.providers.locale ? await opts.providers.locale.get() : (win as any).i18next?.language;
140
- legacySend({ kind: 'init', payload: { moduleName: opts.moduleName, locale, spaBase: spaBase(), navigation: nav ? { mode: nav.mode, route: nav.route } : undefined } });
141
- break;
142
- }
143
- case 'navigate':
144
- controls.navigate?.(msg.to);
145
- break;
146
- case 'resize':
147
- controls.resize?.(msg.height);
148
- break;
149
- case 'title':
150
- if (typeof msg.title === 'string') iframe.title = msg.title.slice(0, 200);
151
- break;
152
- case 'location':
153
- legacySeen = true;
154
- reportLocation(msg.path, { replace: !!msg.replace, title: msg.title });
155
- break;
156
- }
157
- };
158
-
159
128
  const onMessage = (event: MessageEvent) => {
160
129
  if (event.source !== iframe.contentWindow || event.origin !== origin) return;
161
- if (!connection.handle(event.data)) void handleLegacy(event.data);
130
+ connection.handle(event.data);
162
131
  };
163
132
 
164
133
  return {
@@ -180,7 +149,6 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
180
149
  const appPath = toAppPath(cur, nav);
181
150
  if (!appPath) return;
182
151
  if (connection.connected) channel.emit('goto', { path: appPath, seq: ++seq });
183
- else if (legacySeen) legacySend({ kind: 'goto', path: appPath, seq: ++seq });
184
152
  else iframe.src = buildEmbedSrc(opts.src, appPath, nav.mode);
185
153
  };
186
154
  win.addEventListener('single-spa:routing-event', onCoreLocation);
@@ -203,10 +171,6 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
203
171
  win.removeEventListener('blur', onBlur);
204
172
  });
205
173
 
206
- // Pont 1.1 : la langue est poussée après `ready`.
207
- const p = opts.providers;
208
- if (p.locale?.subscribe) stop.push(p.locale.subscribe((l) => legacyReady && !connection.connected && l && legacySend({ kind: 'locale', locale: l })));
209
-
210
174
  container.appendChild(iframe);
211
175
  },
212
176
  async canLeave(timeoutMs = 1500) {
package/src/navigation.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Navigation partagée Shell ↔ application embarquée (protocole 1.1, additif).
2
+ * Navigation partagée Shell ↔ application embarquée (capacité `navigation` du protocole 2).
3
3
  *
4
4
  * L'URL du Core reste la source de vérité, comme pour une app interne : `<base>/<route>/<chemin-de-l'app>?q#h`.
5
5
  * Ce module ne contient que des fonctions pures (aucun accès au DOM), testées isolément.