@egen-civitas/esm-embed-host 0.4.0 → 0.6.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 +33 -0
- package/README.md +9 -4
- package/dist/connection.js +2 -4
- package/dist/host.d.ts +15 -7
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +47 -151
- package/dist/navigation.d.ts +1 -1
- package/dist/navigation.js +1 -1
- package/dist/table.d.ts +2 -0
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +4 -0
- package/package.json +3 -3
- package/src/connection.ts +2 -2
- package/src/host.ts +26 -51
- package/src/navigation.ts +1 -1
- package/src/table.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @egen-civitas/esm-embed-host
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8cb58ba: Contrat « page introuvable » : une app embarquée ne rend plus sa propre 404, elle la délègue au Shell.
|
|
8
|
+
|
|
9
|
+
- **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).
|
|
10
|
+
- **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.
|
|
11
|
+
- **client** : `egen.navigation.notFound(path?)`.
|
|
12
|
+
- **testing** : le simulateur journalise `notFound` dans `calls`.
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [8cb58ba]
|
|
17
|
+
- @egen-civitas/esm-embed-protocol@0.6.0
|
|
18
|
+
|
|
19
|
+
## 0.5.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- 721c7f8: Droits d'iframe négociés et voie unique SDK.
|
|
24
|
+
|
|
25
|
+
- **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`.
|
|
26
|
+
- **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.
|
|
27
|
+
- **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.
|
|
28
|
+
- **client** : documentation (les droits se demandent dans `egen-config.json`), le manifeste s'appelle désormais `egen-config.json`.
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- 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`).
|
|
33
|
+
- Updated dependencies [721c7f8]
|
|
34
|
+
- @egen-civitas/esm-embed-protocol@0.5.0
|
|
35
|
+
|
|
3
36
|
## 0.4.0
|
|
4
37
|
|
|
5
38
|
### 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
|
|
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
|
|
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,7 @@ 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
|
-
- **
|
|
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.
|
|
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).
|
|
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`.
|
|
31
36
|
- `HostConnection` est indépendante du DOM (testable avec le vrai client, voir `src/__tests__/harness.ts`).
|
package/dist/connection.js
CHANGED
|
@@ -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`
|
|
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,18 +12,26 @@ export interface EmbedHostOptions {
|
|
|
12
12
|
/** Grants effectifs (`effectiveGrants(manifeste.capabilities, approuvés)`). */
|
|
13
13
|
grants: EffectiveGrants;
|
|
14
14
|
providers: HostProviders;
|
|
15
|
-
/**
|
|
16
|
-
|
|
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. */
|
|
20
23
|
navigation?: NavigationOptions;
|
|
21
24
|
/** Navigation demandée par l'app vers le Core (défaut : `singleSpaNavigate`). */
|
|
22
25
|
onNavigate?: (to: string) => void;
|
|
26
|
+
/**
|
|
27
|
+
* L'app signale une page introuvable (`navigation.notFound`) : le Shell affiche SA page 404 à la place de l'app.
|
|
28
|
+
* `path` est le chemin de l'app, normalisé et débarrassé des paramètres sensibles (`null` : la page courante de l'app).
|
|
29
|
+
*/
|
|
30
|
+
onNotFound?: (info: {
|
|
31
|
+
path: string | null;
|
|
32
|
+
}) => void;
|
|
23
33
|
limits?: Partial<Limits>;
|
|
24
34
|
hostVersion?: string;
|
|
25
|
-
/** Accepter aussi les apps qui parlent encore le pont 1.1 (défaut : oui). */
|
|
26
|
-
legacy?: boolean;
|
|
27
35
|
window?: Window;
|
|
28
36
|
onConnect?(granted: CapabilityGranted[], denied: CapabilityDenied[]): void;
|
|
29
37
|
onClose?(reason: string): void;
|
|
@@ -38,7 +46,7 @@ export interface EmbedHost {
|
|
|
38
46
|
}
|
|
39
47
|
/**
|
|
40
48
|
* 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
|
|
49
|
+
* événements de cycle de vie. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
|
|
42
50
|
* 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
51
|
*/
|
|
44
52
|
export declare function createEmbedHost(opts: EmbedHostOptions): EmbedHost;
|
package/dist/host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,KAAK,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAE7K,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAwH,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/K,OAAO,KAAK,EAAE,aAAa,EAAS,MAAM,gBAAgB,CAAC;AAG3D,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,aAAa,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kGAAkG;IAClG,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,iFAAiF;IACjF,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC;;;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,CAgJjE"}
|
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
|
-
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
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;
|
|
@@ -261,6 +285,14 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
|
|
|
261
285
|
return (_win_singleSpaNavigate = win.singleSpaNavigate) === null || _win_singleSpaNavigate === void 0 ? void 0 : _win_singleSpaNavigate.call(win, spaBase() + t.replace(/^\//, ''));
|
|
262
286
|
})(to);
|
|
263
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
|
+
},
|
|
264
296
|
setTitle: function setTitle(t) {
|
|
265
297
|
return void (iframe.title = String(t).slice(0, 200));
|
|
266
298
|
},
|
|
@@ -279,137 +311,14 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
|
|
|
279
311
|
onConnect: opts.onConnect,
|
|
280
312
|
onClose: opts.onClose
|
|
281
313
|
});
|
|
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
314
|
var onMessage = function onMessage(event) {
|
|
405
315
|
if (event.source !== iframe.contentWindow || event.origin !== origin) return;
|
|
406
|
-
|
|
316
|
+
connection.handle(event.data);
|
|
407
317
|
};
|
|
408
318
|
return {
|
|
409
319
|
iframe: iframe,
|
|
410
320
|
connection: connection,
|
|
411
321
|
mount: function mount(container) {
|
|
412
|
-
var _p_locale;
|
|
413
322
|
win.addEventListener('message', onMessage);
|
|
414
323
|
stop.push(function() {
|
|
415
324
|
return win.removeEventListener('message', onMessage);
|
|
@@ -432,11 +341,6 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
|
|
|
432
341
|
path: appPath,
|
|
433
342
|
seq: ++seq
|
|
434
343
|
});
|
|
435
|
-
else if (legacySeen) legacySend({
|
|
436
|
-
kind: 'goto',
|
|
437
|
-
path: appPath,
|
|
438
|
-
seq: ++seq
|
|
439
|
-
});
|
|
440
344
|
else iframe.src = buildEmbedSrc(opts.src, appPath, nav.mode);
|
|
441
345
|
};
|
|
442
346
|
win.addEventListener('single-spa:routing-event', onCoreLocation);
|
|
@@ -463,14 +367,6 @@ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups'
|
|
|
463
367
|
win.removeEventListener('focus', onFocus);
|
|
464
368
|
win.removeEventListener('blur', onBlur);
|
|
465
369
|
});
|
|
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
370
|
container.appendChild(iframe);
|
|
475
371
|
},
|
|
476
372
|
canLeave: function canLeave() {
|
package/dist/navigation.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Navigation partagée Shell ↔ application embarquée (protocole
|
|
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/dist/navigation.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Navigation partagée Shell ↔ application embarquée (protocole
|
|
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/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;
|
package/dist/table.d.ts.map
CHANGED
|
@@ -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,YAAY,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,gBAAgB,CAAA;CAAE,
|
|
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,6FAA6F;IAC7F,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,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,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.
|
|
3
|
+
"version": "0.6.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.
|
|
60
|
+
"@egen-civitas/esm-embed-client": "^0.4.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.
|
|
72
|
+
"@egen-civitas/esm-embed-protocol": "^0.6.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
|
|
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
|
|
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`
|
|
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,18 +15,24 @@ export interface EmbedHostOptions {
|
|
|
15
15
|
/** Grants effectifs (`effectiveGrants(manifeste.capabilities, approuvés)`). */
|
|
16
16
|
grants: EffectiveGrants;
|
|
17
17
|
providers: HostProviders;
|
|
18
|
-
/**
|
|
19
|
-
|
|
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. */
|
|
23
26
|
navigation?: NavigationOptions;
|
|
24
27
|
/** Navigation demandée par l'app vers le Core (défaut : `singleSpaNavigate`). */
|
|
25
28
|
onNavigate?: (to: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* L'app signale une page introuvable (`navigation.notFound`) : le Shell affiche SA page 404 à la place de l'app.
|
|
31
|
+
* `path` est le chemin de l'app, normalisé et débarrassé des paramètres sensibles (`null` : la page courante de l'app).
|
|
32
|
+
*/
|
|
33
|
+
onNotFound?: (info: { path: string | null }) => void;
|
|
26
34
|
limits?: Partial<Limits>;
|
|
27
35
|
hostVersion?: string;
|
|
28
|
-
/** Accepter aussi les apps qui parlent encore le pont 1.1 (défaut : oui). */
|
|
29
|
-
legacy?: boolean;
|
|
30
36
|
window?: Window;
|
|
31
37
|
onConnect?(granted: CapabilityGranted[], denied: CapabilityDenied[]): void;
|
|
32
38
|
onClose?(reason: string): void;
|
|
@@ -41,11 +47,12 @@ export interface EmbedHost {
|
|
|
41
47
|
destroy(): void;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
/** Socle d'isolation appliqué à toute app embarquée ; les droits négociés (`iframe`) ne peuvent que l'étendre. */
|
|
51
|
+
const BASE_SANDBOX = ['allow-scripts', 'allow-same-origin', 'allow-forms', 'allow-popups'];
|
|
45
52
|
|
|
46
53
|
/**
|
|
47
54
|
* 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
|
|
55
|
+
* événements de cycle de vie. Une seule voie : le protocole 2 (SDK `esm-embed-client`).
|
|
49
56
|
* 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
57
|
*/
|
|
51
58
|
export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
@@ -63,7 +70,8 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
63
70
|
const src = nav ? buildEmbedSrc(opts.src, initialAppPath, nav.mode) : opts.src;
|
|
64
71
|
const origin = opts.allowedOrigin ?? new URL(src, win.location.href).origin;
|
|
65
72
|
if (origin === '*' || origin === 'null') throw new Error('allowedOrigin invalide : une origine explicite est requise.');
|
|
66
|
-
const
|
|
73
|
+
const rights = sanitizeIframeRights(opts.iframe);
|
|
74
|
+
const sandbox = [...new Set([...BASE_SANDBOX, ...rights.sandbox])].join(' ');
|
|
67
75
|
if (origin === win.location.origin && /allow-scripts/.test(sandbox) && /allow-same-origin/.test(sandbox)) {
|
|
68
76
|
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
77
|
}
|
|
@@ -72,6 +80,7 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
72
80
|
iframe.src = src;
|
|
73
81
|
iframe.title = opts.title ?? opts.moduleName;
|
|
74
82
|
iframe.setAttribute('sandbox', sandbox);
|
|
83
|
+
if (rights.allow.length) iframe.setAttribute('allow', rights.allow.join('; '));
|
|
75
84
|
iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
|
|
76
85
|
iframe.setAttribute('data-egen-fill', '');
|
|
77
86
|
iframe.style.cssText = `width:100%;border:0;display:block;min-height:${opts.minHeight ?? 400}px`;
|
|
@@ -80,13 +89,10 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
80
89
|
const allowLocation = createRateLimiter();
|
|
81
90
|
const stop: Unsub[] = [];
|
|
82
91
|
let seq = 0;
|
|
83
|
-
let legacySeen = false;
|
|
84
|
-
let legacyReady = false;
|
|
85
92
|
|
|
86
93
|
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
94
|
|
|
89
|
-
/** Page courante annoncée par l'app → URL du Core
|
|
95
|
+
/** Page courante annoncée par l'app → URL du Core. */
|
|
90
96
|
const reportLocation = (path: unknown, o?: { replace?: boolean; title?: string }) => {
|
|
91
97
|
if (!nav || !allowLocation()) return;
|
|
92
98
|
if (typeof o?.title === 'string') {
|
|
@@ -106,6 +112,12 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
106
112
|
if (normalizeAppPath(to) === null) return;
|
|
107
113
|
(opts.onNavigate ?? ((t) => (win as any).singleSpaNavigate?.(spaBase() + t.replace(/^\//, ''))))(to);
|
|
108
114
|
},
|
|
115
|
+
notFound: (path) => {
|
|
116
|
+
if (!opts.onNotFound || !allowLocation()) return;
|
|
117
|
+
const normalized = path === undefined ? null : normalizeAppPath(path);
|
|
118
|
+
if (path !== undefined && normalized === null) return;
|
|
119
|
+
opts.onNotFound({ path: normalized === null ? null : stripSensitive(normalized, nav?.sensitiveParams) });
|
|
120
|
+
},
|
|
109
121
|
setTitle: (t) => void (iframe.title = String(t).slice(0, 200)),
|
|
110
122
|
resize: (h) => {
|
|
111
123
|
if (Number.isFinite(h) && h >= 0) iframe.style.height = `${Math.min(Math.ceil(h), 100_000)}px`;
|
|
@@ -124,41 +136,9 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
124
136
|
onClose: opts.onClose,
|
|
125
137
|
});
|
|
126
138
|
|
|
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
139
|
const onMessage = (event: MessageEvent) => {
|
|
160
140
|
if (event.source !== iframe.contentWindow || event.origin !== origin) return;
|
|
161
|
-
|
|
141
|
+
connection.handle(event.data);
|
|
162
142
|
};
|
|
163
143
|
|
|
164
144
|
return {
|
|
@@ -180,7 +160,6 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
180
160
|
const appPath = toAppPath(cur, nav);
|
|
181
161
|
if (!appPath) return;
|
|
182
162
|
if (connection.connected) channel.emit('goto', { path: appPath, seq: ++seq });
|
|
183
|
-
else if (legacySeen) legacySend({ kind: 'goto', path: appPath, seq: ++seq });
|
|
184
163
|
else iframe.src = buildEmbedSrc(opts.src, appPath, nav.mode);
|
|
185
164
|
};
|
|
186
165
|
win.addEventListener('single-spa:routing-event', onCoreLocation);
|
|
@@ -203,10 +182,6 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
203
182
|
win.removeEventListener('blur', onBlur);
|
|
204
183
|
});
|
|
205
184
|
|
|
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
185
|
container.appendChild(iframe);
|
|
211
186
|
},
|
|
212
187
|
async canLeave(timeoutMs = 1500) {
|
package/src/navigation.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Navigation partagée Shell ↔ application embarquée (protocole
|
|
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/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
|
};
|