@egen-civitas/esm-embed-host 0.5.0 → 0.7.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,30 @@
1
1
  # @egen-civitas/esm-embed-host
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b3c354a: Plus d'échec muet de la poignée de main.
8
+
9
+ - **hôte** : un message de l'iframe dont le **nom de module** ne correspond pas à celui verrouillé côté Core, ou dont l'**origine** diffère de celle déclarée, est toujours ignoré (aucun changement de sécurité) mais est désormais signalé par un `console.warn` explicite (une fois par cause) qui nomme les deux valeurs et la correction (`yarn external:sync`, URL déclarée). Option `logger`. Les messages d'une autre fenêtre ou hors protocole restent ignorés sans bruit.
10
+ - **client** : au dépassement du délai, `connectToEgen` écrit un avertissement qui liste les causes probables (nom du module, origines du Shell, URL déclarée, hôte v2) avec le nom et les origines utilisés. Option `log`. Aucun avertissement hors iframe ni en cas de connexion réussie.
11
+
12
+ ## 0.6.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 8cb58ba: Contrat « page introuvable » : une app embarquée ne rend plus sa propre 404, elle la délègue au Shell.
17
+
18
+ - **protocole** : méthode `navigation.notFound(path?)` (chemin interne ou aucun argument ; tout autre argument est rejeté) dans la capacité `navigation` existante (aucune nouvelle capacité, rétrocompatible).
19
+ - **hôte** : option `onNotFound({ path })` de `createEmbedHost` ; le chemin est normalisé et débarrassé des paramètres sensibles, l'appel est limité en débit comme `report`. Sans callback : accepté, sans effet.
20
+ - **client** : `egen.navigation.notFound(path?)`.
21
+ - **testing** : le simulateur journalise `notFound` dans `calls`.
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [8cb58ba]
26
+ - @egen-civitas/esm-embed-protocol@0.6.0
27
+
3
28
  ## 0.5.0
4
29
 
5
30
  ### Minor Changes
package/README.md CHANGED
@@ -30,6 +30,7 @@ host.mount(container); // …; host.destroy() au démontage
30
30
 
31
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`).
32
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.
33
+ - **Page introuvable** : `onNotFound({ path })` est appelé quand l'app signale (`navigation.notFound`) qu'elle ne connaît pas une page. Le Shell affiche **sa** page 404 à la place de l'app ; `path` est normalisé et sans paramètre sensible (`null` = page courante). Sans callback, l'appel est accepté et sans effet.
33
34
  - **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
35
  - **Voie unique** : le pont 1.1 (`{ egen: 1 }`) est retiré ; ses messages sont ignorés. Une app doit adopter `@egen-civitas/esm-embed-client`.
35
36
  - `HostConnection` est indépendante du DOM (testable avec le vrai client, voir `src/__tests__/harness.ts`).
package/dist/host.d.ts CHANGED
@@ -23,6 +23,15 @@ export interface EmbedHostOptions {
23
23
  navigation?: NavigationOptions;
24
24
  /** Navigation demandée par l'app vers le Core (défaut : `singleSpaNavigate`). */
25
25
  onNavigate?: (to: string) => void;
26
+ /** Où écrire les diagnostics de poignée de main (défaut : `console`). */
27
+ logger?: Pick<Console, 'warn'>;
28
+ /**
29
+ * L'app signale une page introuvable (`navigation.notFound`) : le Shell affiche SA page 404 à la place de l'app.
30
+ * `path` est le chemin de l'app, normalisé et débarrassé des paramètres sensibles (`null` : la page courante de l'app).
31
+ */
32
+ onNotFound?: (info: {
33
+ path: string | null;
34
+ }) => void;
26
35
  limits?: Partial<Limits>;
27
36
  hostVersion?: string;
28
37
  window?: Window;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EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,KAAK,IAAI,CAAC;IACrD,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,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,CA6KjE"}
package/dist/host.js CHANGED
@@ -203,7 +203,7 @@ function _ts_generator(thisArg, body) {
203
203
  };
204
204
  }
205
205
  }
206
- import { sanitizeIframeRights } from '@egen-civitas/esm-embed-protocol';
206
+ import { EGEN_EMBED_PROTOCOL, parseEnvelope, sanitizeIframeRights } from '@egen-civitas/esm-embed-protocol';
207
207
  import { createBus } from './bus.js';
208
208
  import { HostConnection } from './connection.js';
209
209
  import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensitive, toAppPath, toCorePath, normalizeAppPath } from './navigation.js';
@@ -218,7 +218,7 @@ import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensi
218
218
  * événements de cycle de vie. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
219
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.
220
220
  */ export function createEmbedHost(opts) {
221
- var _opts_window, _opts_navigation_mode, _opts_navigation_mode1, _currentCorePath, _toAppPath, _opts_allowedOrigin, _opts_title, _opts_minHeight;
221
+ var _opts_window, _opts_navigation_mode, _opts_navigation_mode1, _currentCorePath, _toAppPath, _opts_allowedOrigin, _opts_title, _opts_minHeight, _opts_logger;
222
222
  var win = (_opts_window = opts.window) !== null && _opts_window !== void 0 ? _opts_window : window;
223
223
  var doc = win.document;
224
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), {
@@ -285,6 +285,14 @@ import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensi
285
285
  return (_win_singleSpaNavigate = win.singleSpaNavigate) === null || _win_singleSpaNavigate === void 0 ? void 0 : _win_singleSpaNavigate.call(win, spaBase() + t.replace(/^\//, ''));
286
286
  })(to);
287
287
  },
288
+ notFound: function notFound(path) {
289
+ if (!opts.onNotFound || !allowLocation()) return;
290
+ var normalized = path === undefined ? null : normalizeAppPath(path);
291
+ if (path !== undefined && normalized === null) return;
292
+ opts.onNotFound({
293
+ path: normalized === null ? null : stripSensitive(normalized, nav === null || nav === void 0 ? void 0 : nav.sensitiveParams)
294
+ });
295
+ },
288
296
  setTitle: function setTitle(t) {
289
297
  return void (iframe.title = String(t).slice(0, 200));
290
298
  },
@@ -303,9 +311,28 @@ import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensi
303
311
  onConnect: opts.onConnect,
304
312
  onClose: opts.onClose
305
313
  });
314
+ // Diagnostics : sans eux, un nom de module ou une origine qui ne correspond pas à la déclaration verrouillée côté Core
315
+ // fait échouer la poignée de main EN SILENCE (l'app attend 5 s puis se replie en mode autonome, sans la moindre trace).
316
+ var logger = (_opts_logger = opts.logger) !== null && _opts_logger !== void 0 ? _opts_logger : console;
317
+ var warned = new Set();
318
+ var warnOnce = function warnOnce(key, message) {
319
+ if (warned.has(key)) return;
320
+ warned.add(key);
321
+ logger.warn(message);
322
+ };
306
323
  var onMessage = function onMessage(event) {
307
- if (event.source !== iframe.contentWindow || event.origin !== origin) return;
308
- connection.handle(event.data);
324
+ if (event.source !== iframe.contentWindow) return; // une autre fenêtre : ignorée sans bruit
325
+ var envelope = parseEnvelope(event.data);
326
+ if (event.origin !== origin) {
327
+ if ((envelope === null || envelope === void 0 ? void 0 : envelope.egen) === EGEN_EMBED_PROTOCOL) {
328
+ warnOnce("origin:".concat(event.origin), "[egen-embed] \xab ".concat(opts.moduleName, " \xbb : message ignor\xe9, l'iframe parle depuis ").concat(event.origin, " alors que le Core attend ").concat(origin, ". ") + "Ouvrir l'app par l'URL d\xe9clar\xe9e (\xab url \xbb de l'entr\xe9e embed / de egen-config.json) ou corriger cette URL.");
329
+ }
330
+ return;
331
+ }
332
+ var handled = connection.handle(event.data);
333
+ if (!handled && (envelope === null || envelope === void 0 ? void 0 : envelope.egen) === EGEN_EMBED_PROTOCOL && envelope.moduleName !== opts.moduleName) {
334
+ warnOnce("name:".concat(envelope.moduleName), "[egen-embed] message ignor\xe9 : l'app s'annonce \xab ".concat(envelope.moduleName, " \xbb mais le Core attend \xab ").concat(opts.moduleName, " \xbb. ") + "La d\xe9claration verrouill\xe9e c\xf4t\xe9 Core est p\xe9rim\xe9e, ou l'app utilise un autre nom que celui de son egen-config.json : " + "relancer \xab yarn external:sync \xbb apr\xe8s tout changement de d\xe9claration.");
335
+ }
309
336
  };
310
337
  return {
311
338
  iframe: iframe,
package/dist/table.d.ts CHANGED
@@ -8,6 +8,8 @@ export interface HostControls {
8
8
  title?: string;
9
9
  }): void;
10
10
  navigate?(to: string): void;
11
+ /** L'app signale une page introuvable (`path` : chemin de l'app, absent = page courante). */
12
+ notFound?(path?: string): void;
11
13
  setTitle?(title: string): void;
12
14
  resize?(height: number): void;
13
15
  onReady?(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../src/table.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAEjB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEnE,+EAA+E;AAC/E,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC1E,QAAQ,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB,6DAA6D;IAC7D,OAAO,EAAE,GAAG,CAAC;CACd;AAED,8HAA8H;AAC9H,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,aAAa,GAAG,GAAG,CAAC,YAAY,CAAC,CAczE;AAID,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,SAAS,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,YA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qBAAqB,CAAC,CAAC,EAAE,YAAY,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,gBAAgB,CAAA;CAAE,CAgG3G"}
package/dist/table.js CHANGED
@@ -411,6 +411,10 @@ var list = function list(cfg, key) {
411
411
  var _c_navigate;
412
412
  return (_c_navigate = c.navigate) === null || _c_navigate === void 0 ? void 0 : _c_navigate.call(c, to);
413
413
  },
414
+ notFound: function notFound(path) {
415
+ var _c_notFound;
416
+ return (_c_notFound = c.notFound) === null || _c_notFound === void 0 ? void 0 : _c_notFound.call(c, path);
417
+ },
414
418
  setTitle: function setTitle(t) {
415
419
  var _c_setTitle;
416
420
  return (_c_setTitle = c.setTitle) === null || _c_setTitle === void 0 ? void 0 : _c_setTitle.call(c, t);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egen-civitas/esm-embed-host",
3
- "version": "0.5.0",
3
+ "version": "0.7.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.1",
60
+ "@egen-civitas/esm-embed-client": "^0.7.0",
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.5.0"
72
+ "@egen-civitas/esm-embed-protocol": "^0.6.0"
73
73
  }
74
74
  }
package/src/host.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { sanitizeIframeRights, type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type IframeRights, type Limits } from '@egen-civitas/esm-embed-protocol';
1
+ import { EGEN_EMBED_PROTOCOL, parseEnvelope, 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';
@@ -26,6 +26,13 @@ export interface EmbedHostOptions {
26
26
  navigation?: NavigationOptions;
27
27
  /** Navigation demandée par l'app vers le Core (défaut : `singleSpaNavigate`). */
28
28
  onNavigate?: (to: string) => void;
29
+ /** Où écrire les diagnostics de poignée de main (défaut : `console`). */
30
+ logger?: Pick<Console, 'warn'>;
31
+ /**
32
+ * L'app signale une page introuvable (`navigation.notFound`) : le Shell affiche SA page 404 à la place de l'app.
33
+ * `path` est le chemin de l'app, normalisé et débarrassé des paramètres sensibles (`null` : la page courante de l'app).
34
+ */
35
+ onNotFound?: (info: { path: string | null }) => void;
29
36
  limits?: Partial<Limits>;
30
37
  hostVersion?: string;
31
38
  window?: Window;
@@ -107,6 +114,12 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
107
114
  if (normalizeAppPath(to) === null) return;
108
115
  (opts.onNavigate ?? ((t) => (win as any).singleSpaNavigate?.(spaBase() + t.replace(/^\//, ''))))(to);
109
116
  },
117
+ notFound: (path) => {
118
+ if (!opts.onNotFound || !allowLocation()) return;
119
+ const normalized = path === undefined ? null : normalizeAppPath(path);
120
+ if (path !== undefined && normalized === null) return;
121
+ opts.onNotFound({ path: normalized === null ? null : stripSensitive(normalized, nav?.sensitiveParams) });
122
+ },
110
123
  setTitle: (t) => void (iframe.title = String(t).slice(0, 200)),
111
124
  resize: (h) => {
112
125
  if (Number.isFinite(h) && h >= 0) iframe.style.height = `${Math.min(Math.ceil(h), 100_000)}px`;
@@ -125,9 +138,38 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
125
138
  onClose: opts.onClose,
126
139
  });
127
140
 
141
+ // Diagnostics : sans eux, un nom de module ou une origine qui ne correspond pas à la déclaration verrouillée côté Core
142
+ // fait échouer la poignée de main EN SILENCE (l'app attend 5 s puis se replie en mode autonome, sans la moindre trace).
143
+ const logger = opts.logger ?? console;
144
+ const warned = new Set<string>();
145
+ const warnOnce = (key: string, message: string) => {
146
+ if (warned.has(key)) return;
147
+ warned.add(key);
148
+ logger.warn(message);
149
+ };
150
+
128
151
  const onMessage = (event: MessageEvent) => {
129
- if (event.source !== iframe.contentWindow || event.origin !== origin) return;
130
- connection.handle(event.data);
152
+ if (event.source !== iframe.contentWindow) return; // une autre fenêtre : ignorée sans bruit
153
+ const envelope = parseEnvelope(event.data);
154
+ if (event.origin !== origin) {
155
+ if (envelope?.egen === EGEN_EMBED_PROTOCOL) {
156
+ warnOnce(
157
+ `origin:${event.origin}`,
158
+ `[egen-embed] « ${opts.moduleName} » : message ignoré, l'iframe parle depuis ${event.origin} alors que le Core attend ${origin}. ` +
159
+ `Ouvrir l'app par l'URL déclarée (« url » de l'entrée embed / de egen-config.json) ou corriger cette URL.`
160
+ );
161
+ }
162
+ return;
163
+ }
164
+ const handled = connection.handle(event.data);
165
+ if (!handled && envelope?.egen === EGEN_EMBED_PROTOCOL && envelope.moduleName !== opts.moduleName) {
166
+ warnOnce(
167
+ `name:${envelope.moduleName}`,
168
+ `[egen-embed] message ignoré : l'app s'annonce « ${envelope.moduleName} » mais le Core attend « ${opts.moduleName} ». ` +
169
+ `La déclaration verrouillée côté Core est périmée, ou l'app utilise un autre nom que celui de son egen-config.json : ` +
170
+ `relancer « yarn external:sync » après tout changement de déclaration.`
171
+ );
172
+ }
131
173
  };
132
174
 
133
175
  return {
package/src/table.ts CHANGED
@@ -18,6 +18,8 @@ import type { CallerContext, HostProviders } from './providers.js';
18
18
  export interface HostControls {
19
19
  report?(path: string, opts?: { replace?: boolean; title?: string }): void;
20
20
  navigate?(to: string): void;
21
+ /** L'app signale une page introuvable (`path` : chemin de l'app, absent = page courante). */
22
+ notFound?(path?: string): void;
21
23
  setTitle?(title: string): void;
22
24
  resize?(height: number): void;
23
25
  onReady?(): void;
@@ -116,6 +118,7 @@ export function createCapabilityTable(o: TableOptions): { table: HandlerTable; s
116
118
  table.navigation = {
117
119
  report: (path: string, opts?: { replace?: boolean; title?: string }) => c.report?.(path, opts),
118
120
  navigate: (to: string) => c.navigate?.(to),
121
+ notFound: (path?: string) => c.notFound?.(path),
119
122
  setTitle: (t: string) => c.setTitle?.(t),
120
123
  resize: (h: number) => c.resize?.(h),
121
124
  };